4
I am checking in the API if the user’s email is already registered and returns a warning message. Even performing the requests the payload returns empty.
Even debugging and knowing that the payload on the api side is with the information it returns empty.
A friend, recommended me to make an interface and to throw the information inside it, turning an interface inside another interface, but it didn’t work.
Thank you.
func CreateUsuario(responseWriter http.ResponseWriter, r *http.Request) {
var util util.StructApp
msg := []interface{}{}
msg = append(msg, "Erro")
util.RespondWithJSON(responseWriter, http.StatusCreated, msg)
}
func (appStruct *StructApp) RespondWithJSON(responseWriter http.ResponseWriter, code int, payload interface{}) {
var responseSuccess response.ResponseSuccess
responseSuccess.Records = payload
lenPayload := reflect.ValueOf(payload)
responseSuccess.Meta.RecordCount = 1
responseSuccess.Meta.Limit = 1
if lenPayload.Kind() == reflect.Slice {
responseSuccess.Meta.Limit = lenPayload.Len()
responseSuccess.Meta.RecordCount = lenPayload.Len()
}
response, _ := json.Marshal(responseSuccess)
responseWriter.Header().Set("Content-Type", "application/json")
responseWriter.WriteHeader(code)
responseWriter.Write(response)
}
{"meta":{"limit":1,"offset":0,"recordCount":1},"records":{}}
Hello Caio, could add the return?
– Gabriel Souza
Hello Gabriel, added the return
– Caio