Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidLogLayout = errors.New("Invalid log layout")
Functions ¶
func ErrorEx ¶
func ErrorEx(w http.ResponseWriter, code int, title, msg string) int64
Write http error, accrording status code and msg, return number of bytes write to ResponseWriter. Parameter msg is a string contains html, could be ignored.
func ErrorFile404 ¶
func ErrorFile404(w http.ResponseWriter, abspath string) (int64, error)
Write 404 file to client. abspath is path of 404 file.
Types ¶
type Auth ¶
type Auth struct { Username string Password string // paths which use password to protect, relative to "/". // if Paths is empty, all paths are protected. // not used currently Paths []string Method AuthMethod }
type AuthMethod ¶
type AuthMethod string
const BasicMethod AuthMethod = "basic"
const DigestMethod AuthMethod = "digest"
type Config ¶
type Config struct { Root string // Root path of the website. Default is current working directory. Path404 *string // Abspath of custom 404 file, under directory of Root. // When a 404 not found error occurs, the file's content will be send to client. // nil means do not use 404 file. Path401 *string // Abspath of custom 401 file, under directory of Root. // When a 401 unauthorized error occurs, the file's content will be send to client. // nil means do not use 401 file. IndexName Index // File name of index, priority depends on the order of values. // Default is []string{"index.html", "index.htm"}. ListDir bool // If no index file provide, show file list of the directory. // Default is false. Gzip bool // If turn on gzip compression, default is true. NoCache bool // If true, ran will write some no-cache headers to the response. Default is false. CORS bool // If true, ran will write some CORS headers to the response. Default is false. Auth *Auth // If not nil, turn on authentication. ServeAll bool // If is false, path start with dot will not be served, that means a 404 error will be returned. }
type LogLayout ¶
type LogLayout string
LogLayout indicate what information will be present in access log. LogLayout is a string contains format specifiers. The format specifiers is a tag start with a percent sign and followd by a letter. The format specifiers will be replaced by corresponding values when the log is created.
Below are format specifiers and there meanings:
%% Percent sign (%) %i Request id %s Response status code %h Host %a Client ip address %m Request method %l Request url %r Referer %u User agent %n Number of bytes transferred %t Response time %c Compression status (gzip / none) %S Scheme (http or https)
var LogLayoutMin LogLayout = `Access #%i: [%s] [%a] [%m] [%l] [%n]`
var LogLayoutNormal LogLayout = `` /* 143-byte string literal not displayed */
var LogLayoutShort LogLayout = `Access #%i: [%s] [%h] [%a] [%m] [%S] [%l] [%r] [%u] [%n] [%t] [%c]`
type RanServer ¶
type RanServer struct {
// contains filtered or unexported fields
}
func (*RanServer) RedirectToHTTPS ¶
func (this *RanServer) RedirectToHTTPS(port uint) http.HandlerFunc
redirect to https page
func (*RanServer) Serve ¶
func (this *RanServer) Serve() http.HandlerFunc
make the request handler chain: log -> authentication -> gzip -> original handler TODO: add ip filter: log -> [ip filter] -> authentication -> gzip -> original handler