2

I am working on a CMS project where the URL for the frontend is https://cms.example.com

However, the backend routes start with /v1 which I have configured in gin as a Router Group engine.Group("/v1"). Hence a backend endpoint will be something like https://cms.example.com/v1/endpoint

I've also set a NoRoute handler function:

var errRouteNotFound = errors.New("route not found")
s.engine.NoRoute(func(c *gin.Context) {
 c.AbortWithError(http.StatusNotFound, errRouteNotFound)
})

The issue I am facing is that whenever someone visits the frontend, I get a 404 error for GET request on / in the backend logs. How can I avoid getting these logs without changing the route schema as it's part of a bigger project?

Edit: I am using a custom logger.

MRA1412
  • 57
  • 8
  • Does this answer your question? [Disable request logging for a particular Go-Gin route](https://stackoverflow.com/questions/48780070/disable-request-logging-for-a-particular-go-gin-route) – Emile Pels Feb 23 '23 at 08:17
  • @EmilePels I'm using a custom logger so this won't work. – MRA1412 Feb 23 '23 at 09:14
  • then you're not going to get a helpful answer without supplying more information about that. This question is not about Gin, but about your "custom logger". – Emile Pels Feb 23 '23 at 09:18

1 Answers1

1

I found the solution:

In case gin's logger is used

Use this answer. Thanks to @EmilePels.

In case of a custom logger

Use something like this in the logger function:

requestURL := c.Request.URL.String()
if requestURL == "/" {
  return
}
MRA1412
  • 57
  • 8