重构项目

This commit is contained in:
ExplodingDragon
2025-11-15 01:09:25 +08:00
parent d67dbf88ae
commit 3492dead8d
34 changed files with 715 additions and 444 deletions

View File

@@ -17,10 +17,11 @@ type ProviderGitea struct {
BaseURL string
Token string
gitea *gitea.Client
gitea *gitea.Client
client *http.Client
}
func NewGitea(url, token string) (*ProviderGitea, error) {
func NewGitea(httpClient *http.Client, url, token string) (*ProviderGitea, error) {
client, err := gitea.NewClient(url, gitea.SetGiteaVersion(""), gitea.SetToken(token))
if err != nil {
return nil, err
@@ -29,6 +30,7 @@ func NewGitea(url, token string) (*ProviderGitea, error) {
BaseURL: url,
Token: token,
gitea: client,
client: httpClient,
}, nil
}
@@ -103,7 +105,7 @@ func (g *ProviderGitea) Branches(_ context.Context, owner, repo string) (map[str
return result, nil
}
func (g *ProviderGitea) Open(ctx context.Context, client *http.Client, owner, repo, commit, path string, headers http.Header) (*http.Response, error) {
func (g *ProviderGitea) Open(ctx context.Context, owner, repo, commit, path string, headers http.Header) (*http.Response, error) {
if headers == nil {
headers = make(http.Header)
}
@@ -122,7 +124,7 @@ func (g *ProviderGitea) Open(ctx context.Context, client *http.Client, owner, re
}
}
req.Header.Add("Authorization", "token "+g.Token)
return client.Do(req)
return g.client.Do(req)
}
func (g *ProviderGitea) Close() error {