🔑 AddGitLabToken
Adds a GitLab OAuth token to Composer's auth.json, used to access private GitLab repositories.
When to use
Use when the project depends on private Composer repositories hosted on GitLab (including self-hosted instances). The token is written to the gitlab-oauth section of auth.json in the Composer home directory.
Signature
go
func (c *Composer) AddGitLabToken(domain string, token string) errorParameters
| Parameter | Type | Description |
|---|---|---|
domain | string | Domain the token applies to, e.g. gitlab.com or a self-hosted instance domain |
token | string | GitLab personal access token |
Return value
error: Returns the corresponding error message when reading or writing auth.json fails; nil on success.
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("init failed: %v", err)
}
// Add a token for a self-hosted GitLab instance
if err := comp.AddGitLabToken("gitlab.example.com", "glpat-xxxxxxxxxxxxxxxxxxxx"); err != nil {
log.Fatalf("failed to add token: %v", err)
}
fmt.Println("GitLab token written to auth.json")
}Advanced
- The token is stored in the
AuthConfig.GitLabmap returned byGetAuthConfig. - To remove a token, use
RemoveTokenwith typegitlab-oauth. - Related methods:
AddGitHubToken,AddBearerToken,AddHTTPBasicAuth.