Skip to content

Commit

Permalink
Add check to only serve swagger on development
Browse files Browse the repository at this point in the history
  • Loading branch information
daison12006013 committed Jun 2, 2024
1 parent ed62f1e commit 6d1ee5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The project also integrates with LOG_SENTRY_LEVEL (default: "warn") and includes

```
# app
APP_ENV="production"
APP_KEY="YourAPPKeyHere"
APP_DEBUG=true
APP_PORT="8080"
Expand Down
8 changes: 5 additions & 3 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ func main() {
hr.Map("api\\.(.*)", apiRouter)
r.Mount("/", hr)

r.Get("/swagger/*", httpSwagger.Handler(
httpSwagger.URL("/swagger/doc.json"),
))
if utils.IsDevelopment() {
r.Get("/swagger/*", httpSwagger.Handler(
httpSwagger.URL("/swagger/doc.json"),
))
}

fmt.Printf("Server is listening on port %s...\n", port)
log.Fatal(http.ListenAndServe(":"+port, r))
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func Validator() *validator.Validate {
return validate
}

func AppEnv() string {
return GetEnvWithDefault("APP_ENV", "production")
}

func IsDevelopment() bool {
return strings.HasPrefix(AppEnv(), "dev")
}

type ContextKey string

func (c ContextKey) String() string {
Expand Down

0 comments on commit 6d1ee5e

Please sign in to comment.