当前位置:首页 > Web开发 > 正文

http服务读取配置文件,交叉编译

2024-03-31 Web开发

标签:

因为是在windows上编译的代码,在linux上不可执行,所以需要交叉编译

package main import ( "flag" "gopkg.in/ini.v1" "log" "net/http" "strconv" ) func main() { port := flag.Int("p", 8080, "服务端口") flag.Parse() if *port == 0 { log.Fatal("请指定端口") } cfg, err := ini.Load("my.ini") if err != nil { log.Fatal(err) } http.HandleFunc("http://www.mamicode.com/", func(writer http.ResponseWriter, request *http.Request) { dbUser := cfg.Section("db").Key("db_user").Value() dbPass := cfg.Section("db").Key("db_pass").Value() writer.Write([]byte("<h1>" + dbUser + "</h1>")) writer.Write([]byte("<h1>" + dbPass + "</h1>")) }) http.ListenAndServe(":"+strconv.Itoa(*port), nil) }



来自为知笔记(Wiz)



http服务读取配置文件,,交叉编译

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/39949.html