2024-07-14 12:25:30 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2024-07-15 12:04:03 +00:00
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
|
|
|
2024-07-14 12:25:30 +00:00
|
|
|
"google.golang.org/grpc/reflection"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
health "google.golang.org/grpc/health/grpc_health_v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
proto.UnimplementedServiceDirectoryServer
|
2024-07-14 15:45:18 +00:00
|
|
|
proto.UnimplementedStreamControllerServer
|
2024-07-21 05:51:46 +00:00
|
|
|
proto.UnimplementedPostmanServer
|
2024-07-14 12:25:30 +00:00
|
|
|
proto.UnimplementedAuthServer
|
|
|
|
|
|
|
|
srv *grpc.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer() *Server {
|
|
|
|
server := &Server{
|
|
|
|
srv: grpc.NewServer(),
|
|
|
|
}
|
|
|
|
|
2024-07-14 15:45:18 +00:00
|
|
|
proto.RegisterServiceDirectoryServer(server.srv, server)
|
|
|
|
proto.RegisterStreamControllerServer(server.srv, server)
|
|
|
|
proto.RegisterAuthServer(server.srv, server)
|
2024-07-21 05:51:46 +00:00
|
|
|
proto.RegisterPostmanServer(server.srv, server)
|
2024-07-14 15:45:18 +00:00
|
|
|
health.RegisterHealthServer(server.srv, server)
|
2024-07-14 12:25:30 +00:00
|
|
|
|
|
|
|
reflection.Register(server.srv)
|
|
|
|
|
|
|
|
return server
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) Listen() error {
|
|
|
|
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return v.srv.Serve(listener)
|
|
|
|
}
|