func LoadBangoConfig(fileName string) { var err error _, err = os.Stat(fileName) if err != nil { if os.IsNotExist(err) { panic("Configuration file does not exists: " + err.Error()) } else { panic("Something wrong with configuration file: " + err.Error()) } } var cfg *goconfig.ConfigFile cfg, err = goconfig.LoadConfigFile(fileName) if err != nil { panic("Fail to load configuration file: " + err.Error()) } // Parse the global section config.global.debug = cfg.MustBool("global", "debug", false) // Parse the redis section config.redis.server = cfg.MustValue("redis", "server", "localhost") config.redis.port = cfg.MustValue("redis", "port", "6379") config.redis.db = cfg.MustInt("redis", "db", 0) config.redis.pass = cfg.MustValue("redis", "pass", "") // Parse the fail2ban section config.fail2ban.channel = cfg.MustValue("fail2ban", "channel", "fail2ban") config.fail2ban.jail = cfg.MustValue("fail2ban", "jail", "fail2ban-recidive") config.fail2ban.useF2C = cfg.MustBool("fail2ban", "usef2bclient", true) }
func runRun(ctx *cli.Context) { setup(ctx) //support unix only if ctx.Bool("local") { var localPath string var err error var wd string var gf *goconfig.ConfigFile wd, _ = os.Getwd() for wd != "/" { gf, _ = goconfig.LoadConfigFile(".gopmfile") if gf != nil { localPath = gf.MustValue("project", "localPath") } if localPath != "" { break } os.Chdir("..") wd, _ = os.Getwd() } if wd == "/" { log.Fatal("run", "no gopmfile in the directory or parent directory") } argss := gf.MustValue("run", "cmd") if localPath == "" { log.Fatal("run", "No localPath set") } args := strings.Split(argss, " ") argsLen := len(args) for i := 0; i < argsLen; i++ { strings.Trim(args[i], " ") } if len(args) < 2 { log.Fatal("run", "cmd arguments less than 2") } err = execCmd(localPath, localPath, args...) if err != nil { log.Error("run", "Fail to run program:") log.Fatal("", "\t"+err.Error()) } return } // Get GOPATH. installGopath = com.GetGOPATHs()[0] if com.IsDir(installGopath) { isHasGopath = true log.Log("Indicated GOPATH: %s", installGopath) installGopath += "/src" } // run command with gopm repos context // need version control , auto link to GOPATH/src repos genNewGoPath(ctx, false) defer os.RemoveAll(doc.VENDOR) log.Trace("Running...") cmdArgs := []string{"go", "run"} cmdArgs = append(cmdArgs, ctx.Args()...) err := execCmd(newGoPath, newCurPath, cmdArgs...) if err != nil { log.Error("run", "Fail to run program:") log.Fatal("", "\t"+err.Error()) } log.Success("SUCC", "run", "Command executed successfully!") }