2024-02-20 13:46:15 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2024-06-17 14:21:34 +00:00
|
|
|
"google.golang.org/grpc/reflection"
|
2024-03-20 12:56:07 +00:00
|
|
|
"net"
|
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
exproto "git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
2024-06-17 14:21:34 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
2024-02-20 13:46:15 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2024-06-17 14:21:34 +00:00
|
|
|
import health "google.golang.org/grpc/health/grpc_health_v1"
|
|
|
|
|
2024-02-20 13:46:15 +00:00
|
|
|
type Server struct {
|
2024-07-14 16:01:17 +00:00
|
|
|
exproto.UnimplementedAuthServer
|
2024-02-20 13:46:15 +00:00
|
|
|
proto.UnimplementedNotifyServer
|
2024-04-05 17:07:36 +00:00
|
|
|
proto.UnimplementedFriendshipsServer
|
2024-05-03 17:47:44 +00:00
|
|
|
proto.UnimplementedRealmsServer
|
2024-06-17 14:21:34 +00:00
|
|
|
health.UnimplementedHealthServer
|
2024-06-24 15:06:20 +00:00
|
|
|
|
|
|
|
srv *grpc.Server
|
2024-02-20 13:46:15 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 15:06:20 +00:00
|
|
|
func NewServer() *Server {
|
|
|
|
server := &Server{
|
|
|
|
srv: grpc.NewServer(),
|
|
|
|
}
|
2024-06-17 14:21:34 +00:00
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
exproto.RegisterAuthServer(server.srv, &Server{})
|
2024-06-24 15:06:20 +00:00
|
|
|
proto.RegisterNotifyServer(server.srv, &Server{})
|
|
|
|
proto.RegisterFriendshipsServer(server.srv, &Server{})
|
|
|
|
proto.RegisterRealmsServer(server.srv, &Server{})
|
|
|
|
health.RegisterHealthServer(server.srv, &Server{})
|
2024-06-17 14:21:34 +00:00
|
|
|
|
2024-06-24 15:06:20 +00:00
|
|
|
reflection.Register(server.srv)
|
2024-06-17 14:21:34 +00:00
|
|
|
|
2024-06-24 15:06:20 +00:00
|
|
|
return server
|
2024-06-17 14:21:34 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 15:06:20 +00:00
|
|
|
func (v *Server) Listen() error {
|
2024-06-19 15:25:40 +00:00
|
|
|
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
|
2024-02-20 13:46:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-24 15:06:20 +00:00
|
|
|
return v.srv.Serve(listener)
|
2024-02-20 13:46:15 +00:00
|
|
|
}
|