1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

api/types/swarm: Version: implement stringer interface

makes the code a bit more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-05-10 22:35:09 +02:00
parent d35731fa15
commit d9524d92a9
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
7 changed files with 18 additions and 16 deletions

View file

@ -1,12 +1,20 @@
package swarm // import "github.com/docker/docker/api/types/swarm" package swarm // import "github.com/docker/docker/api/types/swarm"
import "time" import (
"strconv"
"time"
)
// Version represents the internal object version. // Version represents the internal object version.
type Version struct { type Version struct {
Index uint64 `json:",omitempty"` Index uint64 `json:",omitempty"`
} }
// String implements fmt.Stringer interface.
func (v Version) String() string {
return strconv.FormatUint(v.Index, 10)
}
// Meta is a base object inherited by most of the other once. // Meta is a base object inherited by most of the other once.
type Meta struct { type Meta struct {
Version Version `json:",omitempty"` Version Version `json:",omitempty"`

View file

@ -3,7 +3,6 @@ package client // import "github.com/docker/docker/client"
import ( import (
"context" "context"
"net/url" "net/url"
"strconv"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
) )
@ -14,7 +13,7 @@ func (cli *Client) ConfigUpdate(ctx context.Context, id string, version swarm.Ve
return err return err
} }
query := url.Values{} query := url.Values{}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
resp, err := cli.post(ctx, "/configs/"+id+"/update", query, config, nil) resp, err := cli.post(ctx, "/configs/"+id+"/update", query, config, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -3,7 +3,6 @@ package client // import "github.com/docker/docker/client"
import ( import (
"context" "context"
"net/url" "net/url"
"strconv"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
) )
@ -11,7 +10,7 @@ import (
// NodeUpdate updates a Node. // NodeUpdate updates a Node.
func (cli *Client) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error { func (cli *Client) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error {
query := url.Values{} query := url.Values{}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
resp, err := cli.post(ctx, "/nodes/"+nodeID+"/update", query, node, nil) resp, err := cli.post(ctx, "/nodes/"+nodeID+"/update", query, node, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -3,7 +3,6 @@ package client // import "github.com/docker/docker/client"
import ( import (
"context" "context"
"net/url" "net/url"
"strconv"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
) )
@ -14,7 +13,7 @@ func (cli *Client) SecretUpdate(ctx context.Context, id string, version swarm.Ve
return err return err
} }
query := url.Values{} query := url.Values{}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
resp, err := cli.post(ctx, "/secrets/"+id+"/update", query, secret, nil) resp, err := cli.post(ctx, "/secrets/"+id+"/update", query, secret, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/url" "net/url"
"strconv"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
@ -35,7 +34,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
query.Set("rollback", options.Rollback) query.Set("rollback", options.Rollback)
} }
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
if err := validateServiceSpec(service); err != nil { if err := validateServiceSpec(service); err != nil {
return response, err return response, err

View file

@ -2,7 +2,6 @@ package client // import "github.com/docker/docker/client"
import ( import (
"context" "context"
"fmt"
"net/url" "net/url"
"strconv" "strconv"
@ -12,10 +11,10 @@ import (
// SwarmUpdate updates the swarm. // SwarmUpdate updates the swarm.
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error { func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
query := url.Values{} query := url.Values{}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
query.Set("rotateWorkerToken", fmt.Sprintf("%v", flags.RotateWorkerToken)) query.Set("rotateWorkerToken", strconv.FormatBool(flags.RotateWorkerToken))
query.Set("rotateManagerToken", fmt.Sprintf("%v", flags.RotateManagerToken)) query.Set("rotateManagerToken", strconv.FormatBool(flags.RotateManagerToken))
query.Set("rotateManagerUnlockKey", fmt.Sprintf("%v", flags.RotateManagerUnlockKey)) query.Set("rotateManagerUnlockKey", strconv.FormatBool(flags.RotateManagerUnlockKey))
resp, err := cli.post(ctx, "/swarm/update", query, swarm, nil) resp, err := cli.post(ctx, "/swarm/update", query, swarm, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -3,7 +3,6 @@ package client // import "github.com/docker/docker/client"
import ( import (
"context" "context"
"net/url" "net/url"
"strconv"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
@ -17,7 +16,7 @@ func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version sw
} }
query := url.Values{} query := url.Values{}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", version.String())
resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil) resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)