Documentation ¶
Index ¶
- Constants
- Variables
- func CheckIfMatch(r *http.Request, etag string) *bool
- func CheckIfModifiedSince(r *http.Request, modTime time.Time) *bool
- func CheckIfNoneMatch(r *http.Request, etag string) *bool
- func CheckIfRange(r *http.Request, modTime time.Time, etag string) *bool
- func CheckIfUnmodifiedSince(r *http.Request, modTime time.Time) *bool
- func CheckPreconditions(r *http.Request, modTime time.Time, etag string) error
- func CompressMiddleware(handler http.Handler) http.Handler
- func ContextRequestId(ctx context.Context) string
- func ContextRequestVars(ctx context.Context) map[string]string
- func CopyToFile(src io.Reader, fn string, overwrite bool) (string, error)
- func CreateRequestContext(srv *Server, req *http.Request) *http.Request
- func EnsureDir(fn string) error
- func EnvEval(s string) string
- func ExternalURL(r *http.Request) *url.URL
- func Forwarded(r *http.Request) []map[string]string
- func GenEtag(f io.Reader) string
- func ParseIPNet(netstr string) *net.IPNet
- func Proxy(w http.ResponseWriter, req *http.Request, proxyUrl string)
- func QueryScan(req *http.Request, obj interface{}) error
- func ReadJSON(req *http.Request, target interface{}) error
- func ScanETag(s string) (etag string, remain string)
- func SendJSON(w http.ResponseWriter, obj interface{})
- func ServeWS(hub Hub, w http.ResponseWriter, req *http.Request) (interface{}, error)
- func SetDefaultContentType(w http.ResponseWriter, ct string)
- func ValidateRouter(r Router) error
- type APIError
- type AccountMatcher
- type AuthCfg
- type AuthConfig
- func (cfg *AuthConfig) GetAuthKey() []byte
- func (cfg *AuthConfig) GetTTL() time.Duration
- func (cfg *AuthConfig) Init(serverRoot string) error
- func (cfg *AuthConfig) ReadCookie(req *http.Request) *auth.User
- func (cfg *AuthConfig) ReadHeader(req *http.Request, name string) *auth.User
- func (cfg *AuthConfig) SetCookie(w http.ResponseWriter, user *auth.User)
- type BindConfig
- type Client
- func (c *Client) Close()
- func (c *Client) NextWriter(messageType int) (io.WriteCloser, error)
- func (c *Client) Open(conn *websocket.Conn) error
- func (c *Client) ReadMessage() (int, []byte, error)
- func (c *Client) ReadPump()
- func (c *Client) SetPongHandler(f func(string) error)
- func (c *Client) SetReadDeadline(t time.Time) error
- func (c *Client) SetReadLimit(size int64)
- func (c *Client) SetWriteDeadline(t time.Time) error
- func (c *Client) WriteMessage(messageType int, data []byte) error
- func (c *Client) WritePump()
- type CompressResponseWriter
- func (w *CompressResponseWriter) Close() error
- func (w *CompressResponseWriter) Flush() error
- func (w *CompressResponseWriter) Header() http.Header
- func (w *CompressResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *CompressResponseWriter) Write(data []byte) (int, error)
- func (w *CompressResponseWriter) WriteHeader(statusCode int)
- type Datable
- type ETaggable
- type GenericHub
- type HTTPError
- type HandlerFunc
- type Hub
- type LogConfig
- type Middleware
- type NetCfg
- type NetworkConfig
- type ProxyURL
- type Redirect
- type ResponseLogger
- type Route
- type Router
- type SSLConfig
- type Server
- func (srv *Server) AccessLoggerMiddleware() Middleware
- func (srv *Server) ContextMiddleware() Middleware
- func (srv *Server) DELETE(path string, handler http.Handler)
- func (srv *Server) GET(path string, handler http.Handler)
- func (srv *Server) Handle(method, path string, handler http.Handler)
- func (srv *Server) ListenAndServe() error
- func (srv *Server) OPTIONS(path string, handler http.Handler)
- func (srv *Server) PATCH(path string, handler http.Handler)
- func (srv *Server) POST(path string, handler http.Handler)
- func (srv *Server) PUT(path string, handler http.Handler)
- func (srv *Server) Prefix(path string) Router
- func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (srv *Server) SetDefaultHandler(h http.Handler)
- func (srv *Server) SetDefaultProxy(u string) error
- func (srv *Server) SocialLogin(prefix string, matcher AccountMatcher)
- func (srv *Server) Use(mw Middleware)
- type ServerConfig
- func (cfg *ServerConfig) Abs(fn string) (string, error)
- func (cfg *ServerConfig) CheckPidfile() error
- func (cfg *ServerConfig) CheckPorts() error
- func (cfg *ServerConfig) Init() error
- func (cfg *ServerConfig) LoadFromFile(fn string) error
- func (cfg *ServerConfig) ReadableFile(fn string) error
- func (cfg *ServerConfig) WritableDir(dn string) error
- type SocialLoginConfig
- type StaticFile
- type WebSocket
Constants ¶
View Source
const (
MinCompressSize = 2048
)
Variables ¶
View Source
var Accepted = newHerr(http.StatusAccepted, "Accpeted")
View Source
var BadGateway = newHerr(http.StatusBadGateway, "Bad Gateway")
View Source
var BadRequest = newHerr(http.StatusBadRequest, "Bad Request")
View Source
var Conflict = newHerr(http.StatusConflict, "Conflict")
View Source
var Created = newHerr(http.StatusCreated, "Created")
View Source
var Forbidden = newHerr(http.StatusForbidden, "Forbidden")
View Source
var Found = newRedirect(http.StatusFound, "Found")
View Source
var GatewayTimeout = newHerr(http.StatusGatewayTimeout, "Gateway Timeout")
View Source
var Gone = newHerr(http.StatusGone, "Gone")
View Source
var InternalServerError = newHerr(http.StatusInternalServerError, "Internal Server Error")
View Source
var MethodNotAllowed = newMethodNotAllowed()
View Source
var MovedPermanently = newRedirect(http.StatusMovedPermanently, "Moved Permanently")
View Source
var NoContent = newHerr(http.StatusNoContent, "No Content")
View Source
var NotAcceptable = newHerr(http.StatusNotAcceptable, "Not Acceptable")
View Source
var NotFound = newNotFound()
View Source
var NotImplemented = newHerr(http.StatusNotImplemented, "Not Implemented")
View Source
var NotModified = newHerr(http.StatusNotModified, "Not Modified")
View Source
var OK = newHerr(http.StatusOK, "OK")
View Source
var PartialContent = newHerr(http.StatusPartialContent, "Partial Content")
View Source
var PermanentRedirect = newRedirect(http.StatusPermanentRedirect, "Permanent Redirect")
View Source
var PreconditionFailed = newHerr(http.StatusPreconditionFailed, "Precondition Failed")
View Source
var RequestTimeout = newHerr(http.StatusRequestTimeout, "Request Timeout")
View Source
var TemporaryRedirect = newRedirect(http.StatusTemporaryRedirect, "Temporary Redirect")
View Source
var TooManyRequests = newHerr(http.StatusTooManyRequests, "Too Many Requests")
Functions ¶
func CheckPreconditions ¶
func ContextRequestId ¶
func ParseIPNet ¶
func SendJSON ¶
func SendJSON(w http.ResponseWriter, obj interface{})
func SetDefaultContentType ¶
func SetDefaultContentType(w http.ResponseWriter, ct string)
func ValidateRouter ¶
Types ¶
type APIError ¶ added in v1.1.0
type APIError interface { Error() string StatusCode() int SetStatus(int) APIError SetMessage(string) APIError AddContent(string, interface{}) APIError Unwrap() error MarshalJSON() ([]byte, error) }
func NewAPIError ¶ added in v1.1.0
type AuthConfig ¶
type AuthConfig struct { PasswordFile string `json:"htpasswd" arg:"--htpasswd"` AuthKey string `json:"key" arg:"key"` TTL int `json:"ttl" arg:"ttl"` SocialLogin map[string]*SocialLoginConfig `json:"social"` // contains filtered or unexported fields }
func (*AuthConfig) GetAuthKey ¶
func (cfg *AuthConfig) GetAuthKey() []byte
func (*AuthConfig) GetTTL ¶
func (cfg *AuthConfig) GetTTL() time.Duration
func (*AuthConfig) Init ¶
func (cfg *AuthConfig) Init(serverRoot string) error
func (*AuthConfig) ReadCookie ¶
func (cfg *AuthConfig) ReadCookie(req *http.Request) *auth.User
func (*AuthConfig) ReadHeader ¶ added in v1.1.5
func (*AuthConfig) SetCookie ¶
func (cfg *AuthConfig) SetCookie(w http.ResponseWriter, user *auth.User)
type BindConfig ¶
type BindConfig struct { ExternalHostname string `json:"hostname" arg:"hostname"` Port int `json:"port" arg:"port"` SSL SSLConfig `json:"ssl" arg:"ssl"` }
func (*BindConfig) Init ¶
func (cfg *BindConfig) Init(serverRoot string) error
func (BindConfig) Proto ¶
func (cfg BindConfig) Proto(ssl bool) string
type Client ¶
type Client struct { Send chan []byte // contains filtered or unexported fields }
func (*Client) NextWriter ¶
func (c *Client) NextWriter(messageType int) (io.WriteCloser, error)
func (*Client) SetPongHandler ¶
func (*Client) SetReadLimit ¶
type CompressResponseWriter ¶
type CompressResponseWriter struct {
// contains filtered or unexported fields
}
func NewCompressResponseWriter ¶
func NewCompressResponseWriter(w http.ResponseWriter, r *http.Request) *CompressResponseWriter
func (*CompressResponseWriter) Close ¶
func (w *CompressResponseWriter) Close() error
func (*CompressResponseWriter) Flush ¶
func (w *CompressResponseWriter) Flush() error
func (*CompressResponseWriter) Header ¶
func (w *CompressResponseWriter) Header() http.Header
func (*CompressResponseWriter) Hijack ¶
func (w *CompressResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*CompressResponseWriter) Write ¶
func (w *CompressResponseWriter) Write(data []byte) (int, error)
func (*CompressResponseWriter) WriteHeader ¶
func (w *CompressResponseWriter) WriteHeader(statusCode int)
type GenericHub ¶
type GenericHub struct { Events chan interface{} // contains filtered or unexported fields }
func NewGenericHub ¶
func NewGenericHub(source chan interface{}) *GenericHub
func (*GenericHub) Broadcast ¶
func (h *GenericHub) Broadcast(msg []byte)
func (*GenericHub) BroadcastEvent ¶
func (h *GenericHub) BroadcastEvent(evt interface{})
func (*GenericHub) Closed ¶
func (h *GenericHub) Closed() bool
func (*GenericHub) Register ¶
func (h *GenericHub) Register(c *Client)
func (*GenericHub) Run ¶
func (h *GenericHub) Run()
func (*GenericHub) Stop ¶
func (h *GenericHub) Stop()
func (*GenericHub) Unregister ¶
func (h *GenericHub) Unregister(c *Client)
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, req *http.Request) (interface{}, error)
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, req *http.Request)
type LogConfig ¶
type LogConfig struct { Directory string `json:"directory" arg:"dir"` AccessLog string `json:"access" arg:"access"` ErrorLog string `json:"error" arg:"error"` RotatePeriod int `json:"rotate_period" arg:"rotate-period"` MaxSize int64 `json:"max_size" arg:"max-size"` RetainCount int `json:"retain" arg:"retain"` LogLevel logging.LogLevel `json:"level" arg:"level"` // contains filtered or unexported fields }
func (*LogConfig) AccessLogger ¶
func (cfg *LogConfig) AccessLogger() (*logrotate.RotateFile, error)
type NetworkConfig ¶
type NetworkConfig struct { Network string `json:"network" arg:"network"` Interface string `json:"interface" arg:"interface"` IP string `json:"ip" arg:"ip"` // contains filtered or unexported fields }
func (*NetworkConfig) GetIP ¶
func (cfg *NetworkConfig) GetIP() net.IP
func (*NetworkConfig) GetInterface ¶
func (cfg *NetworkConfig) GetInterface() *net.Interface
func (*NetworkConfig) GetNetwork ¶
func (cfg *NetworkConfig) GetNetwork() *net.IPNet
func (*NetworkConfig) Init ¶
func (cfg *NetworkConfig) Init() error
type ResponseLogger ¶
type ResponseLogger struct {
// contains filtered or unexported fields
}
func NewResponseLogger ¶
func NewResponseLogger(w http.ResponseWriter, r *http.Request) *ResponseLogger
func (*ResponseLogger) Header ¶
func (rl *ResponseLogger) Header() http.Header
func (*ResponseLogger) Hijack ¶
func (rl *ResponseLogger) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ResponseLogger) WriteHeader ¶
func (rl *ResponseLogger) WriteHeader(statusCode int)
func (*ResponseLogger) WriteLog ¶
func (rl *ResponseLogger) WriteLog(w io.Writer)
type Router ¶
type Router interface { Use(mw Middleware) Prefix(path string) Router LookupPath(method, path string) (http.Handler, map[string]string) Lookup(method string, path []string) (http.Handler, map[string]string) Handle(method, path string, handler http.Handler) error GET(path string, handler http.Handler) error POST(path string, handler http.Handler) error PUT(path string, handler http.Handler) error PATCH(path string, handler http.Handler) error DELETE(path string, handler http.Handler) error OPTIONS(path string, handler http.Handler) error Routes() []*Route Compile(parentMiddlewares []Middleware) }
type SSLConfig ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg *ServerConfig) (*Server, error)
func (*Server) AccessLoggerMiddleware ¶
func (srv *Server) AccessLoggerMiddleware() Middleware
func (*Server) ContextMiddleware ¶
func (srv *Server) ContextMiddleware() Middleware
func (*Server) ListenAndServe ¶
func (*Server) SetDefaultHandler ¶
func (*Server) SetDefaultProxy ¶
func (*Server) SocialLogin ¶
func (srv *Server) SocialLogin(prefix string, matcher AccountMatcher)
func (*Server) Use ¶
func (srv *Server) Use(mw Middleware)
type ServerConfig ¶
type ServerConfig struct { ConfigFile string `json:"-" arg:"--config"` //,-c"` ServerRoot string `json:"server_root" arg:"--server-root"` DocumentRoot string `json:"document_root" arg:"--docroot"` DefaultProxy string `json:"default_proxy" arg:"--proxy"` CacheDirectory string `json:"cache_directory" arg:"--cache-dir"` PidFile string `json:"pidfile" arg:"--pidfile"` Bind BindConfig `json:"bind" arg:"--bind"` Logging LogConfig `json:"log" arg:"--log"` Auth AuthConfig `json:"auth" arg:"--auth"` }
func Configure ¶
func Configure() (*ServerConfig, error)
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
func (*ServerConfig) CheckPidfile ¶
func (cfg *ServerConfig) CheckPidfile() error
func (*ServerConfig) CheckPorts ¶
func (cfg *ServerConfig) CheckPorts() error
func (*ServerConfig) Init ¶
func (cfg *ServerConfig) Init() error
func (*ServerConfig) LoadFromFile ¶
func (cfg *ServerConfig) LoadFromFile(fn string) error
func (*ServerConfig) ReadableFile ¶
func (cfg *ServerConfig) ReadableFile(fn string) error
func (*ServerConfig) WritableDir ¶
func (cfg *ServerConfig) WritableDir(dn string) error
type SocialLoginConfig ¶
type StaticFile ¶
type StaticFile string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.