func Load() { HELP := flag.Bool("help", false, "Show all the help infomation") VERSION := flag.Bool("version", false, "Show version") HOST = flag.String("host", "0.0.0.0", "Listening host") PORT = flag.Int("port", 10101, "Listening port") LOGPATH = flag.String("logPath", "", "Log path") SCRIPT = flag.String("script", "", "dog script path") TELKEY = flag.String("telkey", "", "the peer key which is used to tranfer infomation between shepherd and shepherd-dog.") flag.Parse() if *HELP { fmt.Println("====================================") fmt.Println("============shepherd-dog============") fmt.Println("====================================") fmt.Println("Usage:\n") flag.PrintDefaults() os.Exit(0) } if *VERSION { fmt.Printf("Version:%s \n", VER) os.Exit(0) } switch { case *SCRIPT == "": fmt.Printf("Shepherd-dog:You must specify a dog script.\n") os.Exit(-1) case !util.ExistFile(*SCRIPT): fmt.Printf("Shepherd-dog:Can not find the script '%s',Please check the path.", *SCRIPT) os.Exit(-1) } }
func LoadConfigFile() []SHEEPCFG { var configFile MAINCFG meta, err := toml.DecodeFile(*CFGFILE, &configFile) if err != nil { fmt.Printf("Shepherd Configuration Error:%s", err.Error()) os.Exit(-1) } if meta.IsDefined(globlCfgIndex, "algorithm") { ALGORITHM = configFile.Shepherd.Algorithm } if meta.IsDefined(globlCfgIndex, "assignScript") { if !util.ExistFile(configFile.Shepherd.AssignScript) { fmt.Printf("Shepherd:Can not find the assign script '%s',Please check the path.\n", configFile.Shepherd.AssignScript) os.Exit(-1) } ASSIGNSCRIPT = configFile.Shepherd.AssignScript } if meta.IsDefined(globlCfgIndex, "assignType") { ASSIGNTYPE = configFile.Shepherd.AssignType } if meta.IsDefined(globlCfgIndex, "cport") { DEFAULTCPORT = configFile.Shepherd.Cport } if meta.IsDefined(globlCfgIndex, "port") { PORT = configFile.Shepherd.Port } if meta.IsDefined(globlCfgIndex, "period") { PERIOD = configFile.Shepherd.Period } if meta.IsDefined(globlCfgIndex, "logPath") { LOGPATH = configFile.Shepherd.LogPath } if meta.IsDefined(globlCfgIndex, "retry") { RETRY = configFile.Shepherd.Retry } if meta.IsDefined(globlCfgIndex, "host") { HOST = configFile.Shepherd.Host } if meta.IsDefined(globlCfgIndex, "telkey") { TELKEY = configFile.Shepherd.Telkey } if meta.IsDefined(globlCfgIndex, "dataPath") { DATAPATH = configFile.Shepherd.DataPath } if meta.IsDefined(globlCfgIndex, "perFileSize") { PERFILESIZE = configFile.Shepherd.PerFileSize } for index := 0; index < len(configFile.Sheep); index++ { if configFile.Sheep[index].NAME == "" { fmt.Printf("Shepherd Configuration Error:You must specify a name to the sheep id:'%d'\n", index) os.Exit(-1) } if configFile.Sheep[index].HOST == "" { fmt.Printf("Shepherd Configuration Error:You must specify a host to the sheep '%s'\n", index) os.Exit(-1) } if configFile.Sheep[index].PORT < 1 { configFile.Sheep[index].PORT = DEFAULTCPORT } if configFile.Sheep[index].CAPACITY < 1 { configFile.Sheep[index].CAPACITY = 50 } } SHEEPLEN = len(configFile.Sheep) return configFile.Sheep }