Passport/pkg/internal/grpc/server.go

53 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-02-20 13:46:15 +00:00
package grpc
import (
2024-03-20 12:56:07 +00:00
"net"
"google.golang.org/grpc/reflection"
nroto "git.solsynth.dev/hypernet/nexus/pkg/proto"
"git.solsynth.dev/hypernet/passport/pkg/proto"
2024-02-20 13:46:15 +00:00
"github.com/spf13/viper"
"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
)
2024-10-27 04:50:07 +00:00
type App struct {
nroto.UnimplementedAuthServiceServer
nroto.UnimplementedDirectoryServiceServer
nroto.UnimplementedUserServiceServer
proto.UnimplementedRealmServiceServer
proto.UnimplementedAuditServiceServer
proto.UnimplementedNotifyServiceServer
health.UnimplementedHealthServer
srv *grpc.Server
2024-02-20 13:46:15 +00:00
}
2024-10-27 04:50:07 +00:00
func NewServer() *App {
server := &App{
srv: grpc.NewServer(),
}
nroto.RegisterAuthServiceServer(server.srv, server)
nroto.RegisterUserServiceServer(server.srv, server)
proto.RegisterNotifyServiceServer(server.srv, server)
proto.RegisterRealmServiceServer(server.srv, server)
proto.RegisterAuditServiceServer(server.srv, server)
health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv)
return server
}
2024-10-27 04:50:07 +00:00
func (v *App) Listen() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
2024-02-20 13:46:15 +00:00
if err != nil {
return err
}
return v.srv.Serve(listener)
2024-02-20 13:46:15 +00:00
}