package main

import (
	"fmt"
	"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
	"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/server"
	"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
	"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"

	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

const ServiceName = "auth_service"

func main() {
	var c config.Config
	err := config.GetConfig(&c, ServiceName)
	if err != nil {
		panic(err)
	}

	ctx := svc.NewServiceContext(c)

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		auth.RegisterAuthServiceServer(grpcServer, server.NewAuthServiceServer(ctx))

		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", c.RpcServerConf.ListenOn)
	s.Start()
}