Passport/pkg/internal/grpc/server.go

48 lines
999 B
Go

package grpc
import (
"google.golang.org/grpc/reflection"
"net"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
)
import health "google.golang.org/grpc/health/grpc_health_v1"
type Server struct {
proto.UnimplementedAuthServer
proto.UnimplementedNotifyServer
proto.UnimplementedFriendshipsServer
proto.UnimplementedRealmsServer
health.UnimplementedHealthServer
srv *grpc.Server
}
func NewServer() *Server {
server := &Server{
srv: grpc.NewServer(),
}
proto.RegisterAuthServer(server.srv, &Server{})
proto.RegisterNotifyServer(server.srv, &Server{})
proto.RegisterFriendshipsServer(server.srv, &Server{})
proto.RegisterRealmsServer(server.srv, &Server{})
health.RegisterHealthServer(server.srv, &Server{})
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)
}