Upgraded resty to v3
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
This commit is contained in:
25
client.go
25
client.go
@ -3,6 +3,7 @@ package mysubaru
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"sync"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
|
||||
"git.savin.nyc/alex/mysubaru/config"
|
||||
"github.com/Jeffail/gabs/v2"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
// credentials .
|
||||
@ -252,7 +253,7 @@ func (c *Client) listDevices() {
|
||||
fmt.Println(" Status Code:", resp.StatusCode())
|
||||
fmt.Println(" Status :", resp.Status())
|
||||
fmt.Println(" Proto :", resp.Proto())
|
||||
fmt.Println(" Time :", resp.Time())
|
||||
fmt.Println(" Time :", resp.Duration())
|
||||
fmt.Println(" Received At:", resp.ReceivedAt())
|
||||
// fmt.Println(" Body :\n", resp)
|
||||
fmt.Println()
|
||||
@ -271,7 +272,7 @@ func (c *Client) listDevices() {
|
||||
fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle)
|
||||
fmt.Println(" ConnIdleTime :", ti.ConnIdleTime)
|
||||
fmt.Println(" RequestAttempt:", ti.RequestAttempt)
|
||||
fmt.Println(" RemoteAddr :", ti.RemoteAddr.String())
|
||||
fmt.Println(" RemoteAddr :", ti.RemoteAddr)
|
||||
|
||||
// c.log.Debug("LIST DEVICES OUTPUT", "body", string([]byte(resp.Body())))
|
||||
|
||||
@ -785,20 +786,24 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
Post(requestUrl)
|
||||
}
|
||||
}
|
||||
|
||||
respParsed, err := gabs.ParseJSON([]byte(resp.Body()))
|
||||
resBytes, _ := io.ReadAll(resp.Body)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
respParsed, err := gabs.ParseJSON(resBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.log.Debug("HTTP OUTPUT", "body", string(resp.Body()))
|
||||
c.log.Debug("HTTP OUTPUT", "body", string(resBytes))
|
||||
|
||||
_, ok := respParsed.Path("success").Data().(bool)
|
||||
// value == string, ok == false
|
||||
if !ok {
|
||||
// TODO: Work with errorCode
|
||||
// panic(success)
|
||||
fmt.Printf("ERROR: %+v", string([]byte(resp.Body())))
|
||||
fmt.Printf("ERROR: %+v", string(resBytes))
|
||||
}
|
||||
|
||||
if pollingUrl != "" {
|
||||
@ -817,10 +822,10 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
}).
|
||||
Get(pollingUrl)
|
||||
|
||||
c.log.Debug("POLLING HTTP OUTPUT", "body", string([]byte(resp.Body())))
|
||||
c.log.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
||||
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
||||
|
||||
respParsed, err := gabs.ParseJSON(resp.Body())
|
||||
respParsed, err := gabs.ParseJSON(resBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -849,7 +854,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
|
||||
// fmt.Printf("[DEBUG] HTTP OUTPUT >> %v\n", string([]byte(resp.Body())))
|
||||
|
||||
return resp.Body()
|
||||
return resBytes
|
||||
}
|
||||
|
||||
// isResponseSuccessfull .
|
||||
|
Reference in New Issue
Block a user