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"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	IC "jyBXCore/rpc/init"
	"jyBXCore/rpc/internal/server"
	"jyBXCore/rpc/internal/svc"
	"jyBXCore/rpc/type/bxcore"
	"jyBXCore/rpc/util"
	"log"
)

func main() {
	//
	go func() {
		//正文、附件搜索限制
		util.LimitSearchInit()
		err := endless.ListenAndServe(":"+MC.InterfaceToStr(IC.C.WebRpcPort), nil, func() {})
		if err != nil {
			log.Println("ListenAndServe: ", err)
		}
	}()
	//敏感词初始化
	//fsw.ReadFswDict("./etc/mosaic_fsw.dict")
	ctx := svc.NewServiceContext(IC.C)
	svr := server.NewBxCoreServer(ctx)

	s := zrpc.MustNewServer(IC.C.RpcServerConf, func(grpcServer *grpc.Server) {
		bxcore.RegisterBxCoreServer(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()
}
