github.com/wozhu6104/docker@v20.10.10+incompatible/client/login.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "context" 5 "encoding/json" 6 "net/url" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/api/types/registry" 10 ) 11 12 // RegistryLogin authenticates the docker server with a given docker registry. 13 // It returns unauthorizedError when the authentication fails. 14 func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) { 15 resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) 16 defer ensureReaderClosed(resp) 17 18 if err != nil { 19 return registry.AuthenticateOKBody{}, err 20 } 21 22 var response registry.AuthenticateOKBody 23 err = json.NewDecoder(resp.body).Decode(&response) 24 return response, err 25 }