Documentation
¶
Overview ¶
Package common provides a basic HTTP client to perform HTTP calls. It supports Basic and OAuth authentication methods.
Index ¶
- Constants
- func ConvertSliceItems[T any](input any) ([]T, error)
- func IsValidUUID(u string) bool
- type AuthType
- type Client
- func (c *Client) Call(method, path string, params map[string]interface{}) (*http.Response, error)
- func (c *Client) Delete(path string) (*http.Response, error)
- func (c *Client) Get(path string) (*http.Response, error)
- func (c *Client) GetAuth() *ClientAuth
- func (c *Client) Patch(path string, params map[string]interface{}) (*http.Response, error)
- func (c *Client) Post(path string, params map[string]interface{}) (*http.Response, error)
- func (c *Client) Put(path string, params map[string]interface{}) (*http.Response, error)
- type ClientAuth
- func (ca *ClientAuth) GetAccessToken() string
- func (ca *ClientAuth) GetAccessTokenExpire() int
- func (ca *ClientAuth) GetApplicationId() string
- func (ca *ClientAuth) GetAuthType() AuthType
- func (ca *ClientAuth) GetCustomerId() string
- func (ca *ClientAuth) GetRefreshToken() string
- func (ca *ClientAuth) SetApplicationAuth(id, secret string) error
- func (ca *ClientAuth) SetCustomerAuth(id, key string) error
- func (ca *ClientAuth) SetNoAuth()
- func (ca *ClientAuth) SetUserAuth(accessToken string, tokenExpire int, refreshToken string) error
- func (ca *ClientAuth) SwitchBack()
- func (ca *ClientAuth) SwitchTo(authType AuthType)
- func (ca *ClientAuth) Update(data map[string]interface{}) error
Constants ¶
View Source
const Version = "0.1.0"
Variables ¶
This section is empty.
Functions ¶
func ConvertSliceItems ¶
func IsValidUUID ¶
IsValidUUID checks that u is a valid UUID4 string
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds the configuration (url, auth) and wraps http Requests
func NewClient ¶
func NewClient(serverUrl string, auth *ClientAuth) *Client
NewClient configures and returns a new Client
func (*Client) Call ¶
Performs a HTTP Call using Client configuration `params` map may contain the following keys:
- "_data" is the data to be sent in the request body.
- For "application/json" content type, data is serialized as JSON
- For "application/x-www-form-urlencoded" content type, data is serialized as a form
- "_rawResponse" is a boolean that indicates if the response should be returned as is
- "Content-Type" is the content type of the request, it defaults to "application/json"
- any other key-value pairs which doesn't start wiht a '_' are added as request headers
func (*Client) GetAuth ¶
func (c *Client) GetAuth() *ClientAuth
type ClientAuth ¶
type ClientAuth struct {
// contains filtered or unexported fields
}
ClientAuth keeps the authentication details - Basic vs Bearer (OAuth)
func GetFakeAuth ¶
func GetFakeAuth() *ClientAuth
func NewClientAuth ¶
func NewClientAuth(data map[string]interface{}) *ClientAuth
NewClientAuth returns a new ClientAuth with auth set to NoAuth
func (*ClientAuth) GetAccessToken ¶
func (ca *ClientAuth) GetAccessToken() string
func (*ClientAuth) GetAccessTokenExpire ¶
func (ca *ClientAuth) GetAccessTokenExpire() int
func (*ClientAuth) GetApplicationId ¶
func (ca *ClientAuth) GetApplicationId() string
func (*ClientAuth) GetAuthType ¶
func (ca *ClientAuth) GetAuthType() AuthType
func (*ClientAuth) GetCustomerId ¶
func (ca *ClientAuth) GetCustomerId() string
func (*ClientAuth) GetRefreshToken ¶
func (ca *ClientAuth) GetRefreshToken() string
func (*ClientAuth) SetApplicationAuth ¶
func (ca *ClientAuth) SetApplicationAuth(id, secret string) error
func (*ClientAuth) SetCustomerAuth ¶
func (ca *ClientAuth) SetCustomerAuth(id, key string) error
Set ClientAuth authType to BasicAuth removing tokens
func (*ClientAuth) SetNoAuth ¶
func (ca *ClientAuth) SetNoAuth()
Set ClientAuth authType to NoAuth removing other attributes
func (*ClientAuth) SetUserAuth ¶
func (ca *ClientAuth) SetUserAuth(accessToken string, tokenExpire int, refreshToken string) error
func (*ClientAuth) SwitchBack ¶
func (ca *ClientAuth) SwitchBack()
func (*ClientAuth) SwitchTo ¶
func (ca *ClientAuth) SwitchTo(authType AuthType)
func (*ClientAuth) Update ¶
func (ca *ClientAuth) Update(data map[string]interface{}) error
Click to show internal directories.
Click to hide internal directories.