diff --git a/client.go b/client.go index f941bc3..2e0802a 100644 --- a/client.go +++ b/client.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httputil" @@ -37,7 +36,7 @@ func ExponentialBackoff(b float64, d time.Duration) BackoffFunc { */ type Client struct { - sync.Mutex + mu sync.Mutex endpoints []string username string password string @@ -231,8 +230,8 @@ func (c *Client) Auth() (err error) { if !time.Now().After(c.session.Time) { return } - c.Lock() - defer c.Unlock() + c.mu.Lock() + defer c.mu.Unlock() if !time.Now().After(c.session.Time) { return } @@ -289,13 +288,13 @@ func (c *Client) Do(r *http.Request, v interface{}) (resp *http.Response, err er if err != nil { return } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { resp.Body.Close() return } resp.Body.Close() - resp.Body = ioutil.NopCloser(bytes.NewReader(body)) + resp.Body = io.NopCloser(bytes.NewReader(body)) if c.debugWriter != nil { dumpResp, err := httputil.DumpResponse(resp, true) diff --git a/server.go b/server.go index 28f4e1d..87fcd61 100644 --- a/server.go +++ b/server.go @@ -313,7 +313,7 @@ func (o *ServerTemplateOpts) Validate(ctx context.Context, c *Client) error { return nil } -func (o ServerTemplateOpts) body() httpbody { +func (o *ServerTemplateOpts) body() httpbody { body := httpbody{"name": o.Name} if o.TargetStorage != "" { body["storage"] = o.TargetStorage @@ -325,7 +325,7 @@ func (o ServerTemplateOpts) body() httpbody { return body } -func (c *ServerClient) CreateFromTemplate(ctx context.Context, opts ServerTemplateOpts) (t *Task, url string, err error) { +func (c *ServerClient) CreateFromTemplate(ctx context.Context, opts *ServerTemplateOpts) (t *Task, url string, err error) { err = opts.Validate(ctx, c.client) if err != nil { return diff --git a/task.go b/task.go index 3f1d00d..5cd007a 100644 --- a/task.go +++ b/task.go @@ -97,7 +97,7 @@ func (c *TaskClient) Wait(ctx context.Context, t *Task, f OnTaskChange) error { } } time.Sleep(TaskStatusCheckInterval * time.Second) - waited = waited + TaskStatusCheckInterval + waited += TaskStatusCheckInterval } return errors.New("task wait timeout for: " + t.ID) } diff --git a/userdata.go b/userdata.go index 1bf2dbb..7e96a59 100644 --- a/userdata.go +++ b/userdata.go @@ -3,8 +3,6 @@ package pve import ( - //"encoding/base64" - //"net/url" "gopkg.in/yaml.v2" )