新增index首页服务
This commit is contained in:
46
apps/index/index.go
Normal file
46
apps/index/index.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"tianyuan-api/apps/index/internal/config"
|
||||
"tianyuan-api/apps/index/internal/handler"
|
||||
"tianyuan-api/apps/index/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 读取环境变量 ENV,默认为 "prod"
|
||||
env := os.Getenv("ENV")
|
||||
if env == "" {
|
||||
env = "production"
|
||||
}
|
||||
|
||||
// 根据 ENV 加载不同的配置文件
|
||||
var defaultConfigFile string
|
||||
if env == "development" {
|
||||
defaultConfigFile = "etc/index-api.dev.yaml" // 开发环境配置
|
||||
} else {
|
||||
defaultConfigFile = "etc/index-api.yaml" // 生产环境配置
|
||||
}
|
||||
|
||||
// 允许通过命令行参数覆盖配置文件路径
|
||||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user