mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
refactor: hub grpc system
This commit is contained in:
@@ -4,18 +4,29 @@ import (
|
||||
"context"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/rs/zerolog"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
type HubHandler struct {
|
||||
pb.UnimplementedHubServer
|
||||
log zerolog.Logger
|
||||
GrpcServer *grpc.Server
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
return &Server{}
|
||||
func NewHubHandler(logger zerolog.Logger) *HubHandler {
|
||||
hub := &HubHandler{log: logger}
|
||||
|
||||
grpcServer := grpc.NewServer()
|
||||
pb.RegisterHubServer(grpcServer, hub)
|
||||
|
||||
hub.GrpcServer = grpcServer
|
||||
|
||||
return hub
|
||||
}
|
||||
|
||||
func (s *Server) Ping(ctx context.Context, _ *emptypb.Empty) (*pb.PongResponse, error) {
|
||||
func (h *HubHandler) Ping(ctx context.Context, _ *emptypb.Empty) (*pb.PongResponse, error) {
|
||||
h.log.Info().Msg("pong request")
|
||||
return &pb.PongResponse{Pong: "Pong"}, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user