add config

This commit is contained in:
kandrusyak
2023-06-30 17:14:01 +03:00
parent 8e9eeb989c
commit 827b8231a6
2 changed files with 33 additions and 1 deletions

31
config/config.go Normal file
View File

@@ -0,0 +1,31 @@
package config
import (
"os"
)
type ServerConfig struct {
Port string
}
type Config struct {
Server ServerConfig
}
func New() *Config {
return &Config{
Server: ServerConfig{
Port: getEnv("PORT", ""),
},
}
}
func getEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}
var Env = New()

View File

@@ -1,6 +1,7 @@
package main
import (
"astra-users/config"
"astra-users/handler"
"astra-users/model"
"github.com/labstack/echo/v4"
@@ -48,5 +49,5 @@ func main() {
e.DELETE("/:id", h.DeleteUser)
e.GET("/health", h.Health)
e.Logger.Fatal(e.Start(":8081"))
e.Logger.Fatal(e.Start(":" + config.Env.Server.Port))
}