I have a struct:
type Credentials struct {
Username string `json:"username"`
Password string `json:"password"`
ApplicationId string `json:"application_id"`
ApplicationKey string `json:"application_key"`
}
And I've tagged my fields to lowercase them.
However, whenever I include the application tags, those fields become null, i.e. on my POST request I get
{ application_id: '',
application_key: '',
password: 'myPassword',
username: 'myUsername'
}
But if I remove either of the tag (so remove ApplicatinonId
or ApplicationKey
tag), then that field does show up
Here is how I set my struct:
func getCredentials() Credentials {
raw, err := ioutil.ReadFile(os.Getenv("BASE_PATH") + FILE_Credentials)
if err != nil {
log.Warn("Could not read credentials file: %s", err.Error())
os.Exit(1)
}
var credentials Credentials
json.Unmarshal(raw, &credentials)
return credentials
}
My credential json
file is:
{
"Username": "myUsername",
"Password": "myPassowrd",
"ApplicationId": "someID",
"ApplicationKey": "someString"
}
Then, I post my data with:
credentials := getCredentials()
url := GetLoginURL()
resp, body, requestErr := gorequest.New().
Post(url).
Send(credentials).
End()
But on the server, I get both application_id
and application_key
as empty strings. But if I remove the corresponding tag, then that field is posted