Paperclip/pkg/internal/grpc/server.go

35 lines
620 B
Go
Raw Normal View History

2024-05-17 07:59:51 +00:00
package grpc
import (
2024-06-16 15:24:54 +00:00
"git.solsynth.dev/hydrogen/paperclip/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"
2024-06-22 04:18:54 +00:00
"net"
2024-05-17 07:59:51 +00:00
)
type Server struct {
proto.UnimplementedAttachmentsServer
}
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
proto.RegisterAttachmentsServer(S, &Server{})
health.RegisterHealthServer(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
}