rest

package
v0.0.0-...-de70ca6 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetHandler

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

GetHandler is the HTTP handler for the "Get Person" endpoint In this simplified example we are assuming all possible errors are user errors and returning "bad request" HTTP 400 or "not found" HTTP 404 There are some programmer errors possible but hopefully these will be caught in testing.

func NewGetHandler

func NewGetHandler(model GetModel) *GetHandler

NewGetHandler is the constructor for GetHandler

func (*GetHandler) ServeHTTP

func (h *GetHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP implements http.Handler

type GetModel

type GetModel interface {
	Do(ID int) (*data.Person, error)
}

GetModel will load a registration

type ListHandler

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

ListHandler is the HTTP handler for the "List Do people" endpoint In this simplified example we are assuming all possible errors are system errors (HTTP 500)

func NewListHandler

func NewListHandler(model ListModel) *ListHandler

NewLister is the constructor for ListHandler

func (*ListHandler) ServeHTTP

func (h *ListHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP implements http.Handler

type ListModel

type ListModel interface {
	Do() ([]*data.Person, error)
}

ListModel will load all registrations

type RegisterHandler

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

RegisterHandler is the HTTP handler for the "Register" endpoint In this simplified example we are assuming all possible errors are user errors and returning "bad request" HTTP 400. There are some programmer errors possible but hopefully these will be caught in testing.

func NewRegisterHandler

func NewRegisterHandler(model RegisterModel) *RegisterHandler

NewRegisterHandler is the constructor for RegisterHandler

func (*RegisterHandler) ServeHTTP

func (h *RegisterHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP implements http.Handler

type RegisterModel

type RegisterModel interface {
	Do(ctx context.Context, in *data.Person) (int, error)
}

RegisterModel will validate and save a registration

type Server

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

Server is the HTTP REST server

func New

func New(address string,
	getModel GetModel,
	listModel ListModel,
	registerModel RegisterModel) *Server

New will create and initialize the server

func (*Server) Listen

func (s *Server) Listen(stop <-chan struct{})

Listen will start a HTTP rest for this service

Jump to

Keyboard shortcuts

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