lundi 18 mars 2019

Go. Omit some parameters of structure Gin gonic

I have big structure with more than 50 params

type Application struct {
    Id                  int64   `json:"id"`
    FullName            string  `json:"fullName,omitempty"`
    ActualAddress       string  `json:"actualAddress,omitempty"`
.....
}

I use gin-gonic and when I return application I need to omit some params. I've created a function which makes empty some params(playLink) and then gin returns me correct json(without unnecessary values). I heard that reflection isn't fast operation so in our case we can use a lot of ugly if-else or switch-cases. Is there any other solutions faster than reflecting and more beautiful than if-elses?





Aucun commentaire:

Enregistrer un commentaire