Messaging/pkg/internal/grpc/server.go

35 lines
627 B
Go
Raw Normal View History

package grpc
import (
2024-08-23 11:32:24 +00:00
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
"net"
)
type Server struct {
2024-08-23 11:32:24 +00:00
proto.UnimplementedStreamControllerServer
}
var S *grpc.Server
func NewGRPC() {
S = grpc.NewServer()
health.RegisterHealthServer(S, &Server{})
2024-08-23 11:32:24 +00:00
proto.RegisterStreamControllerServer(S, &Server{})
reflection.Register(S)
}
func ListenGRPC() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
return S.Serve(listener)
}