49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.apinb.com/bsm-sdk/core/conf"
|
|
)
|
|
|
|
const ServiceKey = "all"
|
|
|
|
type ServiceConfig map[string]any
|
|
|
|
type SrvConfig struct {
|
|
conf.Base `yaml:",inline"`
|
|
Databases *conf.DBConf `yaml:"Databases"`
|
|
Etcd *conf.EtcdConf `yaml:"Etcd"`
|
|
Services map[string]ServiceConfig `yaml:"Services"`
|
|
}
|
|
|
|
var Spec SrvConfig
|
|
|
|
func New() {
|
|
conf.New(ServiceKey, &Spec)
|
|
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)
|
|
conf.PrintInfo(Spec.Addr)
|
|
}
|
|
|
|
func Enabled(name string) bool {
|
|
if raw := strings.TrimSpace(os.Getenv("BSM_SERVICES")); raw != "" {
|
|
for _, selected := range strings.Split(raw, ",") {
|
|
if strings.EqualFold(strings.TrimSpace(selected), name) || strings.EqualFold(strings.TrimSpace(selected), "all") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
service, ok := Spec.Services[name]
|
|
if !ok {
|
|
return false
|
|
}
|
|
enabled, ok := service["Enable"].(bool)
|
|
return !ok || enabled
|
|
}
|