web

package
v0.0.0-...-142f600 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON   = "application/json"
	YAML   = "application/yaml"
	XML    = "application/xml"
	JS     = "application/js"
	TEXT   = "text/plain"
	HTML   = "text/html"
	BINARY = "application/octet-stream"
)

Variables

View Source
var DefaultContentType = TEXT

DefaultContentType defines the default content-type for a new response

View Source
var ObjectDataType = JSON

ObjectDataType defines the default content-type for a rich object

Functions

func GetRecommendedContentType

func GetRecommendedContentType(data interface{}) string

GetRecommendedContentType for the given interface

Types

type ErrorResponse

type ErrorResponse struct {
	Error string
}

type Response

type Response struct {
	StatusCode int
	Headers    map[string]string
	// contains filtered or unexported fields
}

func EmptyResponse

func EmptyResponse() Response

Creates a new blank response

func NewErrorResponse

func NewErrorResponse(statusCode int, err error) Response

Create a new error response

func NewResponse

func NewResponse(statusCode int, data interface{}) Response

Creates a basic response

func (*Response) SetContentType

func (response *Response) SetContentType(contentType string)

SetContentType sets the content type from the request, normally text/plain.

func (*Response) SetContentTypeFromRequest

func (response *Response) SetContentTypeFromRequest(r *http.Request) string

SetContentTypeFromRequest reads the `content-type` header from the request and uses that for the response. Returns the new content type.

func (*Response) SetData

func (response *Response) SetData(data interface{})

Sets the data of the response

func (*Response) Write

func (response *Response) Write(w http.ResponseWriter) error

Writes the response to the response writer

Jump to

Keyboard shortcuts

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