handler

package
v0.0.0-...-9d09e4b Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Index

Index handles requests for / path

func NewRouter

func NewRouter(db *database.Database) http.Handler

NewRouter creates a new httprouter Router, sets the handler for each route and adds middleware for enabling CORS with the default options.

Returns an http.Handler

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

Redirect handles requests for /redirect path

func RedirectURL

func RedirectURL(db *database.Database) httprouter.Handle

RedirectURL handles requests for /redirect/:short_url path

func ShortenURL

func ShortenURL(db *database.Database) httprouter.Handle

ShortenURL handles requests for /shorten path

Types

type ErrorResp

type ErrorResp struct {
	Error string `json:"error"`
}

ErrorResp represents the JSON response that will be sent on errors.

type MessageResp

type MessageResp struct {
	Message string `json:"message"`
}

MessageResp represents the JSON response that will be sent as a message.

type ShortenReq

type ShortenReq struct {
	LongURL string `json:"long_url"`
}

ShortenReq represents the JSON body of the request that will be decoded, on the shorten endpoint.

type ShortenResp

type ShortenResp struct {
	LongURL  string `json:"long_url"`
	ShortURL string `json:"short_url"`
}

ShortenResp represents the JSON response that will be sent, on the shorten endpoint.

Jump to

Keyboard shortcuts

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