Versions in this module Expand all Collapse all v1 v1.1.5 Jun 30, 2021 Changes in this version type AuthConfig + func (cfg *AuthConfig) ReadHeader(req *http.Request, name string) *auth.User v1.1.4 Jun 30, 2021 v1.1.3 Jun 30, 2021 Changes in this version + const MinCompressSize v1.1.2 Jun 29, 2021 v1.1.1 May 21, 2021 Changes in this version type APIError + Error func() string v1.1.0 May 21, 2021 Changes in this version + type APIError interface + AddContent func(string, interface{}) + MarshalJSON func() ([]byte, error) + SetMessage func(string) + SetStatus func(int) + StatusCode func() int + Unwrap func() error + func NewAPIError(cause error, status int) APIError type HTTPError + Unwrap func() error v1.0.3 Mar 12, 2021 v1.0.2 Mar 11, 2021 v1.0.1 Feb 25, 2021 Changes in this version + var Accepted = newHerr(http.StatusAccepted, "Accpeted") + var BadGateway = newHerr(http.StatusBadGateway, "Bad Gateway") + var BadRequest = newHerr(http.StatusBadRequest, "Bad Request") + var Conflict = newHerr(http.StatusConflict, "Conflict") + var Created = newHerr(http.StatusCreated, "Created") + var Forbidden = newHerr(http.StatusForbidden, "Forbidden") + var Found = newRedirect(http.StatusFound, "Found") + var GatewayTimeout = newHerr(http.StatusGatewayTimeout, "Gateway Timeout") + var Gone = newHerr(http.StatusGone, "Gone") + var InternalServerError = newHerr(http.StatusInternalServerError, "Internal Server Error") + var MethodNotAllowed = newMethodNotAllowed() + var MovedPermanently = newRedirect(http.StatusMovedPermanently, "Moved Permanently") + var NoContent = newHerr(http.StatusNoContent, "No Content") + var NotAcceptable = newHerr(http.StatusNotAcceptable, "Not Acceptable") + var NotFound = newNotFound() + var NotImplemented = newHerr(http.StatusNotImplemented, "Not Implemented") + var NotModified = newHerr(http.StatusNotModified, "Not Modified") + var OK = newHerr(http.StatusOK, "OK") + var PartialContent = newHerr(http.StatusPartialContent, "Partial Content") + var PermanentRedirect = newRedirect(http.StatusPermanentRedirect, "Permanent Redirect") + var PreconditionFailed = newHerr(http.StatusPreconditionFailed, "Precondition Failed") + var RequestTimeout = newHerr(http.StatusRequestTimeout, "Request Timeout") + var ServiceUnavailable = newHerr(http.StatusServiceUnavailable, "Service Unavailable") + var TemporaryRedirect = newRedirect(http.StatusTemporaryRedirect, "Temporary Redirect") + var TooManyRequests = newHerr(http.StatusTooManyRequests, "Too Many Requests") + var Unauthorized = newHerr(http.StatusUnauthorized, "Login Required") + 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 AccountMatcher interface + GetUserByEmail func(string) (*auth.User, error) + type AuthCfg interface + Authenticate func(http.ResponseWriter, *http.Request) (string, error) + Authorize func(req *http.Request, username string) bool + GetAuthKey func() []byte + GetTTL func() time.Duration + type AuthConfig struct + AuthKey string + PasswordFile string + SocialLogin map[string]*SocialLoginConfig + TTL int + 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) SetCookie(w http.ResponseWriter, user *auth.User) + type BindConfig struct + ExternalHostname string + Port int + SSL SSLConfig + func (cfg *BindConfig) Init(serverRoot string) error + func (cfg BindConfig) Host(netcfg NetCfg, ssl bool) string + func (cfg BindConfig) Proto(ssl bool) string + func (cfg BindConfig) RootURL(netcfg NetCfg, ssl bool) *url.URL + type Client struct + Send chan []byte + 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 struct + func NewCompressResponseWriter(w http.ResponseWriter, r *http.Request) *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 interface + LastModified func() time.Time + type ETaggable interface + ETag func() string + type GenericHub struct + Events chan interface{} + func NewGenericHub(source chan interface{}) *GenericHub + func (h *GenericHub) Broadcast(msg []byte) + func (h *GenericHub) BroadcastEvent(evt interface{}) + func (h *GenericHub) Closed() bool + func (h *GenericHub) Register(c *Client) + func (h *GenericHub) Run() + func (h *GenericHub) Stop() + func (h *GenericHub) Unregister(c *Client) + type HTTPError interface + Cause func() error + Headers func() http.Header + Message func() string + Status func() string + StatusCode func() int + Wrap func(error, string) HTTPError + Wrapf func(error, string, ...interface{}) HTTPError + type HandlerFunc func(w http.ResponseWriter, req *http.Request) (interface{}, error) + func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, req *http.Request) + type Hub interface + Broadcast func([]byte) + BroadcastEvent func(interface{}) + Closed func() bool + Register func(*Client) + Run func() + Stop func() + Unregister func(*Client) + type LogConfig struct + AccessLog string + Directory string + ErrorLog string + LogLevel logging.LogLevel + MaxSize int64 + RetainCount int + RotatePeriod int + func (cfg *LogConfig) AccessLogger() (*logrotate.RotateFile, error) + func (cfg *LogConfig) ErrorLogger() (*logging.Logger, error) + func (cfg *LogConfig) Init(serverRoot string) error + type Middleware func(http.Handler) http.Handler + type NetCfg interface + GetIP func() net.IP + GetInterface func() *net.Interface + GetNetwork func() *net.IPNet + type NetworkConfig struct + IP string + Interface string + Network string + func (cfg *NetworkConfig) GetIP() net.IP + func (cfg *NetworkConfig) GetInterface() *net.Interface + func (cfg *NetworkConfig) GetNetwork() *net.IPNet + func (cfg *NetworkConfig) Init() error + type ProxyURL string + type Redirect string + type ResponseLogger struct + func NewResponseLogger(w http.ResponseWriter, r *http.Request) *ResponseLogger + func (rl *ResponseLogger) Header() http.Header + func (rl *ResponseLogger) Hijack() (net.Conn, *bufio.ReadWriter, error) + func (rl *ResponseLogger) Write(data []byte) (int, error) + func (rl *ResponseLogger) WriteHeader(statusCode int) + func (rl *ResponseLogger) WriteLog(w io.Writer) + type Route struct + Method string + Path string + func (r *Route) String() string + func (r *Route) URL(params map[string]string) string + type Router interface + Compile func(parentMiddlewares []Middleware) + DELETE func(path string, handler http.Handler) error + GET func(path string, handler http.Handler) error + Handle func(method, path string, handler http.Handler) error + Lookup func(method string, path []string) (http.Handler, map[string]string) + LookupPath func(method, path string) (http.Handler, map[string]string) + OPTIONS func(path string, handler http.Handler) error + PATCH func(path string, handler http.Handler) error + POST func(path string, handler http.Handler) error + PUT func(path string, handler http.Handler) error + Prefix func(path string) Router + Routes func() []*Route + Use func(mw Middleware) + func NewRouter() Router + type SSLConfig struct + CertFile string + Disabled bool + KeyFile string + Port int + func (cfg *SSLConfig) CheckCert(serverRoot string) error + func (cfg *SSLConfig) CheckKey(serverRoot string) error + func (cfg *SSLConfig) Init(serverRoot string) error + func (cfg SSLConfig) Enabled() bool + type Server struct + func NewServer(cfg *ServerConfig) (*Server, error) + 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 struct + Auth AuthConfig + Bind BindConfig + CacheDirectory string + ConfigFile string + DefaultProxy string + DocumentRoot string + Logging LogConfig + PidFile string + ServerRoot string + func Configure() (*ServerConfig, error) + func DefaultServerConfig() *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 struct + ClientID string + ClientSecret string + type StaticFile string + type WebSocket interface + Close func() + Open func(*websocket.Conn) error + ReadPump func() + WritePump func() Other modules containing this package github.com/rclancey/httpserver/v2