fix issue in gyaml for invalid decoding result of type map[interface{}]interface{}

This commit is contained in:
John
2019-09-17 20:53:20 +08:00
parent 4847fecdaa
commit c2ad9f5fb9
5 changed files with 133 additions and 22 deletions

View File

@ -0,0 +1,44 @@
broker:
ip: "127.0.0.1"
tcpport: "4222"
httpport: "8222"
user: "alfxnats"
pwd: "alfxnats"
clusterid: "alfxnats"
database:
ip: "110.1.1.227"
port: "27017"
user: "alfxdev"
pwd: "alfxdev"
dbname: "alfxdev"
scheduler:
a2rparallel: 4
sleeptime: 300
worker:
name: "worker1"
domains:
officenet: 3
producnet: 3
free: 3
temppath: "/home/alfx/proc"
common:
filepath: "/home/alfx/file"
logpath: "home/alfx/log"
logdebug: true
logtrace: true
report:
localip: "127.0.0.1"
localport: ""

View File

@ -0,0 +1,77 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gparser"
)
type Conf struct {
Broker Broker
Database Database
Scheduler Scheduler
Worker Worker
Common Common
Report Report
}
type Broker struct {
Ip string
Tcport string
Httpport string
User string
Pwd string
Clusterid string
}
type Database struct {
Ip string
Port string
User string
Pwd string
Dbname string
}
type Scheduler struct {
SleepTime int
Pidfilepath string
A2rparallel int
}
type Worker struct {
Name string
Domains map[string]interface{}
Temppath string
Pidfilepath string
}
type Common struct {
Filepath string
Logpath string
Logdebug bool
Logtrace bool
}
type Report struct {
Localip string
Localport string //暂不启用
}
func main() {
_, err := gparser.Load("config.yaml")
if err != nil {
fmt.Println("oops,read config.yaml err:", err)
}
//fmt.Println("yaml.v3读取yaml文件")
//f, err := os.Open("config.yaml")
//if err != nil {
// panic(err)
//}
//var conf Conf
//err = yaml.NewDecoder(f).Decode(&conf)
//if err != nil {
// panic(err)
//}
//fmt.Println(conf)
}