Skip to content

Commit

Permalink
fix: load host or IP from .env
Browse files Browse the repository at this point in the history
  • Loading branch information
pilinux committed Aug 5, 2023
1 parent 8038852 commit 5e8d37f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ func security() (securityConfig SecurityConfig, err error) {

// server - port and env
func server() (serverConfig ServerConfig, err error) {
serverConfig.ServerHost = strings.TrimSpace(os.Getenv("APP_HOST"))
serverConfig.ServerPort = strings.TrimSpace(os.Getenv("APP_PORT"))
serverConfig.ServerEnv = strings.TrimSpace(os.Getenv("APP_ENV"))

Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestGetConfig(t *testing.T) {
}
expected.Logger.SentryDsn = "https://xyz.ingest.sentry.io/123456"

expected.Server.ServerHost = "localhost"
expected.Server.ServerPort = "3000"
expected.Server.ServerEnv = "development"

Expand Down
1 change: 1 addition & 0 deletions config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

// ServerConfig ...
type ServerConfig struct {
ServerHost string
ServerPort string // public port of server
ServerEnv string
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
return
}
// Attaches the router to a http.Server and starts listening and serving HTTP requests
err = r.Run(":" + configure.Server.ServerPort)
err = r.Run(configure.Server.ServerHost + ":" + configure.Server.ServerPort)
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion example/router/setupRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// SetupRouter sets up all the routes
func SetupRouter(configure *gconfig.Configuration) (*gin.Engine, error) {
if configure.Server.ServerEnv == "production" {
gin.SetMode(gin.ReleaseMode) // Omit this line to enable debug mode
gin.SetMode(gin.ReleaseMode)
}

// Write log file
Expand Down

0 comments on commit 5e8d37f

Please sign in to comment.