Options
Options configures a Client.
On this page
Options configures a Client. At least one of GitHub and OpenCollective is required.
type Options struct {
GitHub string
OpenCollective string
AppName string
CacheTTL time.Duration
Mock *Mock
StorageDir string
Storage Storage
APIBaseURL string
SiteBaseURL string
HTTPClient *http.Client
RequestTimeout time.Duration
OpenBrowser func(ctx context.Context, url string) error
PromptForCode func(ctx context.Context, url string) (string, error)
SignInMethod SignInMethod
SignInTimeout time.Duration
Env map[string]string
DevChecks *bool
CheckoutPollInterval time.Duration
Clock func() time.Time
Stderr io.Writer
Interactive *bool
}Fields#
GitHub#
GitHub stringGitHub is the GitHub login that receives sponsorships.
OpenCollective#
OpenCollective stringOpenCollective is the Open Collective slug that receives contributions.
AppName#
AppName stringAppName is shown on the consent page as "says it is" (max 64 characters).
CacheTTL#
CacheTTL time.DurationCacheTTL is how long a fetched result is served from the local cache without calling the API. Zero means one hour; values below one minute are raised to one minute. Use WithCacheTTL per call to force a refresh.
Mock#
Mock *MockMock enables mock mode: see MockPreset and MockContributions. It takes precedence over the SPONSORKIT_MOCK environment variable.
StorageDir#
StorageDir stringStorageDir is the directory for the local state file. Defaults to DefaultStorageDir(). Ignored when Storage is set. If DefaultStorageDir fails (for example HOME and XDG_CONFIG_HOME are both unset) and no StorageDir is given, state is kept in process memory only: nothing is written to disk, so a sign-in does not outlive the process.
Storage#
Storage StorageStorage replaces the file storage entirely.
APIBaseURL#
APIBaseURL stringAPIBaseURL overrides the API origin used for API calls (self-hosting, tests). Defaults to DefaultAPIBaseURL. Trailing slashes are trimmed.
SiteBaseURL#
SiteBaseURL stringSiteBaseURL overrides the site base URL (origin plus optional base path) used for the /connect/ and /checkout/ pages, CheckoutURL and the loopback redirect after a checkout sign-in. When empty it defaults to APIBaseURL if that is set (single-origin self-hosting, tests), else to DefaultSiteBaseURL. Trailing slashes are trimmed.
HTTPClient#
HTTPClient *http.ClientHTTPClient is used for all API calls. Defaults to http.DefaultClient's transport; RequestTimeout applies whichever client is used.
RequestTimeout#
RequestTimeout time.DurationRequestTimeout bounds every HTTP request, including reading the response body (PROTOCOL §7.0). Zero means 30 s; NoRequestTimeout (or any negative value) disables it. A timeout counts as a network error: GetFinancialContribution serves the stale cache and SignIn returns network_error.
OpenBrowser#
OpenBrowser func(ctx context.Context, url string) errorOpenBrowser opens a URL for the user. Defaults to OpenSystemBrowser. It runs concurrently with the loopback wait, so it may block; its ctx ends when the sign-in fails, is cancelled or times out, but not when the sign-in succeeds (the browser may still be following a redirect). An error makes SignInAuto fall back to paste-back.
PromptForCode#
PromptForCode func(ctx context.Context, url string) (string, error)PromptForCode asks the user for the paste-back sign-in code. It receives the URL the user must open. Defaults to PromptStdin.
SignInMethod#
SignInMethod SignInMethodSignInMethod forces a sign-in flow. Defaults to SignInAuto.
SignInTimeout#
SignInTimeout time.DurationSignInTimeout bounds how long SignIn (and the sign-in phase of OpenCheckout) waits for the user to finish signing in, with the loopback or the paste-back flow. Exceeding it returns a timeout *Error. Defaults to 5 minutes.
Env#
Env map[string]stringEnv overrides the process environment for SPONSORKIT_DISABLE, SPONSORKIT_MOCK, SPONSORKIT_NO_NAG, SPONSORKIT_DEV_CHECKS, CI and the display detection of SignInAuto. When non-nil it replaces the process environment for these variables (it is not merged): a variable missing from the map counts as unset. When nil, the process environment is used.
DevChecks#
DevChecks *boolDevChecks forces the dev-time target existence check on or off. By default it is on only when SPONSORKIT_DEV_CHECKS is set (see Env); Go has no implicit development signal.
CheckoutPollInterval#
CheckoutPollInterval time.DurationCheckoutPollInterval is how often OpenCheckout polls. Defaults to 60 s.
Clock#
Clock func() time.TimeClock returns the current time (cache TTL, nag). Defaults to time.Now.
Stderr#
Stderr io.WriterStderr receives user-facing messages such as the paste-back URL. Defaults to os.Stderr.
Interactive#
Interactive *boolInteractive overrides the TTY detection used by Nag.