Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateRequestSize(request *http.Request) int64
- func PanicHandler(response http.ResponseWriter, _ *http.Request, err interface{})
- func ReadClientIPAddress(request *http.Request, customHeader string) string
- func ReadHeader(request *http.Request, canonicalHeaderName string) string
- func WriteError(response http.ResponseWriter, err error, statusCode int)
- func WriteErrorMessage(response http.ResponseWriter, message string, statusCode int)
- func WriteHeader(request *http.Request, canonicalHeaderName string, value string)
- func WriteJSON(contents interface{}, response http.ResponseWriter)
- func WritePrettyJSON(contents interface{}, response http.ResponseWriter)
- func WriteRequest(response http.ResponseWriter, request *http.Request, message string, ...)
- func WriteResponse(response http.ResponseWriter, err error)
- func WriteResult(response http.ResponseWriter, statusCode int)
- type HTTPServer
- func (this *HTTPServer) Close()
- func (this *HTTPServer) Listen()
- func (this *HTTPServer) Shutdown(timeout time.Duration) error
- func (this *HTTPServer) WithTLS(certificatePEM string, tlsConfig *tls.Config) *HTTPServer
- func (this *HTTPServer) WithTLSFiles(cert, key string, tlsConfig *tls.Config) *HTTPServer
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAuthorization = "Authorization" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderHost = "Host" HeaderOrigin = "Origin" HeaderReferer = "Referer" HeaderUserAgent = "User-Agent" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlMaxAgeSeconds = "Access-Control-Max-Age" HeaderXForwardedFor = "X-Forwarded-For" )
View Source
const ( ContentTypeOctetStream = "application/octet-stream" ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" )
View Source
const ( ContentTypeHeader = "Content-Type" MIMEApplicationJSON = "application/json; charset=utf-8" MIMETextPlain = "text/plain; charset=utf-8" )
Variables ¶
View Source
var ( DefaultCORSMethods = strings.Join([]string{ http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete, http.MethodHead, }, ", ") DefaultCORSHeaders = strings.Join([]string{ HeaderAccept, HeaderAuthorization, HeaderContentLength, HeaderContentType, HeaderHost, HeaderOrigin, HeaderReferer, }, ", ") )
View Source
var DefaultShutdownTimeout = time.Second
Functions ¶
func CalculateRequestSize ¶
func PanicHandler ¶
func PanicHandler(response http.ResponseWriter, _ *http.Request, err interface{})
func ReadClientIPAddress ¶
func WriteError ¶
func WriteError(response http.ResponseWriter, err error, statusCode int)
func WriteErrorMessage ¶
func WriteErrorMessage(response http.ResponseWriter, message string, statusCode int)
func WriteHeader ¶
func WriteJSON ¶
func WriteJSON(contents interface{}, response http.ResponseWriter)
func WritePrettyJSON ¶
func WritePrettyJSON(contents interface{}, response http.ResponseWriter)
func WriteRequest ¶
func WriteResponse ¶
func WriteResponse(response http.ResponseWriter, err error)
func WriteResult ¶
func WriteResult(response http.ResponseWriter, statusCode int)
Types ¶
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer(listenAddress string, handler http.Handler) *HTTPServer
func (*HTTPServer) Close ¶
func (this *HTTPServer) Close()
func (*HTTPServer) Listen ¶
func (this *HTTPServer) Listen()
func (*HTTPServer) WithTLS ¶
func (this *HTTPServer) WithTLS(certificatePEM string, tlsConfig *tls.Config) *HTTPServer
func (*HTTPServer) WithTLSFiles ¶
func (this *HTTPServer) WithTLSFiles(cert, key string, tlsConfig *tls.Config) *HTTPServer
Source Files ¶
Click to show internal directories.
Click to hide internal directories.