diff --git a/README.MD b/README.MD index 1807fa1..282e9a4 100644 --- a/README.MD +++ b/README.MD @@ -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" diff --git a/cmd/http/main.go b/cmd/http/main.go index 64e4297..88d7964 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -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)) diff --git a/pkg/utils/helpers.go b/pkg/utils/helpers.go index 337e7c5..0b6764c 100644 --- a/pkg/utils/helpers.go +++ b/pkg/utils/helpers.go @@ -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 {