Initial
This commit is contained in:
commit
995ea60f34
11 changed files with 449 additions and 0 deletions
48
internal/router/handler.go
Normal file
48
internal/router/handler.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"merch-parser-api/internal/interfaces"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type router struct {
|
||||
apiPrefix string
|
||||
engine *gin.Engine
|
||||
ginMode string
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
ApiPrefix string
|
||||
GinMode string
|
||||
}
|
||||
|
||||
func NewRouter(deps Deps) interfaces.Router {
|
||||
engine := gin.Default()
|
||||
|
||||
if deps.GinMode == "release" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
err := engine.SetTrustedProxies([]string{"172.20.0.0/16"})
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Router | Set proxies failed")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return &router{
|
||||
apiPrefix: deps.ApiPrefix,
|
||||
engine: engine,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *router) Set() *gin.Engine {
|
||||
r.engine.NoRoute(func(c *gin.Context) {
|
||||
c.Status(http.StatusForbidden)
|
||||
})
|
||||
|
||||
//version
|
||||
r.engine.GET("/version", func(c *gin.Context) { c.JSON(200, gin.H{"version": "2.0.0-alpha"}) })
|
||||
|
||||
return r.engine
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue