audit full project flows and harden backend
This commit is contained in:
@@ -4,6 +4,8 @@ package config
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Spec SrvConfig
|
||||
@@ -30,10 +32,28 @@ type IoTAPIConfig struct {
|
||||
|
||||
func New(srvKey string) {
|
||||
conf.New(srvKey, &Spec)
|
||||
if databaseDSN := strings.TrimSpace(os.Getenv("HEQI_DATABASE_DSN")); databaseDSN != "" {
|
||||
if Spec.Databases == nil {
|
||||
panic("Databases configuration is required")
|
||||
}
|
||||
Spec.Databases.Source = []string{databaseDSN}
|
||||
}
|
||||
if redisURL := strings.TrimSpace(os.Getenv("HEQI_REDIS_URL")); redisURL != "" {
|
||||
Spec.Cache = redisURL
|
||||
}
|
||||
if token := strings.TrimSpace(os.Getenv("HEQI_PAYMENT_INTERNAL_TOKEN")); token != "" {
|
||||
Spec.PaymentAPI.Token = token
|
||||
}
|
||||
if token := strings.TrimSpace(os.Getenv("HEQI_IOT_INTERNAL_TOKEN")); token != "" {
|
||||
Spec.IoTAPI.Token = token
|
||||
}
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
if Spec.Databases == nil || len(Spec.Databases.Source) == 0 {
|
||||
panic("Databases configuration is required")
|
||||
}
|
||||
if Spec.PaymentAPI.BaseURL == "" || Spec.PaymentAPI.Token == "" || Spec.PaymentAPI.IntervalSeconds <= 0 {
|
||||
panic("PaymentAPI configuration is required")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user