Paperclip/pkg/internal/grpc/server.go

36 lines
628 B
Go
Raw Normal View History

2024-05-17 07:59:51 +00:00
package grpc
import (
2024-07-28 13:03:56 +00:00
"net"
2024-09-19 14:25:53 +00:00
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
2024-05-17 07:59:51 +00:00
"github.com/spf13/viper"
"google.golang.org/grpc"
2024-06-22 04:18:54 +00:00
health "google.golang.org/grpc/health/grpc_health_v1"
2024-05-17 07:59:51 +00:00
"google.golang.org/grpc/reflection"
)
type Server struct {
2024-09-19 14:25:53 +00:00
proto.UnimplementedServiceDirectoryServer
2024-05-17 07:59:51 +00:00
}
2024-06-22 04:18:54 +00:00
var S *grpc.Server
2024-05-17 07:59:51 +00:00
2024-06-22 04:18:54 +00:00
func NewGRPC() {
S = grpc.NewServer()
2024-05-17 07:59:51 +00:00
2024-06-22 04:18:54 +00:00
health.RegisterHealthServer(S, &Server{})
2024-09-19 14:25:53 +00:00
proto.RegisterServiceDirectoryServer(S, &Server{})
2024-05-17 07:59:51 +00:00
2024-06-22 04:18:54 +00:00
reflection.Register(S)
}
func ListenGRPC() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
2024-05-17 07:59:51 +00:00
2024-06-22 04:18:54 +00:00
return S.Serve(listener)
2024-05-17 07:59:51 +00:00
}