Documentation ¶
Overview ¶
Package jsendx implements a custom JSEND model to wrap HTTP responses in a JSON object with default fields.
Index ¶
- func DefaultIPHandler(info *AppInfo, fn httpserver.GetPublicIPFunc) http.HandlerFunc
- func DefaultIndexHandler(info *AppInfo) httpserver.IndexHandlerFunc
- func DefaultMethodNotAllowedHandlerFunc(info *AppInfo) http.HandlerFunc
- func DefaultNotFoundHandlerFunc(info *AppInfo) http.HandlerFunc
- func DefaultPanicHandlerFunc(info *AppInfo) http.HandlerFunc
- func DefaultPingHandler(info *AppInfo) http.HandlerFunc
- func DefaultStatusHandler(info *AppInfo) http.HandlerFunc
- func HealthCheckResultWriter(info *AppInfo) healthcheck.ResultWriter
- func NewRouter(info *AppInfo, instrumentHandler httpserver.InstrumentHandler) *httprouter.Router
- func Send(ctx context.Context, w http.ResponseWriter, statusCode int, info *AppInfo, ...)
- type AppInfo
- type Response
- type RouterArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultIPHandler ¶
func DefaultIPHandler(info *AppInfo, fn httpserver.GetPublicIPFunc) http.HandlerFunc
DefaultIPHandler returns the route ip in JSendX format.
func DefaultIndexHandler ¶
func DefaultIndexHandler(info *AppInfo) httpserver.IndexHandlerFunc
DefaultIndexHandler returns the route index in JSendX format.
func DefaultMethodNotAllowedHandlerFunc ¶
func DefaultMethodNotAllowedHandlerFunc(info *AppInfo) http.HandlerFunc
DefaultMethodNotAllowedHandlerFunc http handler called when a request cannot be routed.
func DefaultNotFoundHandlerFunc ¶
func DefaultNotFoundHandlerFunc(info *AppInfo) http.HandlerFunc
DefaultNotFoundHandlerFunc http handler called when no matching route is found.
func DefaultPanicHandlerFunc ¶
func DefaultPanicHandlerFunc(info *AppInfo) http.HandlerFunc
DefaultPanicHandlerFunc http handler to handle panics recovered from http handlers.
func DefaultPingHandler ¶
func DefaultPingHandler(info *AppInfo) http.HandlerFunc
DefaultPingHandler returns a ping request in JSendX format.
func DefaultStatusHandler ¶
func DefaultStatusHandler(info *AppInfo) http.HandlerFunc
DefaultStatusHandler returns the server status in JSendX format.
func HealthCheckResultWriter ¶
func HealthCheckResultWriter(info *AppInfo) healthcheck.ResultWriter
HealthCheckResultWriter returns a new healthcheck result writer.
func NewRouter ¶
func NewRouter(info *AppInfo, instrumentHandler httpserver.InstrumentHandler) *httprouter.Router
NewRouter is deprecated. Deprecated: Set instead the router error handlers with the following options:
httpserver.WithNotFoundHandlerFunc(jsendx.DefaultNotFoundHandlerFunc(appInfo)) httpserver.WithMethodNotAllowedHandlerFunc(jsendx.DefaultMethodNotAllowedHandlerFunc(appInfo)) httpserver.WithPanicHandlerFunc(jsendx.DefaultPanicHandlerFunc(appInfo))
Types ¶
type Response ¶
type Response struct { // Program is the application name. Program string `json:"program"` // Version is the program semantic version (e.g. 1.2.3). Version string `json:"version"` // Release is the program build number that is appended to the version. Release string `json:"release"` // DateTime is the human-readable date and time when the response is sent. DateTime string `json:"datetime"` // Timestamp is the machine-readable UTC timestamp in nanoseconds since EPOCH. Timestamp int64 `json:"timestamp"` // Status code string (i.e.: error, fail, success). Status httputil.Status `json:"status"` // Code is the HTTP status code number. Code int `json:"code"` // Message is the error or general HTTP status message. Message string `json:"message"` // Data is the content payload. Data interface{} `json:"data"` }
Response wraps data into a JSend compliant response.
type RouterArgs ¶
type RouterArgs struct { // TraceIDHeaderName is the Trace ID header name. TraceIDHeaderName string // RedactFunc is the function used to redact HTTP request and response dumps in the logs. RedactFunc httpserver.RedactFn }
RouterArgs extra arguments for the router.