Documentation ¶
Index ¶
- func Bool(value bool) param.Field[bool]
- func F[T any](value T) param.Field[T]
- func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]
- func Float(value float64) param.Field[float64]
- func Int(value int64) param.Field[int64]
- func Null[T any]() param.Field[T]
- func Raw[T any](value any) param.Field[T]
- func String(value string) param.Field[string]
- type Client
- func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, ...) error
- func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- type Error
- type ShortURL
- type ShortURLCountResult
- type ShortURLSearchResult
- type ShortURLSearchResultURL
- type URLDeleteByOriginalURLParams
- type URLDeleteByOriginalURLResponse
- type URLDeleteByShortIDParams
- type URLDeleteByShortIDResponse
- type URLFromOriginalURLParams
- type URLFromOriginalURLResponse
- type URLFromShortIDParams
- type URLFromShortIDResponse
- type URLNewParams
- type URLNewResponse
- type URLQuickCountResponse
- type URLSearchParams
- type URLSearchResponse
- type URLService
- func (r *URLService) DeleteByOriginalURL(ctx context.Context, body URLDeleteByOriginalURLParams, ...) (res *URLDeleteByOriginalURLResponse, err error)
- func (r *URLService) DeleteByShortID(ctx context.Context, body URLDeleteByShortIDParams, ...) (res *URLDeleteByShortIDResponse, err error)
- func (r *URLService) FromOriginalURL(ctx context.Context, query URLFromOriginalURLParams, ...) (res *URLFromOriginalURLResponse, err error)
- func (r *URLService) FromShortID(ctx context.Context, query URLFromShortIDParams, opts ...option.RequestOption) (res *URLFromShortIDResponse, err error)
- func (r *URLService) New(ctx context.Context, body URLNewParams, opts ...option.RequestOption) (res *URLNewResponse, err error)
- func (r *URLService) QuickCount(ctx context.Context, opts ...option.RequestOption) (res *URLQuickCountResponse, err error)
- func (r *URLService) Search(ctx context.Context, query URLSearchParams, opts ...option.RequestOption) (res *URLSearchResponse, err error)
- func (r *URLService) SlowCount(ctx context.Context, opts ...option.RequestOption) (res *URLSlowCountResponse, err error)
- type URLSlowCountResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func F ¶
F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.
func Int ¶
Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.
func Raw ¶
Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).
Types ¶
type Client ¶
type Client struct { Options []option.RequestOption URLs *URLService }
Client creates a struct with services and top level methods that help with interacting with the sst-url-shortener API. You should not instantiate this client directly, and instead use the NewClient method instead.
func NewClient ¶
func NewClient(opts ...option.RequestOption) (r *Client)
NewClient generates a new client with the default option read from the environment (BEARER_TOKEN). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.
func (*Client) Delete ¶
func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Execute ¶
func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.
If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.
The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.
If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.
Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.
The response body will be deserialized into the res variable, depending on its type:
- A pointer to a *http.Response is populated by the raw response.
- A pointer to a byte array will be populated with the contents of the request body.
- A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
- A nil value will not read the response body.
For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.
func (*Client) Get ¶
func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Patch ¶
func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Post ¶
func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
type ShortURL ¶
type ShortURL struct { CreatedAt time.Time `json:"createdAt,required" format:"date-time"` OriginalURL string `json:"originalUrl,required" format:"uri"` ShortID string `json:"shortId,required"` ShortURL string `json:"shortUrl,required" format:"uri"` ExpiredAt time.Time `json:"expiredAt" format:"date-time"` JSON shortURLJSON `json:"-"` }
func (*ShortURL) UnmarshalJSON ¶
type ShortURLCountResult ¶
type ShortURLCountResult struct { Count float64 `json:"count,required"` JSON shortURLCountResultJSON `json:"-"` }
func (*ShortURLCountResult) UnmarshalJSON ¶
func (r *ShortURLCountResult) UnmarshalJSON(data []byte) (err error)
type ShortURLSearchResult ¶
type ShortURLSearchResult struct { Cursor string `json:"cursor,required,nullable"` URLs []ShortURLSearchResultURL `json:"urls,required"` JSON shortURLSearchResultJSON `json:"-"` }
func (*ShortURLSearchResult) UnmarshalJSON ¶
func (r *ShortURLSearchResult) UnmarshalJSON(data []byte) (err error)
type ShortURLSearchResultURL ¶
type ShortURLSearchResultURL struct { CreatedAt time.Time `json:"createdAt,required" format:"date-time"` OriginalURL string `json:"originalUrl,required" format:"uri"` ShortID string `json:"shortId,required"` ShortURL string `json:"shortUrl,required" format:"uri"` ExpiredAt time.Time `json:"expiredAt" format:"date-time"` JSON shortURLSearchResultURLJSON `json:"-"` }
func (*ShortURLSearchResultURL) UnmarshalJSON ¶
func (r *ShortURLSearchResultURL) UnmarshalJSON(data []byte) (err error)
type URLDeleteByOriginalURLParams ¶
type URLDeleteByOriginalURLParams struct {
OriginalURL param.Field[string] `query:"originalUrl,required" format:"uri"`
}
func (URLDeleteByOriginalURLParams) URLQuery ¶
func (r URLDeleteByOriginalURLParams) URLQuery() (v url.Values)
URLQuery serializes URLDeleteByOriginalURLParams's query parameters as `url.Values`.
type URLDeleteByOriginalURLResponse ¶
type URLDeleteByOriginalURLResponse = interface{}
type URLDeleteByShortIDParams ¶
func (URLDeleteByShortIDParams) URLQuery ¶
func (r URLDeleteByShortIDParams) URLQuery() (v url.Values)
URLQuery serializes URLDeleteByShortIDParams's query parameters as `url.Values`.
type URLDeleteByShortIDResponse ¶
type URLDeleteByShortIDResponse = interface{}
type URLFromOriginalURLParams ¶
type URLFromOriginalURLParams struct {
OriginalURL param.Field[string] `query:"originalUrl,required" format:"uri"`
}
func (URLFromOriginalURLParams) URLQuery ¶
func (r URLFromOriginalURLParams) URLQuery() (v url.Values)
URLQuery serializes URLFromOriginalURLParams's query parameters as `url.Values`.
type URLFromOriginalURLResponse ¶
type URLFromOriginalURLResponse struct { Result ShortURL `json:"result,required"` JSON urlFromOriginalURLResponseJSON `json:"-"` }
func (*URLFromOriginalURLResponse) UnmarshalJSON ¶
func (r *URLFromOriginalURLResponse) UnmarshalJSON(data []byte) (err error)
type URLFromShortIDParams ¶
func (URLFromShortIDParams) URLQuery ¶
func (r URLFromShortIDParams) URLQuery() (v url.Values)
URLQuery serializes URLFromShortIDParams's query parameters as `url.Values`.
type URLFromShortIDResponse ¶
type URLFromShortIDResponse struct { Result ShortURL `json:"result,required"` JSON urlFromShortIDResponseJSON `json:"-"` }
func (*URLFromShortIDResponse) UnmarshalJSON ¶
func (r *URLFromShortIDResponse) UnmarshalJSON(data []byte) (err error)
type URLNewParams ¶
type URLNewParams struct { OriginalURL param.Field[string] `json:"originalUrl,required" format:"uri"` ExpiredAt param.Field[time.Time] `json:"expiredAt" format:"date-time"` }
func (URLNewParams) MarshalJSON ¶
func (r URLNewParams) MarshalJSON() (data []byte, err error)
type URLNewResponse ¶
type URLNewResponse struct { Result ShortURL `json:"result,required"` JSON urlNewResponseJSON `json:"-"` }
func (*URLNewResponse) UnmarshalJSON ¶
func (r *URLNewResponse) UnmarshalJSON(data []byte) (err error)
type URLQuickCountResponse ¶
type URLQuickCountResponse struct { Result ShortURLCountResult `json:"result,required"` JSON urlQuickCountResponseJSON `json:"-"` }
func (*URLQuickCountResponse) UnmarshalJSON ¶
func (r *URLQuickCountResponse) UnmarshalJSON(data []byte) (err error)
type URLSearchParams ¶
type URLSearchParams struct { Cursor param.Field[string] `query:"cursor"` ExpiredAtLte param.Field[time.Time] `query:"expiredAtLTE" format:"date-time"` Limit param.Field[float64] `query:"limit"` OriginalURLBeginsWith param.Field[string] `query:"originalUrlBeginsWith"` }
func (URLSearchParams) URLQuery ¶
func (r URLSearchParams) URLQuery() (v url.Values)
URLQuery serializes URLSearchParams's query parameters as `url.Values`.
type URLSearchResponse ¶
type URLSearchResponse struct { Result ShortURLSearchResult `json:"result,required"` JSON urlSearchResponseJSON `json:"-"` }
func (*URLSearchResponse) UnmarshalJSON ¶
func (r *URLSearchResponse) UnmarshalJSON(data []byte) (err error)
type URLService ¶
type URLService struct {
Options []option.RequestOption
}
URLService contains methods and other services that help with interacting with the sst-url-shortener API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewURLService method instead.
func NewURLService ¶
func NewURLService(opts ...option.RequestOption) (r *URLService)
NewURLService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*URLService) DeleteByOriginalURL ¶
func (r *URLService) DeleteByOriginalURL(ctx context.Context, body URLDeleteByOriginalURLParams, opts ...option.RequestOption) (res *URLDeleteByOriginalURLResponse, err error)
Delete a short url by original url
func (*URLService) DeleteByShortID ¶
func (r *URLService) DeleteByShortID(ctx context.Context, body URLDeleteByShortIDParams, opts ...option.RequestOption) (res *URLDeleteByShortIDResponse, err error)
Delete a short url by short id
func (*URLService) FromOriginalURL ¶
func (r *URLService) FromOriginalURL(ctx context.Context, query URLFromOriginalURLParams, opts ...option.RequestOption) (res *URLFromOriginalURLResponse, err error)
Get the short url from the original url
func (*URLService) FromShortID ¶
func (r *URLService) FromShortID(ctx context.Context, query URLFromShortIDParams, opts ...option.RequestOption) (res *URLFromShortIDResponse, err error)
Get the short url from the short id
func (*URLService) New ¶
func (r *URLService) New(ctx context.Context, body URLNewParams, opts ...option.RequestOption) (res *URLNewResponse, err error)
Create a new short url
func (*URLService) QuickCount ¶
func (r *URLService) QuickCount(ctx context.Context, opts ...option.RequestOption) (res *URLQuickCountResponse, err error)
Get approximate count of short urls in the DB. Updated every 6 hours.
func (*URLService) Search ¶
func (r *URLService) Search(ctx context.Context, query URLSearchParams, opts ...option.RequestOption) (res *URLSearchResponse, err error)
Paginated search of short urls
func (*URLService) SlowCount ¶
func (r *URLService) SlowCount(ctx context.Context, opts ...option.RequestOption) (res *URLSlowCountResponse, err error)
Scan through the entire table to get real-time count of items
type URLSlowCountResponse ¶
type URLSlowCountResponse struct { Result ShortURLCountResult `json:"result,required"` JSON urlSlowCountResponseJSON `json:"-"` }
func (*URLSlowCountResponse) UnmarshalJSON ¶
func (r *URLSlowCountResponse) UnmarshalJSON(data []byte) (err error)