handler

package
v0.0.0-...-68c1abf Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 13 Imported by: 0

README

handler

-- import "github.com/rickbassham/example-go/chiapi/handler"

Package handler implements the request handlers for the API.

Usage

type Handler
type Handler struct {
}

Handler has all the functions needed to serve our api.

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

Health always returns a 200 response.

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

NotFound is called when the request is for an unknown resource.

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

Protected is a protected endpoint example.

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

Unauthorized is called when the request is not authorized.

type SimpleResponse
type SimpleResponse struct {
	XMLName xml.Name `json:"-" xml:"simpleResponse"`
	TraceID string   `json:"trace_id" xml:"traceId,attr"`
	Message string   `json:"message" xml:",innerxml"`
}

SimpleResponse is used to send a meaningful message back to the caller, with trace id to debug later.

Documentation

Overview

Package handler implements the request handlers for the API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	GetValue(ctx context.Context) (string, error)
}

Cache defines the funcs needed to get stuff from redis.

type Handler

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

Handler has all the functions needed to serve our api.

func New

func New(c Cache) *Handler

New creates a new handler.

func (*Handler) Cached

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

Cached gets a value from redis and writes it to the response.

func (*Handler) Health

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

Health always returns a 200 response.

func (*Handler) NotFound

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

NotFound is called when the request is for an unknown resource.

func (*Handler) Protected

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

Protected is a protected endpoint example.

func (*Handler) Unauthorized

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

Unauthorized is called when the request is not authorized.

type SimpleResponse

type SimpleResponse struct {
	XMLName xml.Name `json:"-" xml:"simpleResponse"`
	TraceID string   `json:"trace_id" xml:"traceId,attr"`
	Message string   `json:"message" xml:",innerxml"`
}

SimpleResponse is used to send a meaningful message back to the caller, with trace id to debug later.

Jump to

Keyboard shortcuts

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