I have a Gin middleware that gets data (struct) from a source:
type Data struct {
Key1 string
Key2 int
Key3 bool
}
func GetData() Data {
// returns instant of Data
}
func Middleware(ctx *gin.Context) {
data := GetData()
// I need to add data (struct) to ctx to pass to handler
}
With ctx.Set() I have to marshal and it's hard to unmarshal later.
Is there a way to pass the data to the handler as is? If not, is there a way marshal/unmarshal safely?