Nexus/pkg/internal/grpc/server.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-10-19 14:36:33 +00:00
package grpc
import (
2024-10-24 15:46:09 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
2024-10-19 14:36:33 +00:00
"net"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"google.golang.org/grpc/reflection"
"github.com/spf13/viper"
"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
)
2024-10-20 11:04:41 +00:00
type Server struct {
2024-10-21 14:07:36 +00:00
proto.UnimplementedDatabaseServiceServer
proto.UnimplementedStreamServiceServer
2024-10-24 15:46:09 +00:00
proto.UnimplementedAllocatorServiceServer
2024-10-20 11:04:41 +00:00
health.UnimplementedHealthServer
2024-10-19 14:36:33 +00:00
srv *grpc.Server
}
2024-10-20 11:04:41 +00:00
func NewServer() *Server {
server := &Server{
2024-10-19 14:36:33 +00:00
srv: grpc.NewServer(),
}
2024-10-24 15:46:09 +00:00
proto.RegisterDirectoryServiceServer(server.srv, &directory.ServiceRpcServer{})
proto.RegisterCommandProviderServer(server.srv, &directory.CommandRpcServer{})
2024-10-21 14:07:36 +00:00
proto.RegisterDatabaseServiceServer(server.srv, server)
proto.RegisterStreamServiceServer(server.srv, server)
2024-10-24 15:46:09 +00:00
proto.RegisterAllocatorServiceServer(server.srv, server)
2024-10-19 14:36:33 +00:00
health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv)
return server
}
2024-10-20 11:04:41 +00:00
func (v *Server) Listen() error {
2024-10-19 14:36:33 +00:00
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
return v.srv.Serve(listener)
}