mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
- Add `util.ResolveGitHubToken` to resolve GitHub API tokens with priority order (`GITHUB_TOKEN`, `github_token`, and `GITSTORE_GIT_TOKEN` for GitHub repositories). - Set GitHub `Authorization` headers in management version check and asset updater requests when a token is resolved. Closes: #5189
26 lines
623 B
Go
26 lines
623 B
Go
package util
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// ResolveGitHubToken returns the configured GitHub API token in priority order:
|
|
// 1. GITHUB_TOKEN
|
|
// 2. github_token
|
|
// 3. GITSTORE_GIT_TOKEN (only if GITSTORE_GIT_URL points to github.com)
|
|
func ResolveGitHubToken() string {
|
|
for _, name := range []string{"GITHUB_TOKEN", "github_token"} {
|
|
if token := strings.TrimSpace(os.Getenv(name)); token != "" {
|
|
return token
|
|
}
|
|
}
|
|
|
|
gitURL := strings.ToLower(strings.TrimSpace(os.Getenv("GITSTORE_GIT_URL")))
|
|
if !strings.Contains(gitURL, "github.com") {
|
|
return ""
|
|
}
|
|
|
|
return strings.TrimSpace(os.Getenv("GITSTORE_GIT_TOKEN"))
|
|
}
|