feat: port config; print docx link.
This commit is contained in:
@@ -41,12 +41,17 @@ type MQTTConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
|
Server ServerConfig `mapstructure:"server" yaml:"server"`
|
||||||
DB DBConfig `mapstructure:"database" yaml:"database"`
|
DB DBConfig `mapstructure:"database" yaml:"database"`
|
||||||
AI AIConfig `mapstructure:"ai" yaml:"ai"`
|
AI AIConfig `mapstructure:"ai" yaml:"ai"`
|
||||||
MQTT MQTTConfig `mapstructure:"mqtt" yaml:"mqtt"`
|
MQTT MQTTConfig `mapstructure:"mqtt" yaml:"mqtt"`
|
||||||
Swagger SwaggerConfig `mapstructure:"swagger" yaml:"swagger"`
|
Swagger SwaggerConfig `mapstructure:"swagger" yaml:"swagger"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ServerConfig struct {
|
||||||
|
Port string `mapstructure:"port" yaml:"port"`
|
||||||
|
}
|
||||||
|
|
||||||
type SwaggerConfig struct {
|
type SwaggerConfig struct {
|
||||||
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
|
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,5 +84,20 @@ func main() {
|
|||||||
|
|
||||||
// 启动服务
|
// 启动服务
|
||||||
r := routes.SetupRouter()
|
r := routes.SetupRouter()
|
||||||
r.Run(":8081")
|
|
||||||
|
port := config.App.Server.Port
|
||||||
|
if port == "" {
|
||||||
|
port = ":8081"
|
||||||
|
} else if port[0] != ':' {
|
||||||
|
port = ":" + port
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.App.Swagger.Enabled {
|
||||||
|
host := "localhost"
|
||||||
|
addr := host + port
|
||||||
|
log.Printf("Swagger UI: http://%s/swagger/index.html", addr)
|
||||||
|
log.Printf("Scalar 文档: http://%s/scalar", addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Run(port)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user