Documentation
¶
Overview ¶
Package api provides an HTTP client for the Memegen.link API.
Index ¶
- Constants
- func AppendQueryParams(baseURL string, params url.Values) (string, error)
- func WithClient(ctx context.Context, cl *Client) context.Context
- type AutomaticRequest
- type AutomaticResponse
- type Client
- func (c *Client) Generate(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)
- func (c *Client) GenerateAutomatic(ctx context.Context, req AutomaticRequest) (*AutomaticResponse, error)
- func (c *Client) GenerateCustom(ctx context.Context, req CustomRequest) (*GenerateResponse, error)
- func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) GetFont(ctx context.Context, id string) (*Font, error)
- func (c *Client) GetTemplate(ctx context.Context, id string) (*Template, error)
- func (c *Client) ListFonts(ctx context.Context) ([]Font, error)
- func (c *Client) ListTemplates(ctx context.Context, filter string) ([]Template, error)
- func (c *Client) Post(ctx context.Context, path string, body io.Reader) (*http.Response, error)
- type ClientOptions
- type CustomRequest
- type Error
- type Font
- type GenerateRequest
- type GenerateResponse
- type Template
Constants ¶
const DefaultBaseURL = "https://api.memegen.link"
DefaultBaseURL is the Memegen.link API base URL.
Variables ¶
This section is empty.
Functions ¶
func AppendQueryParams ¶
AppendQueryParams merges the given url.Values onto baseURL's existing query string. It is used to add presentation params (color, width, etc.) to the meme URL returned by the API.
Types ¶
type AutomaticRequest ¶
AutomaticRequest is the payload for POST /images/automatic.
type AutomaticResponse ¶
type AutomaticResponse struct {
URL string `json:"url"`
Generator string `json:"generator,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
}
AutomaticResponse is the response from POST /images/automatic.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an HTTP client for Memegen API calls.
func ClientFromContext ¶
ClientFromContext retrieves the Client from the context.
func NewClient ¶
func NewClient(opts ClientOptions) *Client
NewClient builds a Client with retry transport and optional verbose logging.
func (*Client) Generate ¶
func (c *Client) Generate(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)
Generate posts a template-based meme request to POST /images and returns the generated meme URL.
func (*Client) GenerateAutomatic ¶
func (c *Client) GenerateAutomatic(ctx context.Context, req AutomaticRequest) (*AutomaticResponse, error)
GenerateAutomatic posts text to /images/automatic and returns the auto-selected meme URL along with generator metadata.
func (*Client) GenerateCustom ¶
func (c *Client) GenerateCustom(ctx context.Context, req CustomRequest) (*GenerateResponse, error)
GenerateCustom posts a custom-background meme request to POST /images/custom and returns the generated meme URL.
func (*Client) GetTemplate ¶
GetTemplate fetches a single template by ID from GET /templates/{id}.
func (*Client) ListTemplates ¶
ListTemplates fetches all meme templates from GET /templates. The optional filter query-param narrows results server-side.
type ClientOptions ¶
ClientOptions configures a new Client.
type CustomRequest ¶
type CustomRequest struct {
Background string `json:"background"`
Text []string `json:"text"`
Extension string `json:"extension,omitempty"`
Font string `json:"font,omitempty"`
Layout string `json:"layout,omitempty"`
Style string `json:"style,omitempty"`
Redirect bool `json:"redirect"` // always false
}
CustomRequest is the payload for POST /images/custom.
type Font ¶
type Font struct {
ID string `json:"id"`
Alias *string `json:"alias"` // nullable in API
Filename string `json:"filename"`
Self string `json:"_self"`
}
Font describes a font from the API.
type GenerateRequest ¶
type GenerateRequest struct {
TemplateID string `json:"template_id"`
Text []string `json:"text"`
Extension string `json:"extension,omitempty"`
Font string `json:"font,omitempty"`
Layout string `json:"layout,omitempty"`
Style []string `json:"style,omitempty"`
Redirect bool `json:"redirect"` // always false
}
GenerateRequest is the payload for POST /images/{template_id}.
type GenerateResponse ¶
type GenerateResponse struct {
URL string `json:"url"`
}
GenerateResponse is the response from template/custom generation endpoints.
type Template ¶
type Template struct {
ID string `json:"id"`
Name string `json:"name"`
Lines int `json:"lines"`
Overlays int `json:"overlays"`
Styles []string `json:"styles"`
Blank string `json:"blank"`
Example struct {
Text []string `json:"text"`
URL string `json:"url"`
} `json:"example"`
Source string `json:"source"`
Keywords []string `json:"keywords"`
Self string `json:"_self"`
}
Template describes a meme template from the API.