Files
natpass/code/server/global/conf.go
T
2021-08-12 15:15:22 +08:00

38 lines
647 B
Go

package global
import (
"crypto/md5"
"os"
"github.com/lwch/runtime"
"gopkg.in/yaml.v2"
)
type Configure struct {
Listen uint16
Enc [md5.Size]byte
TLSKey string
TLSCrt string
}
func LoadConf(dir string) *Configure {
var cfg struct {
Listen uint16 `yaml:"listen"`
Secret string `yaml:"secret"`
TLS struct {
Key string `yaml:"key"`
Crt string `yaml:"crt"`
} `yaml:"tls"`
}
f, err := os.Open(dir)
runtime.Assert(err)
defer f.Close()
runtime.Assert(yaml.NewDecoder(f).Decode(&cfg))
return &Configure{
Listen: cfg.Listen,
Enc: md5.Sum([]byte(cfg.Secret)),
TLSKey: cfg.TLS.Key,
TLSCrt: cfg.TLS.Crt,
}
}