build(deps): bump github.com/vmware/govmomi from 0.23.0 to 0.26.1

Bumps [github.com/vmware/govmomi](https://github.com/vmware/govmomi) from 0.23.0 to 0.26.1.
- [Release notes](https://github.com/vmware/govmomi/releases)
- [Changelog](https://github.com/vmware/govmomi/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vmware/govmomi/compare/v0.23.0...v0.26.1)

---
updated-dependencies:
- dependency-name: github.com/vmware/govmomi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2021-09-04 17:51:27 +00:00 committed by Ondřej Budai
parent 974c258382
commit 137819b9cd
77 changed files with 7610 additions and 486 deletions

View file

@ -25,6 +25,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"time"
@ -106,10 +107,21 @@ func (c *Client) UnmarshalJSON(b []byte) error {
return nil
}
// isAPI returns true if path starts with "/api"
// This hack allows helpers to support both endpoints:
// "/rest" - value wrapped responses and structured error responses
// "/api" - raw responses and no structured error responses
func isAPI(path string) bool {
return strings.HasPrefix(path, "/api")
}
// Resource helper for the given path.
func (c *Client) Resource(path string) *Resource {
r := &Resource{u: c.URL()}
r.u.Path = Path + path
if !isAPI(path) {
path = Path + path
}
r.u.Path = path
return r
}
@ -153,6 +165,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{})
return c.Client.Do(ctx, req, func(res *http.Response) error {
switch res.StatusCode {
case http.StatusOK:
case http.StatusCreated:
case http.StatusNoContent:
case http.StatusBadRequest:
// TODO: structured error types
@ -174,12 +187,18 @@ func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{})
_, err := io.Copy(b, res.Body)
return err
default:
d := json.NewDecoder(res.Body)
if isAPI(req.URL.Path) {
// Responses from the /api endpoint are not wrapped
return d.Decode(resBody)
}
// Responses from the /rest endpoint are wrapped in this structure
val := struct {
Value interface{} `json:"value,omitempty"`
}{
resBody,
}
return json.NewDecoder(res.Body).Decode(&val)
return d.Decode(&val)
}
})
}