Passport/pkg/internal/grpc/server.go

44 lines
882 B
Go
Raw Normal View History

2024-02-20 13:46:15 +00:00
package grpc
import (
"google.golang.org/grpc/reflection"
2024-03-20 12:56:07 +00:00
"net"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
2024-02-20 13:46:15 +00:00
"github.com/spf13/viper"
"google.golang.org/grpc"
)
import health "google.golang.org/grpc/health/grpc_health_v1"
2024-02-20 13:46:15 +00:00
type Server struct {
proto.UnimplementedAuthServer
proto.UnimplementedNotifyServer
2024-04-05 17:07:36 +00:00
proto.UnimplementedFriendshipsServer
2024-05-03 17:47:44 +00:00
proto.UnimplementedRealmsServer
health.UnimplementedHealthServer
2024-02-20 13:46:15 +00:00
}
var S *grpc.Server
func NewGRPC() {
S = grpc.NewServer()
proto.RegisterAuthServer(S, &Server{})
proto.RegisterNotifyServer(S, &Server{})
proto.RegisterFriendshipsServer(S, &Server{})
proto.RegisterRealmsServer(S, &Server{})
health.RegisterHealthServer(S, &Server{})
reflection.Register(S)
}
func ListenGRPC() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
2024-02-20 13:46:15 +00:00
if err != nil {
return err
}
return S.Serve(listener)
2024-02-20 13:46:15 +00:00
}