github.com/gogf/gf@v1.16.9/.example/encoding/gparser/gparser_yaml_issue336.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/gogf/gf/encoding/gparser" 7 ) 8 9 type Conf struct { 10 Broker Broker 11 Database Database 12 Scheduler Scheduler 13 Worker Worker 14 Common Common 15 Report Report 16 } 17 18 type Broker struct { 19 Ip string 20 Tcport string 21 Httpport string 22 User string 23 Pwd string 24 Clusterid string 25 } 26 27 type Database struct { 28 Ip string 29 Port string 30 User string 31 Pwd string 32 Dbname string 33 } 34 35 type Scheduler struct { 36 SleepTime int 37 Pidfilepath string 38 A2rparallel int 39 } 40 41 type Worker struct { 42 Name string 43 Domains map[string]interface{} 44 Temppath string 45 Pidfilepath string 46 } 47 48 type Common struct { 49 Filepath string 50 Logpath string 51 Logdebug bool 52 Logtrace bool 53 } 54 55 type Report struct { 56 Localip string 57 Localport string //暂不启用 58 } 59 60 func main() { 61 _, err := gparser.Load("config.yaml") 62 if err != nil { 63 fmt.Println("oops,read config.yaml err:", err) 64 } 65 66 //fmt.Println("yaml.v3读取yaml文件") 67 //f, err := os.Open("config.yaml") 68 //if err != nil { 69 // panic(err) 70 //} 71 //var conf Conf 72 //err = yaml.NewDecoder(f).Decode(&conf) 73 //if err != nil { 74 // panic(err) 75 //} 76 //fmt.Println(conf) 77 }