package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/rest/httpx"
	"microGame/app/usercenter/cmd/api/internal/config"
	"microGame/app/usercenter/cmd/api/internal/handler"
	"microGame/app/usercenter/cmd/api/internal/svc"
	"microGame/pkg/resx"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/usercenter.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()
	ctx := svc.NewServiceContext(c)
	//使用 httpx.SetErrorHandler 处理请求体解析和校验的错误，提供更细粒度的错误提示。
	httpx.SetErrorHandler(resx.ErrorHandler)
	handler.RegisterHandlers(server, ctx)
	fmt.Printf("Starting api server at %s:%d...\n", c.Host, c.Port)

	server.Start()
}
