github.com/koko1123/flow-go-1@v0.29.6/admin/server.go (about) 1 package admin 2 3 import ( 4 "context" 5 6 "google.golang.org/grpc/codes" 7 "google.golang.org/grpc/status" 8 "google.golang.org/protobuf/types/known/structpb" 9 10 pb "github.com/koko1123/flow-go-1/admin/admin" 11 ) 12 13 type adminServer struct { 14 pb.UnimplementedAdminServer 15 cr *CommandRunner 16 } 17 18 func (s *adminServer) RunCommand(ctx context.Context, in *pb.RunCommandRequest) (*pb.RunCommandResponse, error) { 19 result, err := s.cr.runCommand(ctx, in.GetCommandName(), in.GetData().AsInterface()) 20 if err != nil { 21 return nil, err 22 } 23 24 value, err := structpb.NewValue(result) 25 if err != nil { 26 return nil, status.Error(codes.Internal, err.Error()) 27 } 28 29 return &pb.RunCommandResponse{ 30 Output: value, 31 }, nil 32 } 33 34 func NewAdminServer(cr *CommandRunner) *adminServer { 35 return &adminServer{cr: cr} 36 }