Skip to content

⚙️ Options

pkg/repository.Options is the configuration structure for Repository layer, controlling HTTP request server address and proxy.

Structure Definition

go
package repository

type Options struct {
    ServerUrl string
    Proxy     string
}
FieldTypeDescription
ServerUrlstringPackagist server address, default https://packagist.org
ProxystringHTTP proxy address, empty means direct connection

How It Takes Effect

Repository.getBytes checks Proxy before initiating request:

go
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)
}
  • Proxy non-empty → enable proxy via requests.RequestSettingProxy.
  • ServerUrl is not directly used in current Repository implementation — 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.

If you need to configure proxy or custom endpoint, ComposerClient is the high-level facade for external use:

go
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

Released under the MIT License