-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from RomainBelorgey/pkg_doc
Add help on using hub-tool as a library
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Using tool as lib | ||
|
||
You can use this tool as a library to make actions to Docker Hub. | ||
|
||
## Examples | ||
|
||
### Login | ||
|
||
``` | ||
username := toto | ||
password := pass | ||
hubClient, err := hub.NewClient( | ||
hub.WithHubAccount(username), | ||
hub.WithPassword(password)) | ||
if err != nil { | ||
log.Fatalf("Can't initiate hubClient | %s", err.Error()) | ||
} | ||
//Login to retrieve new token to Hub | ||
token, _, err := hubClient.Login(username, password, func() (string, error) { | ||
return "2FA required, please provide the 6 digit code: ", nil | ||
}) | ||
if err != nil { | ||
log.Fatalf("Can't get token from Docker Hub | %s", err.Error()) | ||
} | ||
``` | ||
|
||
After a successfull login, it is quite easy to do any action possible and listed inside `pkg/` directory. | ||
|
||
### Removing a tag | ||
|
||
``` | ||
err = hubClient.RemoveTag("toto/myrepo", "v1.0.0") | ||
if err != nil { | ||
log.Fatalf("Can't remove tag | %s", err.Error()) | ||
} | ||
``` |