github.com/tonistiigi/docker@v0.10.1-0.20240229224939-974013b0dc6a/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/registry" 9 ) 10 11 // RegistryLogin authenticates the docker server with a given docker registry. 12 // It returns unauthorizedError when the authentication fails. 13 func (cli *Client) RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error) { 14 resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) 15 defer ensureReaderClosed(resp) 16 17 if err != nil { 18 return registry.AuthenticateOKBody{}, err 19 } 20 21 var response registry.AuthenticateOKBody 22 err = json.NewDecoder(resp.body).Decode(&response) 23 return response, err 24 }