package v1 import ( "context" "net" "google.golang.org/grpc" "minerva.bing89.com/gateway/pkg/minerva" ) type Server struct { Minervas minerva.Minervas engine minerva.PersistentEngine } func NewServer(engine minerva.PersistentEngine)(Server, error){ m, err := minerva.NewMinervas(engine) return Server{ Minervas: m, engine: engine, }, err } func (s *Server)Register(ctx context.Context, m *minerva.Minerva)(*minerva.Response, error){ err := s.Minervas.Insert(m) if err != nil { return &minerva.Response{Success: false, Error: err.Error(),}, err } return &minerva.Response{Success: true,}, nil } func (s *Server)UnRegister(ctx context.Context, m *minerva.Minerva)(*minerva.Response, error){ err := s.Minervas.Delete(m.Name) if err != nil { return &minerva.Response{Success: false, Error: err.Error(),}, err } return &minerva.Response{Success: true,}, nil } func (s *Server)UpRegister(ctx context.Context, m *minerva.Minerva)(*minerva.Response, error){ err := s.Minervas.UpSert(m) if err != nil { return &minerva.Response{Success: false, Error: err.Error(),}, err } return &minerva.Response{Success: true,}, nil } func (s *Server)StartRPCService(lis net.Listener, opt ...grpc.ServerOption)error{ svr := grpc.NewServer(opt...) minerva.RegisterAPIServerServer(svr, s) // lis, err := net.Listen("tcp", address) // if err != nil { // return err // } err := svr.Serve(lis) return err }