nettools/config/common.go

29 lines
600 B
Go
Raw Normal View History

2024-11-12 08:10:09 +00:00
package config
import common_utils "nettools/common"
type FileTLS struct {
Enable bool `yaml:"enable" json:"enable"`
Cert string `yaml:"cert" json:"cert"`
Key string `yaml:"key" json:"key"`
}
type TLS struct {
Cert string
Key string
}
func ApplyEnv(fileCfg FileTLS) *FileTLS {
return &FileTLS{}
}
func NewTlsConfigFromFile(fileCfg *FileTLS, defaultCertPath, defaultKeyPath string) *TLS {
if !fileCfg.Enable {
return nil
}
return &TLS{
Cert: common_utils.ValOrDefaultStr(fileCfg.Cert, defaultCertPath),
Key: common_utils.ValOrDefaultStr(fileCfg.Key, defaultKeyPath),
}
}