Nexus/pkg/internal/grpc/allocator.go

34 lines
994 B
Go
Raw Normal View History

2024-10-24 15:46:09 +00:00
package grpc
import (
"context"
"git.solsynth.dev/hypernet/nexus/pkg/internal/kv"
"git.solsynth.dev/hypernet/nexus/pkg/internal/mq"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (v *Server) AllocMessageQueue(ctx context.Context, request *proto.AllocMqRequest) (*proto.AllocMqResponse, error) {
if mq.Kmq == nil {
return &proto.AllocMqResponse{IsSuccess: false}, status.Error(codes.Unavailable, "message queue wasn't configured")
}
return &proto.AllocMqResponse{
IsSuccess: true,
Addr: viper.GetString("mq.addr"),
}, nil
}
func (v *Server) AllocKv(ctx context.Context, request *proto.AllocKvRequest) (*proto.AllocKvResponse, error) {
if kv.Kv == nil {
return &proto.AllocKvResponse{IsSuccess: false}, status.Error(codes.Unavailable, "kv wasn't configured")
}
return &proto.AllocKvResponse{
IsSuccess: true,
Endpoints: viper.GetStringSlice("kv.endpoints"),
}, nil
}