diff --git a/cli/http.go b/cli/http.go index a90be457ba4e72d9c1a9005fb81c6b9860410039..b7c3254b655bda3c315dd79039deb5f730fc023f 100644 --- a/cli/http.go +++ b/cli/http.go @@ -3,11 +3,12 @@ package cli import ( "errors" "fmt" - log "github.com/sirupsen/logrus" - "github.com/spf13/viper" "io/ioutil" "net/http" "strings" + + log "github.com/sirupsen/logrus" + "github.com/spf13/viper" ) const apiRoot = "?" @@ -26,6 +27,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { } resp, err := http.Get(apiEndpoint + apiRoot + "q=" + f + builder.String()) if err != nil { + log.Info(fmt.Sprintf("Err: %s", err)) return err } builder.Reset() @@ -38,8 +40,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { } switch f { case "init": - pnd := string(bytes[:36]) - sbi := string(bytes[36:]) + pnd := string(bytes[9:45]) + sbi := string(bytes[55:91]) viper.Set("CLI_PND", pnd) viper.Set("CLI_SBI", sbi) err := viper.WriteConfig() @@ -49,6 +51,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { default: fmt.Println(string(bytes)) } + case http.StatusCreated: defer resp.Body.Close() bytes, err := ioutil.ReadAll(resp.Body) @@ -58,8 +61,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { uuid := string(bytes[19:55]) viper.Set("LAST_DEVICE_UUID", uuid) fmt.Println(string(bytes)) - case http.StatusAccepted: + case http.StatusAccepted: default: log.WithFields(log.Fields{ "status code": resp.StatusCode,