api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	// contains filtered or unexported fields
}

Functions

func WithClient

func WithClient(client *http.Client) func(*Config)

func WithDefaultClient

func WithDefaultClient() func(*Config)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(url string, opts ...Option) *Client
func (c *Client) GetLink(ctx context.Context, linkID string) (GetLinkResponse, error)

func (*Client) Shorten

func (c *Client) Shorten(ctx context.Context, targetURL string) (PostLinksResponse, error)

type Config

type Config struct {
	// contains filtered or unexported fields
}
type CreateLink struct {
	TargetURL string `json:"targetUrl" validate:"required,http_url"` // Target link to shorten
}

type GetLinkResponse

type GetLinkResponse struct {
	Link Link `json:"link"`
}

type GetStatsResponse

type GetStatsResponse struct {
	Stats Stats `json:"stats"`
}
type Link struct {
	ID        string `json:"id"`                     // ID
	TargetURL string `json:"targetUrl" format:"uri"` // Target link
	URL       string `json:"url" format:"uri"`       // Short link

	CreatedAt  time.Time `json:"createdAt" format:"date-time"`  // Created at
	ValidUntil time.Time `json:"validUntil" format:"date-time"` // Valid until
}

type Option

type Option func(*Config)

type PostLinksRequest

type PostLinksRequest struct {
	Link CreateLink `json:"link"`
}

type PostLinksResponse

type PostLinksResponse struct {
	Link Link `json:"link"`
}

type Stats

type Stats struct {
	Labels map[string]map[string]int `json:"labels"` // Redirects by labels' values
	Total  int                       `json:"total"`  // Total redirects
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳