// Copyright (C) 2020 Marius Schellenberger package pve import ( "encoding/json" "errors" //"fmt" "io" "net/http" "net/url" "strings" ) type data struct { Data json.RawMessage `json:"data"` Errors json.RawMessage `json:"errors"` } func unwrapData(resp *http.Response, v interface{}) error { if resp.Body == nil { return nil } var d data err := json.NewDecoder(resp.Body).Decode(&d) if err != nil { return err } if d.Errors != nil { return errors.New(string(d.Errors)) } if v == nil { return nil } return json.Unmarshal(d.Data, &v) } type httpbody map[string]string func (b httpbody) Reader() io.Reader { data := url.Values{} for k, v := range b { data.Set(k, v) } enc := data.Encode() //fmt.Println("--- encoded:", enc) return strings.NewReader(enc) }