From 034077f1f1c49318359d8c094ebf28875ab51925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Sterba?= <andre.sterba@stud.h-da.de> Date: Thu, 29 Apr 2021 15:35:02 +0200 Subject: [PATCH] Fix cli parsing of pnd and sbi --- cli/http.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/http.go b/cli/http.go index a90be457b..b7c3254b6 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, -- GitLab