api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsuccessfulReply = Reply{Success: false}
	ErrNotFoundReply     = Reply{Success: false, Error: "resource not found"}
	ErrNotAllowedReply   = Reply{Success: false, Error: "method not allowed"}
	ErrUnparsable        = Reply{Success: false, Error: "could not parse json request"}
)
View Source
var (
	ErrMissingURL         = errors.New("a url is required for shortening")
	ErrCannotParseExpires = errors.New("expires must be a timestamp in the form of YYYY-MM-DD or YYYY-MM-DD HH:MM:SS")
	ErrInvalidExpires     = errors.New("expiration must be valid timestamp in the future")
	ErrParseBearer        = errors.New("could not parse Bearer token from Authorization header")
	ErrNoAuthorization    = errors.New("no authorization header in request")
	ErrInvalidToken       = errors.New("invalid bearer token in Authorization header")
	ErrUnauthenticated    = errors.New("this endpoint requires authentication")
)

Functions

This section is empty.

Types

type LongURL added in v0.2.0

type LongURL struct {
	URL     string `json:"url"`
	Expires string `json:"expires,omitempty"`
}

func (*LongURL) ExpiresAt added in v0.2.0

func (u *LongURL) ExpiresAt() (time.Time, error)

func (*LongURL) Validate added in v0.2.0

func (u *LongURL) Validate() error

type PageQuery

type PageQuery struct {
	PageSize      int    `json:"page_size" url:"page_size,omitempty" form:"page_size"`
	NextPageToken string `json:"next_page_token" url:"next_page_token,omitempty" form:"next_page_token"`
}

PageQuery manages paginated list requests.

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func ErrorResponse

func ErrorResponse(err interface{}) Reply

Construct a new response for an error or simply return unsuccessful.

type Service added in v1.0.0

type Service interface {
	// Unauthenticated endpoints
	Status(context.Context) (*StatusReply, error)

	// URL Management
	ShortenURL(context.Context, *LongURL) (*ShortURL, error)
	ShortURLInfo(context.Context, string) (*ShortURL, error)
	DeleteShortURL(context.Context, string) error
}

type ShortURL added in v0.2.0

type ShortURL struct {
	URL     string     `json:"url"`
	AltURL  string     `json:"alt_url,omitempty"`
	Visits  uint64     `json:"visits,omitempty"`
	Expires *time.Time `json:"expires,omitempty"`
}

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

Jump to

Keyboard shortcuts

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