handler

package
v0.0.0-...-c6b0d7e Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 13 Imported by: 0

README

handler

This package contains handler that handle http request for each endpoints. Every handler should be simple and light, it's should only responsible for decoding request, calling business service, and encoding the response.

It's recommended to avoid implementing any business logic directly in handler, including writes to the database. Even if the logic seems simple at the beginning, implementing the logic directly in the handler might trigger tech-debt when additional requirement comes and other engineer just added the implementation directly in handler without moving it to a specific service.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrBadRequest error.
	ErrBadRequest = errors.New("Bad Request")
)

Functions

This section is empty.

Types

type Healthz

type Healthz struct {
	*chi.Mux
	// contains filtered or unexported fields
}

Healthz handler.

func NewHealthz

func NewHealthz() Healthz

NewHealthz handler.

func (*Healthz) Add

func (h *Healthz) Add(name string, ping Pinger)

Add a pinger.

func (Healthz) Show

func (h Healthz) Show(w http.ResponseWriter, r *http.Request)

Show handle GET /

type Pinger

type Pinger interface {
	Ping(ctx context.Context) error
}

Pinger interface.

type Score

type Score struct {
	*chi.Mux
	// contains filtered or unexported fields
}

Score for score endpoints.

func NewScore

func NewScore(repository rel.Repository) Score

NewScore handler.

func (Score) Index

func (s Score) Index(w http.ResponseWriter, r *http.Request)

Index handle GET /

func (Score) Points

func (s Score) Points(w http.ResponseWriter, r *http.Request)

Points handle Get /points

type Todos

type Todos struct {
	*chi.Mux
	// contains filtered or unexported fields
}

Todos for todos endpoints.

func NewTodos

func NewTodos(repository rel.Repository, todos todos.Service) Todos

NewTodos handler.

func (Todos) Clear

func (t Todos) Clear(w http.ResponseWriter, r *http.Request)

Clear handle DELETE /

func (Todos) Create

func (t Todos) Create(w http.ResponseWriter, r *http.Request)

Create handle POST /

func (Todos) Destroy

func (t Todos) Destroy(w http.ResponseWriter, r *http.Request)

Destroy handle DELETE /{ID}

func (Todos) Index

func (t Todos) Index(w http.ResponseWriter, r *http.Request)

Index handle GET /.

func (Todos) Load

func (t Todos) Load(next http.Handler) http.Handler

Load is middleware that loads todos to context.

func (Todos) Show

func (t Todos) Show(w http.ResponseWriter, r *http.Request)

Show handle GET /{ID}

func (Todos) Update

func (t Todos) Update(w http.ResponseWriter, r *http.Request)

Update handle PATCH /{ID}

Jump to

Keyboard shortcuts

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