create config
This commit is contained in:
		@@ -25,7 +25,6 @@ func init() {
 | 
				
			|||||||
// 实现一个 web api 服务(获取指定尺寸的图片)
 | 
					// 实现一个 web api 服务(获取指定尺寸的图片)
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	runtime.GOMAXPROCS(runtime.NumCPU())
 | 
						runtime.GOMAXPROCS(runtime.NumCPU())
 | 
				
			||||||
 | 
					 | 
				
			||||||
	models.GetMysql() // 连接数据库
 | 
						models.GetMysql() // 连接数据库
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
 | 
						http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,21 @@ func init() {
 | 
				
			|||||||
	viper.AddConfigPath("./data") // 设置配置文件所在的路径
 | 
						viper.AddConfigPath("./data") // 设置配置文件所在的路径
 | 
				
			||||||
	if err := viper.ReadInConfig(); err != nil {
 | 
						if err := viper.ReadInConfig(); err != nil {
 | 
				
			||||||
		log.Println("读取配置文件失败", err)
 | 
							log.Println("读取配置文件失败", err)
 | 
				
			||||||
		panic(err)
 | 
							生成配置文件()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	Viper = viper.GetViper()
 | 
						Viper = viper.GetViper()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func 生成配置文件() {
 | 
				
			||||||
 | 
						viper.Set("mysql.host", "")
 | 
				
			||||||
 | 
						viper.Set("mysql.port", 3306)
 | 
				
			||||||
 | 
						viper.Set("mysql.user", "")
 | 
				
			||||||
 | 
						viper.Set("mysql.password", "")
 | 
				
			||||||
 | 
						viper.Set("mysql.dbname", "")
 | 
				
			||||||
 | 
						viper.Set("mysql.charset", "utf8mb4")
 | 
				
			||||||
 | 
						viper.Set("mysql.maxOpenConns", 100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						viper.Set("oss.host", "")
 | 
				
			||||||
 | 
						viper.Set("oss.accessKeyId", "")
 | 
				
			||||||
 | 
						viper.Set("oss.accessKeySecret", "")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user