⚙️ Options
pkg/repository.Options is the configuration structure for Repository layer, controlling HTTP request server address and proxy.
Structure Definition
package repository
type Options struct {
ServerUrl string
Proxy string
}| Field | Type | Description |
|---|---|---|
ServerUrl | string | Packagist server address, default https://packagist.org |
Proxy | string | HTTP proxy address, empty means direct connection |
How It Takes Effect
Repository.getBytes checks Proxy before initiating request:
func (x *Repository) getBytes(ctx context.Context, targetUrl string) ([]byte, error) {
options := requests.NewOptions[any, []byte](targetUrl, requests.BytesResponseHandler())
if x.options.Proxy != "" {
options.AppendRequestSetting(requests.RequestSettingProxy(x.options.Proxy))
}
return requests.SendRequest[any, []byte](ctx, options)
}Proxynon-empty → enable proxy viarequests.RequestSettingProxy.ServerUrlis not directly used in currentRepositoryimplementation — method parameters themselves are already complete URLs. It's mainly for upper-level or future extension use.
Unexported Field
Repository.options is an unexported field, external packages cannot set it directly. Currently external construction of Repository can only use zero value literal &repository.Repository{}, so Options proxy capability is temporarily only available within the package.
If you need to configure proxy/server address externally, please use pkg/client.ComposerClient, which provides WithBaseURL, WithRepoURL, WithAPICredentials etc. public options.
Recommended Approach: Use Client Instead
If you need to configure proxy or custom endpoint, ComposerClient is the high-level facade for external use:
package main
import (
"fmt"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
)
func main() {
c := client.NewComposerClient(
30*time.Second,
client.WithBaseURL("https://packagist.org"),
client.WithRepoURL("https://repo.packagist.org"),
client.WithAPICredentials("your-username", "your-api-token"),
)
stats, _ := c.GetStatistics()
fmt.Printf("Total packages: %d\n", stats.Packages)
}See Client for details.
Advanced Topics
- Repository layer methods: see Repository.
- Proxy is common in network-restricted CI environments — see CI/CD Pipeline.