Documentation ¶
Overview ¶
Package middleware is the middlewares of takanawa.
Index ¶
- Variables
- func AccessLog(opt *AccessLogOptions) takanawa.Middleware
- func ChangeOrigin(host string) takanawa.Middleware
- func Cors(opt *CorsOption) takanawa.Middleware
- func RequestID() takanawa.Middleware
- func ReverseProxy(target *url.URL) takanawa.Middleware
- func StripPrefix(prefix string) takanawa.Middleware
- type AccessLogFormat
- type AccessLogOptions
- type CorsOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // CommonLogFormat formats access logs according to the // Apache's Common Log Format. // // Common Log Format: https://httpd.apache.org/docs/2.4/en/logs.html#common CommonLogFormat = func(t *time.Time, w *util.ResponseSniffer, r *http.Request) string { remoteAddr := strings.SplitN(r.RemoteAddr, ":", 2) return fmt.Sprintf( "%s - - [%s] \"%s %s %s\" %d %d", remoteAddr[0], t.Format("02/Jan/2006:15:04:05 -0700"), r.Method, r.RequestURI, r.Proto, w.StatusCode, w.Length, ) } // CombinedLogFormat formats access logs according to the // Apache's Combined Log Format. // // Combined Log Format: https://httpd.apache.org/docs/2.4/en/logs.html#combined CombinedLogFormat = func(t *time.Time, w *util.ResponseSniffer, r *http.Request) string { referer := r.Referer() if len(referer) == 0 { referer = "-" } userAgent := r.UserAgent() if len(userAgent) == 0 { userAgent = "-" } return CommonLogFormat(t, w, r) + fmt.Sprintf(" \"%s\" \"%s\"", referer, userAgent) } )
View Source
var ( // DefaultAccessLogOptions is used by AccessLog as default options. DefaultAccessLogOptions = AccessLogOptions{ Logger: log.New(ioutil.Discard, "", 0), Format: CommonLogFormat, } )
Functions ¶
func AccessLog ¶
func AccessLog(opt *AccessLogOptions) takanawa.Middleware
AccessLog returns the middleware.
func ChangeOrigin ¶
func ChangeOrigin(host string) takanawa.Middleware
ChangeOrigin changes the Host request header.
func ReverseProxy ¶
func ReverseProxy(target *url.URL) takanawa.Middleware
ReverseProxy returns the middleware that invokes httputil.ReverseProxy.
func StripPrefix ¶
func StripPrefix(prefix string) takanawa.Middleware
StripPrefix returns a middleware that invokes http.StripPrefix(prefix, handler).
Types ¶
type AccessLogFormat ¶
AccessLogFormat formats access logs.
type AccessLogOptions ¶
type AccessLogOptions struct { Logger *log.Logger Format AccessLogFormat }
AccessLogOptions is options of AccessLog.
type CorsOption ¶
type CorsOption struct { takanawa.MiddlewareFunc AllowedOrigins []string AllowedMethods []string AllowedHeaders []string ExposedHeaders []string AllowCredentials bool }
CorsOption is options of Cors.
Click to show internal directories.
Click to hide internal directories.