Skip to content

Commit

Permalink
chore: set logger only for non-production
Browse files Browse the repository at this point in the history
  • Loading branch information
martinyonatann committed Jan 4, 2024
1 parent b26d1f1 commit 2f88bb1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"gorm.io/gorm"
)

const (
ENVIRONMENT_NAME_PRODUCTION = "production"
)

// CreateAdminApp creates the fiber app
//
// @title onepixel API
Expand All @@ -34,19 +38,20 @@ import (
// @name X-API-Key
func CreateAdminApp(db *gorm.DB) *fiber.App {
app := fiber.New()
app.Use(logger.NewLogger())

switch config.Env {
case ENVIRONMENT_NAME_PRODUCTION:
docs.SwaggerInfo.Host = config.AdminHost

Check warning on line 44 in src/server/server.go

View check run for this annotation

Codecov / codecov/patch

src/server/server.go#L43-L44

Added lines #L43 - L44 were not covered by tests
default:
app.Use(logger.NewLogger())
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", config.AdminHost, config.Port)
}

apiV1 := app.Group("/api/v1")

apiV1.Route("/users", api.UsersRoute(db))
apiV1.Route("/urls", api.UrlsRoute(db))

if config.Env == "production" {
docs.SwaggerInfo.Host = config.AdminHost
} else {
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", config.AdminHost, config.Port)
}

app.Get("/docs/*", swagger.HandlerDefault)

return app
Expand Down

0 comments on commit 2f88bb1

Please sign in to comment.