I have a struct that is storing values from an API, the json tags are being used to match what the API is returning.
within code, if I print the struct, I see my field names. However, when I send the struct to gin, it is using the tag names.
I am tryng to figure out how to either use the struct field names in the original struct, or copy the value of the struct to similar struct, but use json tags to give a custom name.
example:
type ComputeResponse struct {
Endpoints []ComputeObject
}
type ComputeObject struct {
Hostname string `json:"hostname"`
LogicalEnvironment string `json:"lgcl_env"`
}
If I print the values of ComputeResponse.Endpoints I will see something like this:
[{Hostname:test LogicalEnvironment:test]
but in the browser or curl response I get:
{
"hostname": "test",
"lgcl_env": "test"
}
I am pretty new to go. Any suggestions would be appreciated.
评论:
kpurdon:
