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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -