Пример #1
0
func Fetcher() {
	var config Config

	if err := viper.Marshal(&config); err != nil {
		fmt.Println(err)
	}

	for _, feed := range config.Feeds {
		go PollFeed(feed)
	}
}
Пример #2
0
func loadConfig(file string) error {
	viper.SetConfigFile(file)

	err := viper.ReadInConfig()
	if err != nil {
		return err
	}

	err = viper.Marshal(&configs)
	if err != nil {
		return err
	}

	return nil
}
Пример #3
0
// Marshall server config from Yaml file
func (s *Server) getServerConfig() {
	viper.SetConfigName("mongolar")
	viper.AddConfigPath(ServerConfigDirectory)
	err := viper.ReadInConfig()
	if err != nil {
		log.Fatal(err)
	}
	err = viper.Marshal(s)
	if err != nil {
		log.Fatal(err)
	}
	if s.SitesDirectory == "" {
		log.Fatal("No Mongolar sites directory set.")
	}
	if s.LogDirectory == "" {
		log.Fatal("No Mongolar sites directory set.")
	}
}
Пример #4
0
//configInit initializes Howler configuration
func configInit(filename string) (*Config, *ConfigError) {
	viper := viper.New()
	viper.SetConfigType("yaml")
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/howler")
	viper.AddConfigPath(fmt.Sprintf("%s/.config/howler", os.ExpandEnv("$HOME")))
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Printf("Can not read config, caused by: %s\n", err)
		return nil, &ConfigError{"cannot read configuration, something must be wrong."}
	}
	var config Config
	err = viper.Marshal(&config)
	if err != nil {
		fmt.Printf("Can not marshal config, caused by: %s\n", err)
		return nil, &ConfigError{"configuration format is not correct."}
	}
	return &config, nil
}
Пример #5
0
func clientConfigInit(filename string) (*ClientConfig, error) {
	viper := viper.New()
	viper.SetConfigType("yaml")
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/chimp")
	viper.AddConfigPath(fmt.Sprintf("%s/.config/chimp", os.ExpandEnv("$HOME")))
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Printf("Can not read config, caused by: %s", err)
		return nil, err
	}
	var c ClientConfig
	err = viper.Marshal(&c)
	if err != nil {
		fmt.Printf("Can not marshal config, caused by: %s", err)
		return nil, err
	}

	return &c, nil
}
Пример #6
0
//FIXME dirty hack to make labels work
func buildRequest(arguments map[string]interface{}) (*client.CmdClientRequest, error) {
	//reading configuration file
	var c client.CmdClientRequest
	fileName := GetStringFromArgs(arguments, "<filename>", "")
	if fileName != "" {
		viper := viper.New()
		viper.SetConfigFile(fileName)
		err := viper.ReadInConfig()
		if err != nil {
			fmt.Printf("Can not read config, caused by: %s\n", err)
			return nil, err
		}
		err = viper.Marshal(&c)
	} else {
		labelStr := GetStringFromArgs(arguments, "--label", "")
		name := GetStringFromArgs(arguments, "<name>", "")
		labels := ConvertMaps(labelStr)
		envStr := GetStringFromArgs(arguments, "--env", "")
		envVars := ConvertMaps(envStr)
		replicas := GetIntFromArgs(arguments, "--replicas", 1)
		imageURL := GetStringFromArgs(arguments, "<url>", "")
		svcport := GetIntFromArgs(arguments, "--svcport", 8080)
		cpuNumber := GetIntFromArgs(arguments, "--cpu", 0)            //unlimited or backend decided
		memoryLimit := GetStringFromArgs(arguments, "--memory", "0M") //unlimited or backend decided

		ports := []int{svcport}
		c.Labels = labels
		c.Env = envVars
		c.Replicas = replicas
		c.ImageURL = imageURL
		c.CPULimit = cpuNumber
		c.MemoryLimit = memoryLimit
		c.Ports = ports
		c.Name = name
	}

	var force bool = arguments["--force"].(bool)
	c.Force = force
	return &c, nil

}
Пример #7
0
func configInit(filename string) (*Config, *ConfigError) {
	viper := viper.New()
	viper.SetConfigType("yaml")
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/macaque")
	viper.AddConfigPath(fmt.Sprintf("%s/.config/macaque", os.ExpandEnv("$HOME")))
	err := viper.ReadInConfig()
	if err != nil {
		glog.Errorf("Can not read config, caused by: %s", err)
		return nil, &ConfigError{"configuration format is not correct."}
	}
	var config Config

	err = viper.Marshal(&config)
	if err != nil {
		glog.Errorf("Can not marshal config, caused by: %s", err)
		return nil, &ConfigError{"cannot read configuration, something must be wrong."}
	}

	//glog.Infof("config: %+v, %+v", config, viper.Get("cpus_percent"))
	glog.Infof("config: %+v", config.Entry)
	return &config, nil
}
Пример #8
0
func HydrateConfigurationModel() {
	viper.Marshal(&Configuration)
}