Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from bancodobrasil/fix/refactoring-router-group
Browse files Browse the repository at this point in the history
fix: refactoring router group
  • Loading branch information
eliasfeijo authored Aug 10, 2022
2 parents 168db47 + 62422de commit e791c89
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ FEATWS_API_GITLAB_TOKEN=123123d12d12d1
FEATWS_API_GITLAB_URL=https://gitlab.com/api/v4
FEATWS_API_GITLAB_NAMESPACE=teste-featws
FEATWS_API_GITLAB_PREFIX=rules-
FEATWS_API_GITLAB_DEFAULT_BRANCH=main
FEATWS_API_GITLAB_DEFAULT_BRANCH=main
TELEMETRY_DISABLED=false
TELEMETRY_HTTPCLIENT_TLS=false
TELEMETRY_EXPORTER_JAEGER_AGENT_HOST=localhost
TELEMETRY_ENVIRONMENT=local
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
_ "github.com/bancodobrasil/featws-api/docs"
"github.com/bancodobrasil/featws-api/routes"
ginMonitor "github.com/bancodobrasil/gin-monitor"
telemetry "github.com/bancodobrasil/gin-telemetry"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -77,14 +76,14 @@ func main() {
router.Use(ginlogrus.Logger(log.StandardLogger()), gin.Recovery())
router.Use(monitor.Prometheus())
router.GET("metrics", gin.WrapH(promhttp.Handler()))
// inject middleware
router.Use(telemetry.Middleware("featws-api"))

// Setup Routers of health resources, swagger and home endpoint
routes.SetupRoutes(router)
configCors := cors.DefaultConfig()
configCors.AllowOrigins = strings.Split(cfg.AllowOrigins, ",")
router.Use(cors.New(configCors))

routes.SetupRoutes(router)
// Setup API routers
routes.APIRoutes(router)

port := cfg.Port

Expand Down
7 changes: 7 additions & 0 deletions routes/apiRoutes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package routes

// import (
// "github.com/bancodobrasil/featws-api/routes/api"
// telemetry "github.com/bancodobrasil/gin-telemetry"
// "github.com/gin-gonic/gin"
// )
9 changes: 8 additions & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/bancodobrasil/featws-api/docs"
"github.com/bancodobrasil/featws-api/routes/api"
"github.com/bancodobrasil/featws-api/routes/health"
telemetry "github.com/bancodobrasil/gin-telemetry"
"github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
Expand All @@ -18,8 +19,14 @@ func SetupRoutes(router *gin.Engine) {
docs.SwaggerInfo.Host = cfg.ExternalHost

homeRouter(router.Group("/"))
api.Router(router.Group("/api"))
health.Router(router.Group("/health"))
// setup swagger docs
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}

// APIRoutes define all api routes
func APIRoutes(router *gin.Engine) {
// inject middleware
router.Use(telemetry.Middleware("featws-api"))
api.Router(router.Group("/api"))
}
1 change: 1 addition & 0 deletions services/rulesheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
log "github.com/sirupsen/logrus"
)

// FindOptions ...
type FindOptions struct {
Limit int
Page int
Expand Down

0 comments on commit e791c89

Please sign in to comment.