コード例 #1
0
ファイル: v2.go プロジェクト: miros/init-exporter
func mustGetInt(yaml *simpleyaml.Yaml, key string) int {
	if rawVal := yaml.Get(key); isPresent(rawVal) {
		if val, err := rawVal.Int(); err != nil {
			panic(fmt.Sprintf("%s is not integer", key))
		} else {
			return val
		}
	}

	return 0
}
コード例 #2
0
ファイル: v2.go プロジェクト: miros/init-exporter
func parseCommands(yaml *simpleyaml.Yaml, commands map[interface{}]interface{}) []Service {
	commonOptions := getServiceOptions(yaml)
	services := make([]Service, 0, len(commands))

	for key, _ := range commands {
		name := toString(key)
		commandYaml := yaml.GetPath("commands", name)
		cmd, _ := commandYaml.Get("command").String()

		service := Service{
			Name:    name,
			Cmd:     cmd,
			Options: getServiceOptions(commandYaml),
		}
		mergo.Merge(&service.Options, commonOptions)

		services = append(services, service)
	}

	return services
}
コード例 #3
0
ファイル: v2.go プロジェクト: miros/init-exporter
func getServiceOptions(yaml *simpleyaml.Yaml) ServiceOptions {
	options := ServiceOptions{}

	options.WorkingDirectory, _ = yaml.Get("working_directory").String()
	options.User, _ = yaml.Get("user").String()
	options.Group, _ = yaml.Get("group").String()
	options.KillTimeout = mustGetInt(yaml, "kill_timeout")
	options.LogPath, _ = yaml.Get("log").String()
	options.Count = mustGetInt(yaml, "count")

	if value, err := yaml.Get("env").Map(); err == nil {
		options.Env = toStringMap(value)
	}

	if value := yaml.Get("respawn"); isPresent(value) {
		count := mustGetInt(value, "count")
		interval := mustGetInt(value, "interval")
		options.Respawn = Respawn{Count: count, Interval: interval}
	}

	return options
}