Setting up Route Not Found in Gin
What you’re looking for is the NoRoute handler. More precisely: r := gin.Default() r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{“code”: “PAGE_NOT_FOUND”, “message”: “Page not found”}) })
What you’re looking for is the NoRoute handler. More precisely: r := gin.Default() r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{“code”: “PAGE_NOT_FOUND”, “message”: “Page not found”}) })
So the solution was to initialize it with : productConstructed.BrandMedals = make([]string, 0)
You should be able to do c.Request.URL.Query() which will return a Values which is a map[string][]string
FWIW, this is my CORS Middleware that works for my needs. func CORSMiddleware() gin.HandlerFunc { return func(c *gin.Context) { c.Writer.Header().Set(“Access-Control-Allow-Origin”, “*”) c.Writer.Header().Set(“Access-Control-Allow-Credentials”, “true”) c.Writer.Header().Set(“Access-Control-Allow-Headers”, “Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With”) c.Writer.Header().Set(“Access-Control-Allow-Methods”, “POST, OPTIONS, GET, PUT”) if c.Request.Method == “OPTIONS” { c.AbortWithStatus(204) return } c.Next() } }
I would avoid stuffing ‘application scoped’ dependencies (e.g. a DB connection pool) into a request context. Your two ‘easiest’ options are: Make it a global. This is OK for smaller projects, and *sql.DB is thread-safe. Pass it explicitly in a closure so that the return type satisfies gin.HandlerFunc e.g. // SomeHandler returns a `func(*gin.Context)` to … Read more