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 }
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 }