func getRootNode(t *testing.T, ymlString string) yaml.Node { config := yaml.Config(ymlString) if config == nil { t.Fatal("Got errors trying to parse test input yaml string [%s]", ymlString) return nil } configMap, _ := nodeToMap(config.Root) return configMap["root"] }
// parseYamlString transforms a yaml string into readable yaml structure func parseYamlString(yamlString string) yaml.Node { // Note : yaml.Config doesn't return an error message to bubble up, instead it panics config := yaml.Config(yamlString) if config == nil { return nil } return config.Root }
func (c *handlerYaml) ImportFile(filename string) error { content, err := ioutil.ReadFile(filename) if err != nil { return err } c.raw = string(content) c.m = yaml.Config(c.raw) return nil }
func TestConfig(t *testing.T) { for _, test := range configTests { _, err := ParseConfig(yaml.Config(test.Spec)) var got string switch err { case nil: got = "" default: got = err.Error() } if want := test.Err; got != want { t.Errorf("Get(%q) error %#q, want %#q", test.Spec, got, want) } } }
func initLogAndConfig(logPath, confPath string) { logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0700) if err != nil { panic(err) } log.SetOutput(logFile) log.SetFlags(5) //read the config and build config stuff confFile, err := ioutil.ReadFile(confPath) if err != nil { log.Panic(err) } Config = yaml.Config(string(confFile)) }
func initlogAndConfig() { //create log log_file, err := os.OpenFile(*log_file_name, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) if err != nil { panic("cannot write log") } log.SetOutput(log_file) log.SetFlags(5) //read the config and build config stuff c_file, err := ioutil.ReadFile(*config_file) if err != nil { log.Panic("no config file found") } config = yaml.Config(string(c_file)) }
func parseConfig(body []byte, url string) (conf *Config, err error) { defer func() { if e := recover(); e != nil { // Clear return value. conf = nil body := string(body) if len(body) > 200 { body = body[:200] + "..." } err = fmt.Errorf("Failed to parse config file at %s:\n\n%s", url, body) } }() // Parse the YAML file. yamlFile := yaml.Config(string(body)) count, e := yamlFile.Count("line_rules") if e != nil { err = fmt.Errorf("Could not get line_rules config section.") return } // Extract the line rules. conf = &Config{} conf.lineRules = make([]*LineRule, count) for i, _ := range conf.lineRules { pattern, e := yamlFile.Get(fmt.Sprintf("line_rules[%d].pattern", i)) if e != nil { return nil, e } message, e := yamlFile.Get(fmt.Sprintf("line_rules[%d].message", i)) if e != nil { return nil, e } conf.lineRules[i] = &LineRule{pattern, nil, message} } return conf, nil }
func (c *handlerYaml) Import(raw string) error { c.m = yaml.Config(raw) c.raw = raw return nil }