web

package
v0.0.0-...-1d2f786 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Request, val any) error

Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value.

If the provided value is a struct then it is checked for validation tags.

func Respond

func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error

Respond converts a Go value to JSON and sends it to the client.

Types

type CreateURLDTO

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

type Handler

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

func NewHandler

func NewHandler(service ports.ShortenerService, log *logger.Logger) *Handler

func (*Handler) Create

func (h *Handler) Create(w http.ResponseWriter, r *http.Request)

Create handler validate request, create new short url and respond it

func (*Handler) Delete

func (h *Handler) Delete(w http.ResponseWriter, r *http.Request)

Delete handler validate request and delete short url value

func (*Handler) Find

func (h *Handler) Find(w http.ResponseWriter, r *http.Request)

Find handler vaдidate request, finds and redirects to long url

type ResponseCreateDTO

type ResponseCreateDTO struct {
	ShortURL string `json:"short_url"`
}

type ResponseMessage

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

func NewResponse

func NewResponse(message string) ResponseMessage

Jump to

Keyboard shortcuts

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