package main

import (
	MC "app.yhyue.com/moapp/jybase/common"
	"app.yhyue.com/moapp/jybase/endless"
	logrusx "app.yhyue.com/moapp/jylogx/logx"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"jyBXBuyer/rpc/type/bxbuyer"
	"log"

	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	IC "jyBXBuyer/rpc/init"
	"jyBXBuyer/rpc/internal/server"
	"jyBXBuyer/rpc/internal/svc"
)

func main() {
	//
	go func() {
		err := endless.ListenAndServe(":"+MC.InterfaceToStr(IC.C.Webrpcport), nil, func() {})
		if err != nil {
			log.Println("ListenAndServe: ", err)
		}
	}()

	ctx := svc.NewServiceContext(IC.C)
	svr := server.NewBxbuyerServer(ctx)

	s := zrpc.MustNewServer(IC.C.RpcServerConf, func(grpcServer *grpc.Server) {
		bxbuyer.RegisterBxbuyerServer(grpcServer, svr)

		if IC.C.Mode == service.DevMode || IC.C.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()
	//日志记录
	logx.SetWriter(logrusx.NewLogrusWriter())

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