app registration check
This commit is contained in:
parent
287b1f5a30
commit
08d8450dac
4 changed files with 101 additions and 10 deletions
|
|
@ -1,12 +1,15 @@
|
|||
package config
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App App
|
||||
Http Http
|
||||
TasksSource TasksSource
|
||||
DBase DBase
|
||||
Auth Auth
|
||||
}
|
||||
|
||||
type App struct {
|
||||
|
|
@ -35,6 +38,18 @@ type DBase struct {
|
|||
DBName string
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
Host string
|
||||
Port string
|
||||
Name string
|
||||
Description string
|
||||
BaseCode int
|
||||
EndCode int
|
||||
SecretHash string
|
||||
Status string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
func NewConfig() Config {
|
||||
return Config{
|
||||
App: App{
|
||||
|
|
@ -62,5 +77,17 @@ func NewConfig() Config {
|
|||
Password: getEnv("DB_PASSWORD", "7kek8wait9"),
|
||||
DBName: getEnv("DB_NAME", "merch_dev"),
|
||||
},
|
||||
|
||||
Auth: Auth{
|
||||
Host: getEnv("AUTH_HOST", "127.0.0.1"),
|
||||
Port: getEnv("AUTH_PORT", "19090"),
|
||||
Name: getEnv("AUTH_NAME", "merch_api"),
|
||||
Description: getEnv("AUTH_DESCRIPTION", "merch_api_service"),
|
||||
BaseCode: getEnvInt("AUTH_BASE_CODE", 10_000),
|
||||
EndCode: getEnvInt("AUTH_END_CODE", 11_000),
|
||||
SecretHash: getEnv("AUTH_SECRET_HASH", "123"),
|
||||
Status: getEnv("AUTH_STATUS", getEnv("AUTH_STATUS", "active")),
|
||||
Timeout: getEnvSeconds("AUTH_CONNECT_TIMEOUT_SECONDS", 60),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,3 +39,15 @@ func getEnvUint(key string, fallback uint) uint {
|
|||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func getEnvInt(key string, fallback int) int {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
num, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
log.Printf("Error converting %v to int, using fallback value - %v", key, fallback)
|
||||
return fallback
|
||||
}
|
||||
return num
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue