Documentation
¶
Index ¶
- Constants
- Variables
- func AllowCredentials(w http.ResponseWriter)
- func AllowHeaders(w http.ResponseWriter, Headers ...string)
- func AllowMethods(w http.ResponseWriter, Methods ...string)
- func AllowOrigin(w http.ResponseWriter, value string)
- func AllowOriginAll(w http.ResponseWriter)
- func Body(w http.ResponseWriter, r *http.Request, body []byte, code int) (int, error)
- func CheckAcceptEncoding(r *http.Request, compressType string) bool
- func Deflate(w http.ResponseWriter, r *http.Request, body []byte, code int) (int, error)
- func DelHeader(w http.ResponseWriter, key string)
- func Execute(w http.ResponseWriter, r *http.Request, text string, data interface{}, ...) (int, error)
- func File(w http.ResponseWriter, r *http.Request, name string, code int) (int, error)
- func FreeBufioReader(br *bufio.Reader)
- func FreeBufioWriter(bw *bufio.Writer)
- func FreeRequest(r *http.Request)
- func FreeResponse(w http.ResponseWriter)
- func GetRequestHeader(r *http.Request, key string) (value string)
- func GetResponseHeader(w http.ResponseWriter, key string) (value string)
- func Gzip(w http.ResponseWriter, r *http.Request, body []byte, code int) (int, error)
- func IpTo4(addr string) uint32
- func JSON(w http.ResponseWriter, r *http.Request, v interface{}, code int) (int, error)
- func ListenAndServe(addr string, handler http.Handler) error
- func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error
- func MaxAge(w http.ResponseWriter, age int)
- func NewBufioReader(r io.Reader) *bufio.Reader
- func NewBufioWriter(w io.Writer) *bufio.Writer
- func NewBufioWriterSize(w io.Writer, size int) *bufio.Writer
- func Proxy(w http.ResponseWriter, r *http.Request, targetUrl string)
- func ReadFastRequest(b *bufio.Reader) (*http.Request, error)
- func ReadRequest(b *bufio.Reader) (*http.Request, error)
- func Redirect(w http.ResponseWriter, r *http.Request, url string)
- func RemoteAddr(req *http.Request) (addr string)
- func RunUnix(file string) error
- func ServeFile(w http.ResponseWriter, r *http.Request, name string)
- func SetCharset(w http.ResponseWriter, charset string)
- func SetContentEncoding(w http.ResponseWriter, compressType string)
- func SetContentLength(w http.ResponseWriter, length int)
- func SetContentType(w http.ResponseWriter, value string)
- func SetContentTypeWithCharset(w http.ResponseWriter, value string, charset string)
- func SetHeader(w http.ResponseWriter, key, value string)
- func Text(w http.ResponseWriter, r *http.Request, text string, code int) (int, error)
- func WriteHeader(w http.ResponseWriter, code int)
- func XML(w http.ResponseWriter, r *http.Request, v interface{}, code int) (int, error)
- func Zlib(w http.ResponseWriter, r *http.Request, body []byte, code int) (int, error)
- type CompressWriter
- type Compressor
- type Render
- func (render *Render) Body(w http.ResponseWriter, r *http.Request, body []byte, code int) (int, error)
- func (render *Render) Charset(charset string) *Render
- func (render *Render) DeflateAll() *Render
- func (render *Render) Execute(w http.ResponseWriter, r *http.Request, data interface{}, code int) (int, error)
- func (render *Render) ExecuteTemplate(w http.ResponseWriter, r *http.Request, name string, data interface{}, ...) (int, error)
- func (render *Render) File(w http.ResponseWriter, r *http.Request, name string, code int) (int, error)
- func (render *Render) GzipAll() *Render
- func (render *Render) JSON(w http.ResponseWriter, r *http.Request, v interface{}, code int) (int, error)
- func (render *Render) Parse(text string) error
- func (render *Render) ParseTemplate(name, text string) error
- func (render *Render) Redirect(w http.ResponseWriter, r *http.Request, url string)
- func (render *Render) ServeFile(w http.ResponseWriter, r *http.Request, name string)
- func (render *Render) Text(w http.ResponseWriter, r *http.Request, text string, code int) (int, error)
- func (render *Render) XML(w http.ResponseWriter, r *http.Request, v interface{}, code int) (int, error)
- type Response
- type Route
- func (m *Route) Close() error
- func (m *Route) Run(addr string) error
- func (m *Route) RunTLS(addr string, certFile, keyFile string) error
- func (m *Route) Serve(l net.Listener) error
- func (m *Route) ServeTLS(l net.Listener, certFile, keyFile string) error
- func (m *Route) SetFast(fast bool)
- func (m *Route) SetPoll(poll bool)
- type Tmpl
- func (t *Tmpl) Execute(w http.ResponseWriter, r *http.Request, data interface{}, code int) (int, error)
- func (t *Tmpl) ExecuteTemplate(w http.ResponseWriter, r *http.Request, name string, data interface{}, ...) (int, error)
- func (t *Tmpl) Parse(text string) error
- func (t *Tmpl) ParseFiles(filenames ...string) error
- func (t *Tmpl) ParseTemplate(name, text string) error
Constants ¶
const ( ContentEncoding = "Content-Encoding" ContentLanguage = "Content-Language" ContentLength = "Content-Length" ContentLocation = "Content-Location" ContentMD5 = "Content-MD5" ContentRange = "Content-Range" ContentType = "Content-Type" AcceptRanges = "Accept-Ranges" Bytes = "bytes" AcceptEncoding = "Accept-Encoding" GZIP = "gzip" DEFLATE = "deflate" Vary = "Vary" Charset = "charset" CharsetPrefix = "charset=" UTF8 = "UTF-8" GB18030 = "GB18030" GBK = "GBK" Semicolon = ";" Comma = "," ContentTypeJSON = "application/json" ContentTypeXML = "text/xml" ContentTypeHTML = "text/html" ContentTypeText = "text/plain" AccessControlAllowOrigin = "Access-Control-Allow-Origin" AccessControlAllowCredentials = "Access-Control-Allow-Credentials" AccessControlMaxAge = "Access-Control-Max-Age" AccessControlAllowMethods = "Access-Control-Allow-Methods" AccessControlAllowHeaders = "Access-Control-Allow-Headers" )
const ( XRealIP = "X-Real-IP" XForwardedFor = "X-Forwarded-For" )
const MaxConnPerHost = 16384
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
TimeFormat is the time format to use when generating times in HTTP headers. It is like time.RFC1123 but hard-codes GMT as the time zone. The time being formatted must be in UTC for Format to generate the correct format.
For parsing this time format, see ParseTime.
Variables ¶
var DefaultServer = NewRoute()
DefaultServer is the default HTTP server.
Functions ¶
func AllowCredentials ¶
func AllowCredentials(w http.ResponseWriter)
func AllowHeaders ¶
func AllowHeaders(w http.ResponseWriter, Headers ...string)
func AllowMethods ¶
func AllowMethods(w http.ResponseWriter, Methods ...string)
func AllowOrigin ¶
func AllowOrigin(w http.ResponseWriter, value string)
func AllowOriginAll ¶
func AllowOriginAll(w http.ResponseWriter)
func DelHeader ¶
func DelHeader(w http.ResponseWriter, key string)
DelHeader delete a response header
func FreeBufioReader ¶
FreeBufioReader frees the bufio.Reader.
func FreeBufioWriter ¶
FreeBufioWriter frees the bufio.Writer.
func GetRequestHeader ¶
GetRequestHeader get a request header
func GetResponseHeader ¶
func GetResponseHeader(w http.ResponseWriter, key string) (value string)
GetResponseHeader get response a header
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.
The handler is typically nil, in which case the DefaultServeMux is used.
ListenAndServe always returns a non-nil error.
func ListenAndServeTLS ¶
ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
func MaxAge ¶
func MaxAge(w http.ResponseWriter, age int)
func NewBufioReader ¶
NewBufioReader returns a new bufio.Reader with r.
func NewBufioWriter ¶
NewBufioWriter returns a new bufio.Writer with w.
func NewBufioWriterSize ¶
NewBufioWriterSize returns a new bufio.Writer with w and size.
func ReadFastRequest ¶
ReadFastRequest is like ReadRequest but with the simple request parser.
func ReadRequest ¶
ReadRequest reads and parses an incoming request from b.
ReadRequest is a low-level function and should only be used for specialized applications; most code should use the Server to read requests and handle them via the Handler interface. ReadRequest only supports HTTP/1.x requests.
func RemoteAddr ¶
func SetCharset ¶
func SetCharset(w http.ResponseWriter, charset string)
func SetContentEncoding ¶
func SetContentEncoding(w http.ResponseWriter, compressType string)
func SetContentLength ¶
func SetContentLength(w http.ResponseWriter, length int)
func SetContentType ¶
func SetContentType(w http.ResponseWriter, value string)
func SetContentTypeWithCharset ¶
func SetContentTypeWithCharset(w http.ResponseWriter, value string, charset string)
func SetHeader ¶
func SetHeader(w http.ResponseWriter, key, value string)
SetHeader set a response header
func WriteHeader ¶
func WriteHeader(w http.ResponseWriter, code int)
WriteHeader write a response header
Types ¶
type CompressWriter ¶
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
func NewDeflateWriter ¶
func NewDeflateWriter(w http.ResponseWriter, r *http.Request) *Compressor
func NewGzipWriter ¶
func NewGzipWriter(w http.ResponseWriter, r *http.Request) *Compressor
func NewZlibWriter ¶
func NewZlibWriter(w http.ResponseWriter, r *http.Request) *Compressor
type Render ¶
type Render struct {
// contains filtered or unexported fields
}
var DefaultRender *Render
func (*Render) DeflateAll ¶
func (*Render) ExecuteTemplate ¶
func (*Render) ParseTemplate ¶
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response implements the http.ResponseWriter interface.
func NewResponse ¶
NewResponse returns a new response.
func NewResponseSize ¶
NewResponseSize returns a new response whose buffer has at least the specified size.
func (*Response) FinishRequest ¶
func (w *Response) FinishRequest()
FinishRequest finishes a request.
func (*Response) Flush ¶
func (w *Response) Flush()
Flush implements the http.Flusher interface.
Flush writes any buffered data to the underlying connection.
func (*Response) Hijack ¶
Hijack implements the http.Hijacker interface.
Hijack lets the caller take over the connection. After a call to Hijack the HTTP server library will not do anything else with the connection.
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with the provided status code.
type Route ¶
type Route struct { *mux.Router Handler http.Handler // TLSConfig optionally provides a TLS configuration for use // by ServeTLS and ListenAndServeTLS. Note that this value is // cloned by ServeTLS and ListenAndServeTLS, so it's not // possible to modify the configuration with methods like // tls.Config.SetSessionTicketKeys. To use // SetSessionTicketKeys, use Server.Serve with a TLS Listener // instead. TLSConfig *tls.Config // contains filtered or unexported fields }
Route is an HTTP server.
func (*Route) Run ¶ added in v0.0.5
Run listens on the TCP network address addr and then calls Serve with m to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.
Run always returns a non-nil error.
func (*Route) Serve ¶ added in v0.0.5
Serve accepts incoming connections on the Listener l, creating a new service goroutine for each, or registering the conn fd to poll that will trigger the fd to read requests and then call handler to reply to them.
func (*Route) ServeTLS ¶ added in v0.0.5
ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines perform TLS setup and then read requests, calling srv.Handler to reply to them.
Files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
ServeTLS always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.
type Tmpl ¶
type Tmpl struct {
// contains filtered or unexported fields
}