client

package
v0.0.0-...-3a9b5ea Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package client provides clients that provide basic access to ANAF APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultipartFormFile

func MultipartFormFile(w *multipart.Writer, fieldname, path, contentType string) error

MultipartFormFile adds the multipart file given by path to the multipart.Writer with the given field name.

func MultipartFormFileData

func MultipartFormFileData(w *multipart.Writer, fieldname, filename string, data []byte, contentType string) error

MultipartFormFileData adds the multipart file given by contents 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

func (c ApiClient) Do(req *http.Request) (resp *http.Response, err error)

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

func (c ApiClient) DoUnmarshalXML(req *http.Request, response any) error

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 (c *ApiClient) RevokeAccessToken(ctx context.Context, accessToken string) error

func (*ApiClient) RevokeRefreshToken

func (c *ApiClient) RevokeRefreshToken(ctx context.Context, refreshToken string) error

func (ApiClient) Wait

func (c ApiClient) Wait()

Wait wait for all requests for finish

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

func (c PublicApiClient) Do(req *http.Request) (resp *http.Response, err error)

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

func (c PublicApiClient) DoUnmarshalXML(req *http.Request, response any) error

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.

func (PublicApiClient) Wait

func (c PublicApiClient) Wait()

Wait wait for all requests for finish

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

type RequestOption func(req *http.Request)

RequestOption represents an option that can modify an http.Request.

func RequestOptionHeader

func RequestOptionHeader(name, value string) RequestOption

Jump to

Keyboard shortcuts

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