func getChecks() []Check { var checks []Check if err := viper.UnmarshalKey("checks", &checks); err != nil { return nil } return checks }
func main() { log.Debug("start ") log.Info(viper.GetString("url")) log.Info(viper.GetString("author.name")) var u User err := viper.UnmarshalKey("author", &u) if err != nil { log.Error(err) return } log.Info(u) closeAll := make(chan int) go func() { for { select { case <-time.Tick(time.Second): log.Info("one second gone...") case <-closeAll: log.Debug("over") return } } }() util.WaitForExit(true, closeAll) }
func getDockerHostConfig() *docker.HostConfig { if hostConfig != nil { return hostConfig } dockerKey := func(key string) string { return "vm.docker.hostConfig." + key } getInt64 := func(key string) int64 { defer func() { if err := recover(); err != nil { dockerLogger.Warningf("load vm.docker.hostConfig.%s failed, error: %v", key, err) } }() n := viper.GetInt(dockerKey(key)) return int64(n) } var logConfig docker.LogConfig err := viper.UnmarshalKey(dockerKey("LogConfig"), &logConfig) if err != nil { dockerLogger.Warningf("load docker HostConfig.LogConfig failed, error: %s", err.Error()) } networkMode := viper.GetString(dockerKey("NetworkMode")) if networkMode == "" { networkMode = "host" } dockerLogger.Debugf("docker container hostconfig NetworkMode: %s", networkMode) hostConfig = &docker.HostConfig{ CapAdd: viper.GetStringSlice(dockerKey("CapAdd")), CapDrop: viper.GetStringSlice(dockerKey("CapDrop")), DNS: viper.GetStringSlice(dockerKey("Dns")), DNSSearch: viper.GetStringSlice(dockerKey("DnsSearch")), ExtraHosts: viper.GetStringSlice(dockerKey("ExtraHosts")), NetworkMode: networkMode, IpcMode: viper.GetString(dockerKey("IpcMode")), PidMode: viper.GetString(dockerKey("PidMode")), UTSMode: viper.GetString(dockerKey("UTSMode")), LogConfig: logConfig, ReadonlyRootfs: viper.GetBool(dockerKey("ReadonlyRootfs")), SecurityOpt: viper.GetStringSlice(dockerKey("SecurityOpt")), CgroupParent: viper.GetString(dockerKey("CgroupParent")), Memory: getInt64("Memory"), MemorySwap: getInt64("MemorySwap"), MemorySwappiness: getInt64("MemorySwappiness"), OOMKillDisable: viper.GetBool(dockerKey("OomKillDisable")), CPUShares: getInt64("CpuShares"), CPUSet: viper.GetString(dockerKey("Cpuset")), CPUSetCPUs: viper.GetString(dockerKey("CpusetCPUs")), CPUSetMEMs: viper.GetString(dockerKey("CpusetMEMs")), CPUQuota: getInt64("CpuQuota"), CPUPeriod: getInt64("CpuPeriod"), BlkioWeight: getInt64("BlkioWeight"), } return hostConfig }
func main() { // Run Staging Commands mainCmd.AddCommand(stagingCmd) // Run Cleanup Command mainCmd.AddCommand(cleanupCmd) // Perform REDCap Staging stagingCmd.AddCommand(redcapStagingCmd) // Perform Nautilus Staging stagingCmd.AddCommand(nautilusStagingCmd) // Perform eHB Staging stagingCmd.AddCommand(ehbStagingCmd) // Perform Transform of staging data mainCmd.AddCommand(transformCmd) // Stage and transform the data. mainCmd.AddCommand(etlCmd) viper.SetEnvPrefix("brp_demo") viper.AutomaticEnv() viper.SetConfigName("config") // Directory the program is being called from dir, err := filepath.Abs(filepath.Dir(os.Args[0])) if err == nil { viper.AddConfigPath(dir) } viper.ReadInConfig() err = viper.UnmarshalKey("targets", &targets) if err != nil { log.Println(err) } err = viper.UnmarshalKey("sources", &sources) if err != nil { log.Println(err) } mainCmd.Execute() }
func TestHostConfig(t *testing.T) { config.SetupTestConfig("./../../../peer") var hostConfig = new(docker.HostConfig) err := viper.UnmarshalKey("vm.docker.hostConfig", hostConfig) if err != nil { t.Fatalf("Load docker HostConfig wrong, error: %s", err.Error()) } testutil.AssertNotEquals(t, hostConfig.LogConfig, nil) testutil.AssertEquals(t, hostConfig.LogConfig.Type, "json-file") testutil.AssertEquals(t, hostConfig.LogConfig.Config["max-size"], "50m") testutil.AssertEquals(t, hostConfig.LogConfig.Config["max-file"], "5") }
func runTarball(binariesLocation string) { defer shell.ErrExit() shell.Tee = os.Stdout if viper.GetBool("verbose") { shell.Trace = true } info := NewProjectInfo() var ( prefix = viper.GetString("tarball.prefix") tmpDir = ".release" goos = envOr("GOOS", goos) goarch = envOr("GOARCH", goarch) name = fmt.Sprintf("%s-%s.%s-%s", info.Name, info.Version, goos, goarch) binaries []Binary ext string ) if goos == "windows" { ext = ".exe" } dir := filepath.Join(tmpDir, name) if err := os.MkdirAll(dir, 0777); err != nil { fatalMsg(err, "Failed to create directory") } defer sh("rm -rf", tmpDir) projectFiles := viper.GetStringSlice("tarball.files") for _, file := range projectFiles { sh("cp -a", file, dir) } err := viper.UnmarshalKey("build.binaries", &binaries) fatalMsg(err, "Failed to Unmashal binaries :") for _, binary := range binaries { binaryName := fmt.Sprintf("%s%s", binary.Name, ext) sh("cp -a", shell.Path(binariesLocation, binaryName), dir) } if !fileExists(prefix) { os.Mkdir(prefix, 0777) } tar := fmt.Sprintf("%s.tar.gz", name) fmt.Println(" > ", tar) sh("tar zcf", shell.Path(prefix, tar), "-C", tmpDir, name) }
func init() { err := viper.UnmarshalKey("vm.docker.hostConfig", hostConfig) if err != nil { dockerLogger.Fatalf("Load docker HostConfig wrong, error: %s", err.Error()) } if hostConfig.NetworkMode == "" { hostConfig.NetworkMode = "host" } // not support customize hostConfig.Privileged = false dockerLogger.Debugf("Load docker HostConfig: %+v", hostConfig) }
// GetUser implements auth.Authable interface. func (authenticaton *FileAuthentication) GetUser(header *http.Header) User { var user FileUser token := header.Get("Token") if token == "" { return nil } viper.UnmarshalKey(fmt.Sprintf("%s.%s", TokensConfigPath, token), &user) if user == NilFileUser { return nil } return user }
func runBuild() { defer shell.ErrExit() shell.Tee = os.Stdout if viper.GetBool("verbose") { shell.Trace = true } info := NewProjectInfo() var ( prefix = viper.GetString("build.prefix") repoPath = viper.GetString("repository.path") flags = viper.GetString("build.flags") ext string binaries []Binary ldflags string ) if goos == "windows" { ext = ".exe" } ldflags = getLdflags(info) ldflag := fmt.Sprintf("-ldflags \"%s\"", ldflags) os.Setenv("GO15VENDOREXPERIMENT", "1") err := viper.UnmarshalKey("build.binaries", &binaries) fatalMsg(err, "Failed to Unmashal binaries :") for _, binary := range binaries { binaryName := fmt.Sprintf("%s%s", binary.Name, ext) fmt.Printf(" > %s\n", binaryName) sh("go build", flags, ldflag, "-o", shell.Path(prefix, binaryName), shell.Path(repoPath, binary.Path)) } }
func FillServiceConfigFromFile(config *proxy.ServiceConfig, filename string) error { viper.SetConfigName(filename) viper.AddConfigPath(".") // look in the working dir err := viper.ReadInConfig() if err != nil { return fmt.Errorf("Error when loading config: %s", err) } //log.Println(viper.Get("Routes")) _brokers := []proxy.BrokerConfig{} err = viper.UnmarshalKey("Brokers", &_brokers) if err != nil { return fmt.Errorf("Error when parsing Brokers: %v", err) } brokers := map[string]proxy.BrokerConfig{} for _, broker := range _brokers { brokers[broker.Id] = broker } log.Println("") config.Brokers = brokers _workers := []FcgiWorkerConfig{} err = viper.UnmarshalKey("Workers", &_workers) if err != nil { return fmt.Errorf("Error when parsing Workers: %v", err) } workers := map[string]proxy.WorkerConfig{} for _, worker := range _workers { workers[worker.GetId()] = &worker } config.Workers = workers err = viper.UnmarshalKey("Routes", &config.Routes) if err != nil { return fmt.Errorf("Error when parsing Routes: %v", err) } for _, route := range config.Routes { _, hasBroker := brokers[route.Broker] _, hasWorker := workers[route.Worker] if !hasWorker || !hasBroker { return fmt.Errorf("Config for route %s is not valid", route.Name) } } return nil }
Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { log.Fatal("Error: You must provide a target") } staging.Add(1) redcapStaging(args) }} var redcapStaging = func(args []string) { defer staging.Done() var Rc REDCapConfig err := viper.UnmarshalKey("REDCap", &Rc) if err != nil { log.Println("unable to decode: %s", err) } target := targets[args[0]] db, err := sql.Open("postgres", fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable", target.Host, target.User, target.Db)) if err != nil { log.Fatal(err) }
url := fmt.Sprintf("%sprotocoldatasources/%d/subjects/", Bc.Url, d.Id) r := brpAPIRequest(url) err := json.Unmarshal(r, &as) if err != nil { log.Fatal(err) } c <- as.Subjects } var generateLinkTable = func(args []string) { defer staging.Done() target_config := targets[args[0]] err := viper.UnmarshalKey("BRP", &Bc) if err != nil { log.Fatal(err) } db, err := sql.Open("postgres", fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable", target_config.Host, target_config.User, target_config.Db)) if err != nil { log.Fatal(err) } defer db.Close()