url

package
v0.0.0-...-87faeab Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServerError = &ErrResponse{
		HTTPStatusCode: http.StatusInternalServerError,
		StatusText:     http.StatusText(http.StatusInternalServerError),
	}
	ErrForbidden = &ErrResponse{
		HTTPStatusCode: http.StatusForbidden,
		StatusText:     http.StatusText(http.StatusForbidden),
	}
)

The list of default error types without specific error message.

View Source
var ErrAPIUnsupported = errors.New("unsupported api version")

ErrAPIUnsupported an unsupported api version

View Source
var ErrMissingAPIVersion = errors.New("missing api version header")

ErrMissingAPIVersion a missing api version header with the version text.

View Source
var ErrMissingToken = errors.New("missing authorization header")

ErrMissingToken a missing authorization header with the Bearer token.

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest returns status 422 Unprocessable Entity including error message.

func ErrURLNotFound

func ErrURLNotFound(err error) render.Renderer

ErrURLNotFound returns status 404 Not Found including error message.

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized renders status 401 Unauthorized with custom error message.

func Shorten

func Shorten(originalURL string, len int) (string, error)

Shorten shortens a long url string

Types

type ErrResponse

type ErrResponse struct {
	Err            error  `json:"-"`               // low-level runtime error
	HTTPStatusCode int    `json:"-"`               // http response status code
	StatusText     string `json:"status"`          // user-level status message
	AppCode        int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText      string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render sets the application-specific error code in AppCode.

type Resource

type Resource struct {
	Store  store.Store
	Config *config.Config
}

Resource defines dependencies for url handlers.

func NewResource

func NewResource(store store.Store, cfg *config.Config) *Resource

NewResource returns a configures url resource.

func (Resource) HandleShortenURL

func (rs Resource) HandleShortenURL(w http.ResponseWriter, r *http.Request)

HandleShortenURL shortens the url and returns the shrotened url in the response body

func (*Resource) Router

func (rs *Resource) Router() *chi.Mux

Router provides necessary routes for shortening and resolving fupisha urls.

Jump to

Keyboard shortcuts

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