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