http

package
v0.0.0-...-b1bd15b Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authorize

func Authorize(serviceKey string) (mw func(basehttp.Handler) basehttp.Handler)

Authorize is middleware to ensure security

func GetResponseWriter

func GetResponseWriter(w interface{}) basehttp.ResponseWriter

func Respond

func Respond(w nh.ResponseWriter, r *nh.Request, statusCode int, response interface{})

Respond is used to return data to the client with a custom http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).

func RespondError

func RespondError(w nh.ResponseWriter, r *nh.Request, statusCode int, detail ...interface{})

RespondError is used to return errors to the client The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths). Be careful in here not to recurse (by calling RespondError() again) when there is an error. For the detail parameter, only error, string and RespondErrorDetail types are useful.

func RespondOk

func RespondOk(w nh.ResponseWriter, r *nh.Request, response interface{})

RespondOk is used to return data to the client with a 200 http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).

func SetHTMLTemplatePaths

func SetHTMLTemplatePaths(applicationHTML, textHTML string)

SetHTMLTemplatePaths allows the application to specify the paths to HTML tempate files that will be used for responses with HTML content-types. If a template path is empty, it will not be used and the default content-type (application/json) will be used instead. Template paths are empty by default.

func StartServer

func StartServer(srv *base_http.Server)

Types

type RespondErrorDetail

type RespondErrorDetail string

RespondErrorDetail allows a RespondError detail parameter to end up in the Details array

type ResponseError

type ResponseError struct {
	StatusCode    int      `json:"status_code"`
	Message       string   `json:"message"`
	Documentation string   `json:"documentation"`
	Details       []string `json:"details,omitempty"`
}

ResponseError structure holds standard fields for errors. Public so that when two of our own applications communicate; one can parse the error received from the other.

type Router

type Router struct {
	*mux.Router
}

Simple cover for the mux router, saves another import at the service level

func New

func New() *Router

function New is just your normal new function for a HTTP router, this allows the calling applicaiton to add routes specific to that microservice

Jump to

Keyboard shortcuts

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