Messaging/pkg/internal/grpc/server.go

42 lines
804 B
Go
Raw Normal View History

package grpc
import (
2024-09-11 15:58:02 +00:00
"net"
2024-11-02 05:23:27 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
)
type Server struct {
2024-11-02 05:23:27 +00:00
proto.UnimplementedStreamServiceServer
proto.UnimplementedDirectoryServiceServer
srv *grpc.Server
}
2024-11-02 05:23:27 +00:00
func NewGrpc() *Server {
server := &Server{
srv: grpc.NewServer(),
}
2024-11-02 05:23:27 +00:00
health.RegisterHealthServer(server.srv, server)
proto.RegisterStreamServiceServer(server.srv, server)
proto.RegisterDirectoryServiceServer(server.srv, server)
2024-11-02 05:23:27 +00:00
reflection.Register(server.srv)
2024-11-02 05:23:27 +00:00
return server
}
2024-11-02 05:23:27 +00:00
func (v *Server) Listen() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
2024-11-02 05:23:27 +00:00
return v.srv.Serve(listener)
}