new fields
This commit is contained in:
parent
ca36d84a03
commit
f6e99b2b65
3 changed files with 41 additions and 15 deletions
10
config.env
10
config.env
|
|
@ -1,13 +1,15 @@
|
||||||
#[APP]
|
#[APP]
|
||||||
APP_MODE=dev
|
APP_MODE=dev
|
||||||
APP_LOG_LVL=info
|
APP_LOG_LVL=info
|
||||||
|
APP_CHECK_PERIOD_SECONDS=21600
|
||||||
|
|
||||||
#[HTTP]
|
#[HTTP]
|
||||||
HOST=0.0.0.0
|
HTTP_HOST=0.0.0.0
|
||||||
PORT=41082
|
HTTP_PORT=41082
|
||||||
|
|
||||||
#[TASKS SOURCE(GRPC)]
|
#[TASKS SOURCE(GRPC)]
|
||||||
HOST=
|
TASK_SOURCE_HOST=
|
||||||
PORT=
|
TASK_SOURCE_PORT=
|
||||||
|
TASK_SOURCE_TIMEOUT_SECONDS=
|
||||||
|
|
||||||
#[RABBIT]
|
#[RABBIT]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
App App
|
App App
|
||||||
Http Http
|
Http Http
|
||||||
|
|
@ -9,6 +11,7 @@ type Config struct {
|
||||||
type App struct {
|
type App struct {
|
||||||
Mode string
|
Mode string
|
||||||
LogLvl string
|
LogLvl string
|
||||||
|
CheckPeriod time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type Http struct {
|
type Http struct {
|
||||||
|
|
@ -19,6 +22,7 @@ type Http struct {
|
||||||
type TasksSource struct {
|
type TasksSource struct {
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() Config {
|
func NewConfig() Config {
|
||||||
|
|
@ -26,16 +30,18 @@ func NewConfig() Config {
|
||||||
App: App{
|
App: App{
|
||||||
Mode: getEnv("APP_MODE", "dev"),
|
Mode: getEnv("APP_MODE", "dev"),
|
||||||
LogLvl: getEnv("APP_LOG_LVL", "debug"),
|
LogLvl: getEnv("APP_LOG_LVL", "debug"),
|
||||||
|
CheckPeriod: getEnvSeconds("APP_CHECK_PERIOD_SECONDS", 20),
|
||||||
},
|
},
|
||||||
|
|
||||||
Http: Http{
|
Http: Http{
|
||||||
Host: getEnv("HOST", "0.0.0.0"),
|
Host: getEnv("HTTP_HOST", "0.0.0.0"),
|
||||||
Port: getEnv("PORT", "41082"),
|
Port: getEnv("HTTP_PORT", "41082"),
|
||||||
},
|
},
|
||||||
|
|
||||||
TasksSource: TasksSource{
|
TasksSource: TasksSource{
|
||||||
Host: getEnv("TASK_API_HOST", ""),
|
Host: getEnv("TASK_API_HOST", ""),
|
||||||
Port: getEnv("TASK_API_PORT", ""),
|
Port: getEnv("TASK_API_PORT", ""),
|
||||||
|
Timeout: getEnvSeconds("TASK_SOURCE_TIMEOUT_SECONDS", 60),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func getEnv(key, fallback string) string {
|
func getEnv(key, fallback string) string {
|
||||||
if value, ok := os.LookupEnv(key); ok {
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
|
|
@ -8,3 +13,16 @@ func getEnv(key, fallback string) string {
|
||||||
}
|
}
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnvSeconds(key string, fallback int) time.Duration {
|
||||||
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
|
num, err := strconv.Atoi(value)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error converting %v to int, using default value - 60 seconds", key)
|
||||||
|
return time.Duration(60) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Duration(num) * time.Second
|
||||||
|
}
|
||||||
|
return time.Duration(fallback) * time.Second
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue