Documentation ¶
Index ¶
- Constants
- func Bind(req *http.Request, value interface{}) (err error)
- func DecodeJson(src io.Reader, value interface{}) error
- func DecodeXml(src io.Reader, value interface{}) error
- func DecodeYaml(src io.Reader, value interface{}) error
- func RespondWith(w http.ResponseWriter, statusCode int, contentType string, data interface{}) (n int, err error)
- func RespondWithHtml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
- func RespondWithJson(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
- func RespondWithText(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
- func RespondWithXml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
- func RespondWithYaml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
- func StaticHandlerFunc(content []byte, statusCode int, headers map[string]string) http.HandlerFunc
- type AssetProvider
- type FsServer
- type Json
- type Marshaller
- type MiddlewareFunc
- type StaticHttpHandler
- type WebServer
- type WebServerOptions
Constants ¶
const ( MimeHtml = "text/html" MimeJavascript = "application/javascript" // Should only be used as a response content-type. MimeJson = "application/json" MimePlain = "text/plain" MimePostForm = "application/x-www-form-urlencoded" MimeXml = "application/xml" MimeXml2 = "text/xml" MimeYaml = "application/x-yaml" MimeYaml2 = "text/yaml" MimeYaml3 = "text/x-yaml" )
Mime-types.
const MaxStopChecks = 10
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
Bind automatically deserializes the request body into the specified value.
`value` must be a pointer to the value to be deserialized.
The decoder is automatically selected based on the "Content-Type" header in the request.
Currently supported content types are:
- JSON
- XML
- YAML
func DecodeJson ¶
func DecodeYaml ¶
func RespondWith ¶
func RespondWith(w http.ResponseWriter, statusCode int, contentType string, data interface{}) (n int, err error)
RespondWith tries to detect what kind of data is being sent and serializes it when appropriate, e.g. transmitting a struct, ptr, etc.
func RespondWithHtml ¶
func RespondWithHtml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
func RespondWithJson ¶
func RespondWithJson(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
func RespondWithText ¶
func RespondWithText(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
func RespondWithXml ¶
func RespondWithXml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
func RespondWithYaml ¶
func RespondWithYaml(w http.ResponseWriter, statusCode int, data interface{}) (int, error)
func StaticHandlerFunc ¶
StaticHandlerFunc generates a handler which always serves up the same thing regardless of the request.
Types ¶
type AssetProvider ¶
AssetProvider defines the function signature for a StaticFilesMiddleware asset looker-upper.
While a default implementation of disk-based AssetProvider is provided, tools such as go-bindata can also be easily used.
func DiskBasedAssetProvider ¶
func DiskBasedAssetProvider(basePath string) AssetProvider
type FsServer ¶
type FsServer struct {
// contains filtered or unexported fields
}
FsServer is a filesystem server.
type Marshaller ¶
func MarshallerFor ¶
func MarshallerFor(contentType string) (m Marshaller, err error)
type MiddlewareFunc ¶
MiddlewareFunc defines the function signature for middleware functions.
func StaticFilesMiddleware ¶
func StaticFilesMiddleware(assetProvider AssetProvider) MiddlewareFunc
StaticFilesMiddleware generates a middleware function for serving static files from the specified asset provider.
type StaticHttpHandler ¶
type WebServer ¶
type WebServer struct { Options WebServerOptions // contains filtered or unexported fields }
func NewStaticWebServer ¶
func NewStaticWebServer(options WebServerOptions, content []byte, statusCode int, headers map[string]string) *WebServer
NewStaticWebServer creates a WebServer which always serves the same content.
func NewWebServer ¶
func NewWebServer(options WebServerOptions) *WebServer
NewWebServer creates a basic stoppable WebServer.
type WebServerOptions ¶
type WebServerOptions struct { Addr string // TCP address to listen on, ":http" if empty. Handler http.Handler // handler to invoke, http.DefaultServeMux if nil. ReadTimeout time.Duration // maximum duration before timing out read of the request. WriteTimeout time.Duration // maximum duration before timing out write of the response. MaxHeaderBytes int // maximum size of request headers, net/http.DefaultMaxHeaderBytes if 0. TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS. ErrorLog *golog.Logger }