go17/book/config/config.go

50 lines
917 B
Go
Raw Normal View History

2024-11-16 16:00:55 +08:00
package config
2024-11-16 17:22:21 +08:00
import "encoding/json"
2024-11-16 16:00:55 +08:00
// 定义程序配置
// dsn := "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
// 凡是可以提出出配置的
// 程序的配置对象
type Config struct {
2024-11-16 17:22:21 +08:00
App *App `json:"app"`
MySQL *MySQL `json:"mysql"`
}
// &{0x102317ec0 0x10231c8a0}
//
// String() string, fmt.Strigger接口
//
// fmt.
func (c *Config) String() string {
v, _ := json.Marshal(c)
return string(v)
2024-11-16 16:00:55 +08:00
}
// app:
//
// host: 127.0.0.1
// port: 8080
type App struct {
Host string `json:"host"`
Port int `json:"port"`
}
// mysql:
//
// host: 127.0.0.1
// port: 3306
// database: test
// username: "root"
// password: "123456"
// debug: true
type MySQL struct {
Host string `json:"host"`
Port int `json:"port"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
Debug bool `json:"debug"`
}