diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2019-02-25 16:19:08 +0200 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2019-03-01 15:07:23 +0200 |
commit | 210a5c141c9d76bc9718860d67d77d73997b1534 (patch) | |
tree | e8bfe028d6ecb5ddc269b67283b7b52240323dde /go/cmd/gitaly-upload-archive/main.go | |
parent | 070691c29891c27f0e46f86f6c89566199ccc54b (diff) | |
download | gitlab-shell-an-distributed-tracing.tar.gz |
Adds distributed tracing instrumentation to GitLab-Shellan-distributed-tracing
Adds distributed tracing instrumentation to GitLab-Shell using LabKit
Diffstat (limited to 'go/cmd/gitaly-upload-archive/main.go')
-rw-r--r-- | go/cmd/gitaly-upload-archive/main.go | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/go/cmd/gitaly-upload-archive/main.go b/go/cmd/gitaly-upload-archive/main.go index 10b10d3..fb07613 100644 --- a/go/cmd/gitaly-upload-archive/main.go +++ b/go/cmd/gitaly-upload-archive/main.go @@ -1,12 +1,12 @@ package main import ( + "context" "encoding/json" - "fmt" - "os" "gitlab.com/gitlab-org/gitlab-shell/go/internal/handler" "gitlab.com/gitlab-org/gitlab-shell/go/internal/logger" + "google.golang.org/grpc" pb "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" ) @@ -15,31 +15,21 @@ func init() { logger.ProgName = "gitaly-upload-archive" } -type uploadArchiveHandler func(gitalyAddress string, request *pb.SSHUploadArchiveRequest) (int32, error) - func main() { - if err := handler.Prepare(); err != nil { - logger.Fatal("preparation failed", err) - } - - code, err := uploadArchive(handler.UploadArchive, os.Args) - - if err != nil { - logger.Fatal("upload-archive failed", err) - } - - os.Exit(int(code)) + handler.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn, requestJSON string) (int32, error) { + request, err := deserialize(requestJSON) + if err != nil { + return 1, err + } + + return handler.UploadArchive(ctx, conn, request) + }) } -func uploadArchive(handler uploadArchiveHandler, args []string) (int32, error) { - if n := len(args); n != 3 { - return 0, fmt.Errorf("wrong number of arguments: expected 2 arguments, got %v", args) - } - +func deserialize(argumentJSON string) (*pb.SSHUploadArchiveRequest, error) { var request pb.SSHUploadArchiveRequest - if err := json.Unmarshal([]byte(args[2]), &request); err != nil { - return 0, fmt.Errorf("unmarshaling request json failed: %v", err) + if err := json.Unmarshal([]byte(argumentJSON), request); err != nil { + return nil, err } - - return handler(args[1], &request) + return &request, nil } |