mhandler

package
v0.0.0-...-bb39121 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const HTML_TMPL = `` /* 218-byte string literal not displayed */

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found"}
View Source
var OK = &ErrResponse{HTTPStatusCode: 200, StatusText: "OK"}

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func SetLogger

func SetLogger(log zerolog.Logger) optionFunc

func SetStore

func SetStore(store domain.Store) optionFunc

Types

type DataSetPayload

type DataSetPayload struct {
	domain.DataSet
}

this only allows for a single dataset - probably fine for MVP?

func (*DataSetPayload) Bind

func (d *DataSetPayload) Bind(r *http.Request) (err error)

Binders are used on requests

func (*DataSetPayload) Render

Renders are used on responses.

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.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

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

type MetricPayload

type MetricPayload struct {
	domain.Metric
}

Request types should be render.Binder

func (*MetricPayload) Bind

func (m *MetricPayload) Bind(r *http.Request) (err error)

Binders are used on requests. This will run after unmarshalling is complete - a good time to focus some post-processing after a decoding.

func (*MetricPayload) Render

Renders are used on responses.

type Service

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

func NewService

func NewService(optionFuncs ...optionFunc) *Service

func (*Service) AddData

func (s *Service) AddData(w http.ResponseWriter, r *http.Request)

func (*Service) CreateMetric

func (s *Service) CreateMetric(w http.ResponseWriter, r *http.Request)

func (*Service) GetMetric

func (s *Service) GetMetric(w http.ResponseWriter, r *http.Request)

func (*Service) Router

func (s *Service) Router(r chi.Router)

Jump to

Keyboard shortcuts

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