package main

import (
	"flag"
	"fmt"

	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/config"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/server"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

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

func main() {
	flag.Parse()
	var c Config
	conf.MustLoad(*configFile, &c)
	// logx 根据配置初始化
	logx.MustSetup(c.Logx)
	//初始化mysql
	InitMysql(c.Mysql.BaseService)
	ctx := svc.NewServiceContext(c)
	svr := server.NewResourceServer(ctx)
	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		pb.RegisterResourceServer(grpcServer, svr)
		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()
	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
