mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue in gyaml for invalid decoding result of type map[interface{}]interface{}
This commit is contained in:
44
.example/encoding/gparser/config.yaml
Normal file
44
.example/encoding/gparser/config.yaml
Normal 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: ""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
77
.example/encoding/gparser/gparser_yaml_issue336.go
Normal file
77
.example/encoding/gparser/gparser_yaml_issue336.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user