IniConfig.go 757 Bytes
Newer Older
吴贤德's avatar
吴贤德 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
package Config

import (
	"flag"
	iniReader "github.com/larspensjo/config"
	log "github.com/sirupsen/logrus"
	"runtime"
)

func initIniConfig(dir string, configName string, topic string) map[string]string {
	var (
		configFile = flag.String(dir, configName, "General configuration file")
	)

	var TOPIC = make(map[string]string)
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	cfg, err := iniReader.ReadDefault(*configFile)
	if err != nil {
		log.Fatal("Fail to find", *configFile, err)
	}

	if cfg.HasSection(topic) {
		section, err := cfg.SectionOptions(topic)
		if err == nil {
			for _, v := range section {
				options, err := cfg.String(topic, v)
				if err == nil {
					TOPIC[v] = options
				}
			}
		}
	}

	log.Infoln(TOPIC)
	return TOPIC
}