go - Reading a YAML file in Golang -


i have issue reading yaml file. think it's in file structure can't figure out what.

yaml file:

conf:   hits:5   time:5000000 

code:

type conf struct {     hits int64 `yaml:"hits"`     time int64 `yaml:"time"` }   func (c *conf) getconf() *conf {      yamlfile, err := ioutil.readfile("conf.yaml")     if err != nil {         log.printf("yamlfile.get err   #%v ", err)     }     err = yaml.unmarshal(yamlfile, c)     if err != nil {         log.fatalf("unmarshal: %v", err)     }      return c } 

your yaml file must

 hits: 5  time: 5000000 

your code should this:

package main  import (     "fmt"     "gopkg.in/yaml.v2"     "io/ioutil"     "log" )  type conf struct {     hits int64 `yaml:"hits"`     time int64 `yaml:"time"` }  func (c *conf) getconf() *conf {      yamlfile, err := ioutil.readfile("conf.yaml")     if err != nil {         log.printf("yamlfile.get err   #%v ", err)     }     err = yaml.unmarshal(yamlfile, c)     if err != nil {         log.fatalf("unmarshal: %v", err)     }      return c }  func main() {     var c conf     c.getconf()      fmt.println(c) } 

the main error capital letter struct.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -