config

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithToken added in v0.0.18

func ContextWithToken(ctx context.Context, token string) context.Context

ContextWithToken returns a context whose requests use the given token, when AuthMethodContextToken is configured

Types

type AuthMethod

type AuthMethod string

AuthMethod represents the authentication method to use

const (
	// AuthMethodToken represents direct token authentication
	AuthMethodToken AuthMethod = "token"
	// AuthMethodClientCredentials represents client credentials grant type
	AuthMethodClientCredentials AuthMethod = "client_credentials"
	// AuthMethodContextToken represents a token set on the context of each request
	AuthMethodContextToken AuthMethod = "context_token"
)

type ClientConfig

type ClientConfig struct {
	// BaseURL is the base URL for the API
	BaseURL string
	// HTTPClient is the HTTP client to use for requests
	HTTPClient *http.Client
	// APIKey is the API key to use for authentication (deprecated, use Token instead)
	APIKey string
	// Timeout is the timeout for requests
	Timeout time.Duration

	// Auth related fields
	// AuthMethod is the authentication method to use
	AuthMethod AuthMethod
	// Token is the direct authentication token to use if AuthMethod is AuthMethodToken
	Token string
	// OAuth2ClientID is the client ID to use for client credentials grant type
	OAuth2ClientID string
	// OAuth2ClientSecret is the client secret to use for client credentials grant type
	OAuth2ClientSecret string
	// contains filtered or unexported fields
}

ClientConfig contains the configuration for the API clients

func DefaultClientConfig

func DefaultClientConfig() *ClientConfig

DefaultClientConfig returns a default configuration for the API clients

func (*ClientConfig) GetToken

func (c *ClientConfig) GetToken(ctx context.Context) (string, error)

GetToken returns the current valid token, fetching a new one if necessary

func (*ClientConfig) WithAPIKey

func (c *ClientConfig) WithAPIKey(apiKey string) *ClientConfig

WithAPIKey sets the API key to use for authentication (deprecated, use WithToken instead)

func (*ClientConfig) WithBaseURL

func (c *ClientConfig) WithBaseURL(baseURL string) *ClientConfig

WithBaseURL sets the base URL for the API

func (*ClientConfig) WithCertificatePath added in v0.0.17

func (c *ClientConfig) WithCertificatePath(certPath *string) *ClientConfig

WithCertificatePath sets the CA certificates from the given path

func (*ClientConfig) WithClientCredentials

func (c *ClientConfig) WithClientCredentials(clientID, clientSecret string) *ClientConfig

WithClientCredentials sets up client credentials grant type authentication

func (*ClientConfig) WithContextToken added in v0.0.18

func (c *ClientConfig) WithContextToken() *ClientConfig

WithContextToken sets up authentication with the token set on each request's context by ContextWithToken

func (*ClientConfig) WithHTTPClient

func (c *ClientConfig) WithHTTPClient(httpClient *http.Client) *ClientConfig

WithHTTPClient sets the HTTP client to use for requests

func (*ClientConfig) WithTimeout

func (c *ClientConfig) WithTimeout(timeout time.Duration) *ClientConfig

WithTimeout sets the timeout for requests

func (*ClientConfig) WithToken

func (c *ClientConfig) WithToken(token string) *ClientConfig

WithToken sets a static token for authentication

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope,omitempty"`
}

TokenResponse represents the response from the OAuth token endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL