res: go.bobheadxi.dev/res/base Index | Files

package base

import "go.bobheadxi.dev/res/base"

Index

Package Files

base.go

type Response Uses

type Response struct {
    // Basic metadata
    HTTPStatusCode int    `json:"code"`
    RequestID      string `json:"request_id,omitempty"`

    // Message is included in all responses, and is a summary of the server's response
    Message string `json:"message"`

    // Err contains additional context in the event of an error
    Err string `json:"error,omitempty"`

    // Data contains information the server wants to return
    Data interface{} `json:"data,omitempty"`
}

Response is the underlying response structure to all responses.

func NewResponse Uses

func NewResponse(
    message string,
    code int,
    kvs []interface{},
) *Response

NewResponse creates an instance of the standard basic response renderer

func (*Response) Error Uses

func (b *Response) Error() error

Error returns a summary of an encountered error. For more details, you may want to interrogate Data. Returns nil if StatusCode is not an HTTP error code, ie if the code is in 1xx, 2xx, or 3xx

func (*Response) Render Uses

func (b *Response) Render(w http.ResponseWriter, r *http.Request) error

Render implements chi's render.Renderer

Package base imports 4 packages (graph) and is imported by 2 packages. Updated 2019-08-13. Refresh now. Tools for package owners.