12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package core
- import (
- "eta/eta_bridge/global"
- "eta/eta_bridge/init_serve"
- "eta/eta_bridge/rpc/sso"
- _ "eta/eta_bridge/rpc/sso"
- HTtask "eta/eta_bridge/task/htfutures"
- "flag"
- "fmt"
- "google.golang.org/grpc"
- "net"
- )
- var (
- port = flag.Int("port", 50051, "")
- )
- func RunServe() {
- // 初始化路由
- r := init_serve.InitRouter()
- // 如果配置了redis,那么链接redis
- if global.CONFIG.Serve.UseRedis {
- //初始化redis
- init_serve.Redis()
- }
- // 初始化mysql数据库
- init_serve.Mysql()
- //初始化海通的相关逻辑
- if global.CONFIG.HTFutures.OaDBDns != "" {
- init_serve.DMDataBase()
- //init_serve.DMDataBaseORM()
- }
- if global.CONFIG.HTFutures.SyncTask.EnableTask {
- HTtask.StartCronJob()
- }
- if global.CONFIG.OracleJY.Account != "" {
- //初始化oracle
- init_serve.OracleJy()
- }
- // 启动任务
- init_serve.InitTask()
- //启动oss服务
- go startGRPCServer()
- fmt.Println("port:", global.CONFIG.Serve.Port)
- err := r.Run(fmt.Sprint("0.0.0.0:", global.CONFIG.Serve.Port)) // 监听并在 0.0.0.0:8080 上启动服务
- if err != nil {
- panic(fmt.Errorf("服务启动失败,Err:%s", err))
- } else {
- fmt.Println("Run:", fmt.Sprint("0.0.0.0:", global.CONFIG.Serve.Port))
- }
- }
- func startGRPCServer() {
- flag.Parse()
- lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
- if err != nil {
- global.LOG.Fatal(err)
- }
- // 建立rpc服务,并注册SensitiveServer
- s := grpc.NewServer(
- //grpc.UnaryInterceptor(rpc.SignatureInterceptor),
- //grpc.UnaryInterceptor(rpc.EncryptInterceptor),
- )
- sso.RegisterSSOLoginServer(s, &sso.SSOService{})
- // 启动服务
- err = s.Serve(lis)
- if err != nil {
- global.LOG.Fatal("rpc 服务启动失败,Err:", err)
- }
- }
|