#### **1 配置文件创建** 导入包 ini ``` go get gopkg.in/ini.v1 ``` 新建文件夹与文件 ![](https://img.kancloud.cn/56/28/5628464c65d67c366de9a855bc252f8c_282x173.png) config.ini ~~~ [mysql] DbHost= DbPort=3306 DbUser=root DbPass= DbName= ~~~ config.go ~~~ package config import ( "fmt" "gopkg.in/ini.v1" ) var ( DbHost string DbPort string DbUser string DbPass string DbName string ) func Init() { file,err := ini.Load("./config/config.ini") if err != nil{ fmt.Println("ini load err",err) } LoadMysql(file) } func LoadMysql(file *ini.File) { DbHost = file.Section("mysql").Key("DbHost").String() DbPort = file.Section("mysql").Key("DbPort").String() DbUser = file.Section("mysql").Key("DbUser").String() DbPass = file.Section("mysql").Key("DbPass").String() DbName = file.Section("mysql").Key("DbName").String() } ~~~