github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/client/service_update.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "net/url" 6 "strconv" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/api/types/swarm" 10 "golang.org/x/net/context" 11 ) 12 13 // ServiceUpdate updates a Service. 14 func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) { 15 var ( 16 headers map[string][]string 17 query = url.Values{} 18 ) 19 20 if options.EncodedRegistryAuth != "" { 21 headers = map[string][]string{ 22 "X-Registry-Auth": {options.EncodedRegistryAuth}, 23 } 24 } 25 26 if options.RegistryAuthFrom != "" { 27 query.Set("registryAuthFrom", options.RegistryAuthFrom) 28 } 29 30 query.Set("version", strconv.FormatUint(version.Index, 10)) 31 32 var response types.ServiceUpdateResponse 33 resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers) 34 if err != nil { 35 return response, err 36 } 37 38 err = json.NewDecoder(resp.body).Decode(&response) 39 ensureReaderClosed(resp) 40 return response, err 41 }