HFish/utils/conf/conf.go

72 lines
1.1 KiB
Go
Raw Normal View History

2019-08-07 13:16:23 +08:00
package conf
import (
2019-09-02 12:56:08 +08:00
"gopkg.in/ini.v1"
"HFish/utils/log"
2020-04-12 22:19:13 +08:00
"container/list"
2019-08-07 13:16:23 +08:00
)
2019-09-02 12:56:08 +08:00
var cfg *ini.File
2019-08-07 13:16:23 +08:00
2019-09-02 12:56:08 +08:00
func init() {
c, err := ini.Load("./config.ini")
2019-08-07 13:16:23 +08:00
if err != nil {
2019-09-02 12:56:08 +08:00
log.Pr("HFish", "127.0.0.1", "打开配置文件失败", err)
2019-08-07 13:16:23 +08:00
}
2019-09-02 12:56:08 +08:00
c.BlockMode = false
cfg = c
2019-08-07 13:16:23 +08:00
}
func Get(node string, key string) string {
2019-09-02 12:56:08 +08:00
val := cfg.Section(node).Key(key).String()
return val
2019-08-07 13:16:23 +08:00
}
2019-09-02 19:12:46 +08:00
func GetInt(node string, key string) int {
val, _ := cfg.Section(node).Key(key).Int()
return val
}
2020-04-12 22:19:13 +08:00
func Contains(l *list.List, value string) (bool, *list.Element) {
for e := l.Front(); e != nil; e = e.Next() {
if e.Value == value {
return true, e
}
}
return false, nil
}
func GetCustomName() []string {
names := cfg.SectionStrings()
existConfig := []string{
"DEFAULT",
"rpc",
"admin",
"api",
"plug",
"web",
"deep",
"ssh",
"redis",
"mysql",
"telnet",
"ftp",
"mem_cache",
"http",
"tftp",
"elasticsearch",
"vnc",
}
for i := 0; i < len(names); i++ {
for j := 0; j < len(existConfig); j++ {
if names[i] == existConfig[j] {
names = append(names[:i], names[i+1:]...)
}
}
}
return names
}