From e4958248345a283d29418708c1111a24a94dedd3 Mon Sep 17 00:00:00 2001 From: Anton Schirg Date: Wed, 29 Aug 2018 19:17:45 +0200 Subject: [PATCH] move wakeup to client package and extract http client --- wakeup.go => client/jsonclient.go | 38 +++++++------------------------ client/wakeup.go | 28 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 30 deletions(-) rename wakeup.go => client/jsonclient.go (66%) create mode 100644 client/wakeup.go diff --git a/wakeup.go b/client/jsonclient.go similarity index 66% rename from wakeup.go rename to client/jsonclient.go index df389de..144f9b6 100644 --- a/wakeup.go +++ b/client/jsonclient.go @@ -1,38 +1,15 @@ -package main +package client import ( - "bytes" - "context" - "encoding/json" - "github.com/pkg/errors" - "github.com/zrepl/zrepl/config" - "github.com/zrepl/zrepl/daemon" - "io" - "net" "net/http" + "net" + "context" + "bytes" + "encoding/json" + "io" + "github.com/pkg/errors" ) -func RunWakeup(config config.Config, args []string) error { - if len(args) != 1 { - return errors.Errorf("Expected 1 argument: job") - } - - httpc, err := controlHttpClient(config.Global.Control.SockPath) - if err != nil { - return err - } - - err = jsonRequestResponse(httpc, daemon.ControlJobEndpointWakeup, - struct { - Name string - }{ - Name: args[0], - }, - struct{}{}, - ) - return err -} - func controlHttpClient(sockpath string) (client http.Client, err error) { return http.Client{ Transport: &http.Transport{ @@ -66,3 +43,4 @@ func jsonRequestResponse(c http.Client, endpoint string, req interface{}, res in return nil } + diff --git a/client/wakeup.go b/client/wakeup.go new file mode 100644 index 0000000..97fb180 --- /dev/null +++ b/client/wakeup.go @@ -0,0 +1,28 @@ +package client + +import ( + "github.com/pkg/errors" + "github.com/zrepl/zrepl/config" + "github.com/zrepl/zrepl/daemon" +) + +func RunWakeup(config config.Config, args []string) error { + if len(args) != 1 { + return errors.Errorf("Expected 1 argument: job") + } + + httpc, err := controlHttpClient(config.Global.Control.SockPath) + if err != nil { + return err + } + + err = jsonRequestResponse(httpc, daemon.ControlJobEndpointWakeup, + struct { + Name string + }{ + Name: args[0], + }, + struct{}{}, + ) + return err +}