go的配置文件

go湖南老乡 2018/2/5 17:55:54
package main

import (
	"github.com/kylelemons/go-gypsy/yaml 

"
	"fmt"
)

type (

	// reply to findnode
	neighbors struct {

		Expiration uint64
		confbh  int
		// Ignore additional fields (for forward compatibility).

	}
)

func main(){
	config,err:=yaml.ReadFile("./conf.yaml")
	fmt.Println(config)
	if err!=nil{
		fmt.Println(err)
	}
	str:=neighbors{}
	str64,err:=config.GetInt("path")

	if err!=nil {
		fmt.Println(err)
	}
	str.confbh=int(str64)
	fmt.Println(str.confbh)
}


本地文件格式为 path: 1000

你可能感兴趣的:(go)