* Rename fsldap to efsldap
* Use gopkg.in/ini.v1 over github.com/joho/godotenv * Fix typos Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
43
config/config.go
Normal file
43
config/config.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
var Config struct {
|
||||
LDAPBase string
|
||||
LDAPUID string
|
||||
SMTPDomain string
|
||||
SMTPHost string
|
||||
SMTPPort string
|
||||
}
|
||||
|
||||
var (
|
||||
ConfigPath string
|
||||
)
|
||||
|
||||
func ConfInit() {
|
||||
if _, err := os.Stat(ConfigPath); errors.Is(err, os.ErrNotExist) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
Parse(ConfigPath)
|
||||
}
|
||||
|
||||
func Parse(fn string) error {
|
||||
cfg, err := ini.Load(fn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Config.LDAPBase = cfg.Section("").Key("ldap_base").String()
|
||||
Config.LDAPUID = cfg.Section("").Key("ldap_uid").String()
|
||||
Config.SMTPDomain = cfg.Section("").Key("smtp_domain").String()
|
||||
Config.SMTPHost = cfg.Section("").Key("smtp_host").String()
|
||||
Config.SMTPPort = cfg.Section("").Key("smtp_port").String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user