Documentation
¶
Overview ¶
Package client provides clients that provide basic access to ANAF APIs.
Index ¶
- func MultipartFormFile(w *multipart.Writer, fieldname, path, contentType string) error
- func MultipartFormFileData(w *multipart.Writer, fieldname, filename string, data []byte, ...) error
- type ApiClient
- func (c ApiClient) Do(req *http.Request) (resp *http.Response, err error)
- func (c ApiClient) DoUnmarshalJSON(req *http.Request, destResponse any, cb func(*http.Response, any) error) error
- func (c ApiClient) DoUnmarshalXML(req *http.Request, response any) error
- func (c ApiClient) NewRequest(ctx context.Context, method string, refURL string, query url.Values, ...) (*http.Request, error)
- func (c *ApiClient) RevokeAccessToken(ctx context.Context, accessToken string) error
- func (c *ApiClient) RevokeRefreshToken(ctx context.Context, refreshToken string) error
- func (c ApiClient) Wait()
- type ApiClientConfig
- type ApiClientConfigOption
- func ApiClientBaseURL(baseURL string) ApiClientConfigOption
- func ApiClientContext(ctx context.Context) ApiClientConfigOption
- func ApiClientInsecureSkipVerify(skipVerify bool) ApiClientConfigOption
- func ApiClientOAuth2TokenSource(tokenSource xoauth2.TokenSource) ApiClientConfigOption
- func ApiClientProductionEnvironment(prod bool) ApiClientConfigOption
- func ApiClientSandboxEnvironment(sandbox bool) ApiClientConfigOption
- func ApiClientUserAgent(userAgent string) ApiClientConfigOption
- type PublicApiClient
- func (c PublicApiClient) Do(req *http.Request) (resp *http.Response, err error)
- func (c PublicApiClient) DoUnmarshalJSON(req *http.Request, destResponse any, cb func(*http.Response, any) error) error
- func (c PublicApiClient) DoUnmarshalXML(req *http.Request, response any) error
- func (c PublicApiClient) NewRequest(ctx context.Context, method string, refURL string, query url.Values, ...) (*http.Request, error)
- func (c PublicApiClient) Wait()
- type PublicApiClientConfig
- type PublicApiClientConfigOption
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultipartFormFile ¶
MultipartFormFile adds the multipart file given by path to the multipart.Writer with the given field name.
Types ¶
type ApiClient ¶
type ApiClient struct {
// contains filtered or unexported fields
}
ApiClient is a client that interacts with ANAF protected APIs (APIs that required OAuth2 authentication).
func NewApiClient ¶
func NewApiClient(opts ...ApiClientConfigOption) (*ApiClient, error)
NewApiClient creates a new ApiClient using the provided config options.
func (ApiClient) Do ¶
Do sends the given HTTP request and returns an HTTP response. A non-200 response results in an *errors.ErrorResponse error.
func (ApiClient) DoUnmarshalJSON ¶
func (c ApiClient) DoUnmarshalJSON(req *http.Request, destResponse any, cb func(*http.Response, any) error) error
DoUnmarshalJSON sends the given HTTP request and expects a JSON response which is unmarshalled into response. A non-200 response results in an *errors.ErrorResponse error. If response body if not application/json, we try to autodetect if request limits are exceeded.
func (ApiClient) DoUnmarshalXML ¶
DoUnmarshalXML sends the given HTTP request and expects an XML response which is unmarshalled into response. A non-200 response results in an *errors.ErrorResponse error. If response body if not application/xml, we try to autodetect if request limits are exceeded.
func (ApiClient) NewRequest ¶
func (c ApiClient) NewRequest(ctx context.Context, method string, refURL string, query url.Values, body io.Reader, opts ...RequestOption, ) (*http.Request, error)
NewRequest creates an API request. refURL is resolved relative to the client baseURL. The relative URL should always be specified without a preceding slash.
func (*ApiClient) RevokeAccessToken ¶
func (*ApiClient) RevokeRefreshToken ¶
type ApiClientConfig ¶
type ApiClientConfig struct { // TokenSource is the token source used for generating OAuth2 tokens. // Until this library will support authentication with the SPV certificate, // this must always be provided. TokenSource xoauth2.TokenSource // Unless BaseURL is set, Sandbox controls whether to use production // endpoints (if set to false) or test endpoints (if set to true). Sandbox bool // Context to use for creating the HTTP client. If not set, // context.Background will be used. Ctx context.Context // User agent used when communicating with the ANAF API. UserAgent *string // Base URL of the ANAF protected APIs. It is only useful in // development/testing environments. BaseURL *string // Whether to skip the verification of the SSL certificate (default false). // Since this is a security risk, it should only be use with a custom // BaseURL in development/testing environments. InsecureSkipVerify bool }
ApiClientConfig is the config used to create an ApiClient
type ApiClientConfigOption ¶
type ApiClientConfigOption func(*ApiClientConfig)
ApiClientConfigOption allows gradually modifying a ApiClientConfig
func ApiClientBaseURL ¶
func ApiClientBaseURL(baseURL string) ApiClientConfigOption
ApiClientBaseURL sets the BaseURL to the given url. This should only be used when testing or using a custom endpoint for debugging/testing.
func ApiClientContext ¶
func ApiClientContext(ctx context.Context) ApiClientConfigOption
ApiClientContext sets the Context to use for building the http.Client.
func ApiClientInsecureSkipVerify ¶
func ApiClientInsecureSkipVerify(skipVerify bool) ApiClientConfigOption
ApiClientInsecureSkipVerify allows only setting InsecureSkipVerify. Please check the documentation for the InsecureSkipVerify field for a warning.
func ApiClientOAuth2TokenSource ¶
func ApiClientOAuth2TokenSource(tokenSource xoauth2.TokenSource) ApiClientConfigOption
ApiClientOAuth2TokenSource sets the token source to use for authorizing requests.
func ApiClientProductionEnvironment ¶
func ApiClientProductionEnvironment(prod bool) ApiClientConfigOption
ApiClientProductionEnvironment is the inverse of ApiClientSandboxEnvironment if called with prod=true sets the BaseURL to the production URL, if called with prod=false sets the BaseURL to the sandbox URL.
func ApiClientSandboxEnvironment ¶
func ApiClientSandboxEnvironment(sandbox bool) ApiClientConfigOption
ApiClientSandboxEnvironment is the inverse of ApiClientProductionEnvironment: if called with sandbox=true sets the BaseURL to the sandbox URL, if called with sandbox=false sets the BaseURL to the production URL.
func ApiClientUserAgent ¶
func ApiClientUserAgent(userAgent string) ApiClientConfigOption
ApiClientUserAgent sets the user agent used to communicate with the ANAF API.
type PublicApiClient ¶
type PublicApiClient struct {
// contains filtered or unexported fields
}
PublicApiClient is a client that interacts with ANAF public APIs (no OAuth2 authentication is performed automatically by this client).
func NewPublicApiClient ¶
func NewPublicApiClient(opts ...PublicApiClientConfigOption) (*PublicApiClient, error)
NewPublicApiClient creates a new PublicApiClient using the provided config options.
func (PublicApiClient) Do ¶
Do sends the given HTTP request and returns an HTTP response. A non-200 response results in an *errors.ErrorResponse error.
func (PublicApiClient) DoUnmarshalJSON ¶
func (c PublicApiClient) DoUnmarshalJSON(req *http.Request, destResponse any, cb func(*http.Response, any) error) error
DoUnmarshalJSON sends the given HTTP request and expects a JSON response which is unmarshalled into response. A non-200 response results in an *errors.ErrorResponse error. If response body if not application/json, we try to autodetect if request limits are exceeded.
func (PublicApiClient) DoUnmarshalXML ¶
DoUnmarshalXML sends the given HTTP request and expects an XML response which is unmarshalled into response. A non-200 response results in an *errors.ErrorResponse error. If response body if not application/xml, we try to autodetect if request limits are exceeded.
func (PublicApiClient) NewRequest ¶
func (c PublicApiClient) NewRequest(ctx context.Context, method string, refURL string, query url.Values, body io.Reader, opts ...RequestOption, ) (*http.Request, error)
NewRequest creates an API request. refURL is resolved relative to the client baseURL. The relative URL should always be specified without a preceding slash.
type PublicApiClientConfig ¶
type PublicApiClientConfig struct { // Base URL of the ANAF public APIs. It is only useful in // development/testing environments. BaseURL *string // User agent used when communicating with the ANAF API. UserAgent *string // Whether to skip the verification of the SSL certificate (default false). // Since this is a security risk, it should only be use with a custom // BaseURL in development/testing environments. InsecureSkipVerify bool }
PublicApiClientConfig is the config used to create a PublicApiClient
type PublicApiClientConfigOption ¶
type PublicApiClientConfigOption func(*PublicApiClientConfig)
PublicApiClientConfigOption allows gradually modifying a PublicApiClientConfig
func PublicApiClientBaseURL ¶
func PublicApiClientBaseURL(baseURL string) PublicApiClientConfigOption
PublicApiClientBaseURL sets the BaseURL to the given url. This should only be used when testing or using a custom endpoint for debugging.
func PublicApiClientInsecureSkipVerify ¶
func PublicApiClientInsecureSkipVerify(skipVerify bool) PublicApiClientConfigOption
PublicApiClientInsecureSkipVerify allows only setting InsecureSkipVerify. Please check the documentation for the InsecureSkipVerify field for a warning.
func PublicApiClientUserAgent ¶
func PublicApiClientUserAgent(userAgent string) PublicApiClientConfigOption
PublicApiClientUserAgent sets the user agent used to communicate with the ANAF API.
type RequestOption ¶
RequestOption represents an option that can modify an http.Request.
func RequestOptionHeader ¶
func RequestOptionHeader(name, value string) RequestOption