Documentation
¶
Index ¶
- func Error(ctx context.Context, writer http.ResponseWriter, err error)
- func NewRouter(h *Handler) *mux.Router
- func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)
- func RespondError(ctx context.Context, writer http.ResponseWriter, err error, code int)
- func RespondHTML(writer http.ResponseWriter, title string, body string, code int)
- func Start()
- type Endpoint
- type Handler
- type HandlerFunc
- type ResponseError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(ctx context.Context, writer http.ResponseWriter, err error)
Error handles all error responses for the API.
func Respond ¶
func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)
Respond sends JSON response.
func RespondError ¶
RespondError sends JSON describing the error
func RespondHTML ¶
func RespondHTML(writer http.ResponseWriter, title string, body string, code int)
RespondHTML sends HTML response.
Types ¶
type Endpoint ¶
type Endpoint struct {
Name string
Method string
Pattern string
HandlerFunc HandlerFunc
}
Endpoint defines an http endpoint to be queried from an external source
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the main struct to reference when calling the handling methods
type HandlerFunc ¶
HandlerFunc is a type that handles a http request
func (HandlerFunc) ServeHTTP ¶
func (fn HandlerFunc) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP needed in http.Handler implemented functions
type ResponseError ¶
type ResponseError struct {
Error string `json:"error"`
}
ResponseError is an error placeholder to be converted to JSON
Click to show internal directories.
Click to hide internal directories.