Documentation ¶
Index ¶
- Variables
- func ContentType(w http.ResponseWriter, ct string)
- func GetFilepath() (string, string)
- func IfOK(next http.Handler, ok bool) http.Handler
- func SanitizePath(path string) string
- func StaticHandler(prefix, path string) http.Handler
- type BufferPool
- type Chain
- type Middleware
- type MuxConfig
- type ServeMux
- func (s *ServeMux) ContentType(w http.ResponseWriter, content string)
- func (s *ServeMux) Delete(pattern string, handler http.Handler)
- func (s *ServeMux) Forward(oldpattern string, newpattern string)
- func (s *ServeMux) Get(pattern string, handler http.Handler)
- func (s *ServeMux) Handle(method string, pattern string, handler http.Handler)
- func (s *ServeMux) HandleFunc(method, pattern string, handler func(http.ResponseWriter, *http.Request))
- func (s *ServeMux) Len() int
- func (s *ServeMux) Less(i, j int) bool
- func (s *ServeMux) Post(pattern string, handler http.Handler)
- func (s *ServeMux) Put(pattern string, handler http.Handler)
- func (s *ServeMux) Search(x string) int
- func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *ServeMux) Static(pattern string, path string)
- func (s *ServeMux) Swap(i, j int)
- type TemplateCache
- func (t *TemplateCache) AddSeparateStubs(stubsPattern string) error
- func (t *TemplateCache) ContentType(w http.ResponseWriter, content string)
- func (t *TemplateCache) ExecuteTemplate(w io.Writer, name string, data interface{}) error
- func (t *TemplateCache) Handle(name string) http.Handler
- func (t *TemplateCache) HandleWithData(name string, data interface{}) http.Handler
- func (t *TemplateCache) Lookup(name string) *template.Template
- func (t *TemplateCache) Raw(w http.ResponseWriter, format string, data ...interface{})
- func (t *TemplateCache) Render(w http.ResponseWriter, r *http.Request, tmpl string, data interface{})
- func (t *TemplateCache) RenderWithBuffer(w http.ResponseWriter, r *http.Request, tmpl string, data interface{})
- func (t *TemplateCache) Templates() ([]*template.Template, string)
- func (t *TemplateCache) Use(name string) *template.Template
- type TemplateConfig
- type TemplateManager
- func (tm *TemplateManager) AddCache(scope, base, tmplPattern, stubPattern string) error
- func (tm *TemplateManager) AddCacheWithFiles(scope, base string, files ...string) error
- func (tm *TemplateManager) GetCache(scope string) *TemplateCache
- func (tm *TemplateManager) Lookup(scope, name string) *template.Template
Constants ¶
This section is empty.
Variables ¶
var ( ContentTypeTextHTML = "text/html" ContentTypeTextPlain = "text/plain" ContentTypeTextCSS = "text/css" ContentTypeTextCSV = "text/csv" ContentTypeTextJavaScript = "text/javascript" ContentTypeApplicationXML = "application/xml" ContentTypeApplicationZip = "application/zip" ContentTypeApplicationPDF = "application/pdf" ContentTypeApplicationJSON = "application/json" ContentTypeApplicationJavaScript = "application/javascript" ContentTypeApplicationOctetStream = "application/octet-stream" ContentTypeImageAPNG = "image/apng" ContentTypeImageGIF = "image/gif" ContentTypeImageJPEG = "image/jpeg" ContentTypeImagePNG = "image/png" ContentTypeSVGXML = "image/svg+xml" ContentTypeWebP = "image/webp" ContentTypeMultiPartFormData = "multipart/form-data" )
var ( ErrBadStaticFilepath = errors.New("bad static filepath") ErrBadTemplateFilepath = errors.New("bad template filepath") ErrBadTemplateSuffix = errors.New("bad template suffix") )
var ( DefaultMuxConfigMaxOpts = &MuxConfig{ StaticPath: defaultStaticPath, WithLogging: true, StdOutLogger: logging.NewStdOutLogger(os.Stdout), StdErrLogger: logging.NewStdErrLogger(os.Stderr), } )
var ErrScopeExists = errors.New("scope already exists and cannot be added again")
var ErrScopeNotExists = errors.New("scope does not exist; cannot be found")
Functions ¶
func ContentType ¶ added in v1.8.0
func ContentType(w http.ResponseWriter, ct string)
func GetFilepath ¶ added in v1.8.0
GetFilepath returns the absolute filepath from where it's called. It returns the result as a split string, first the root directory up until the current file and returns the two in this order: dir, file
func SanitizePath ¶ added in v1.8.0
func StaticHandler ¶ added in v1.8.0
StaticHandler is just a static folder handler helper
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
func OpenBufferPool ¶
func OpenBufferPool() *BufferPool
OpenBufferPool returns a single instance of the buffer pool utilizing sync.Once which gives us a no-brainier implementation of the classic singleton pattern
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() *bytes.Buffer
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(buf *bytes.Buffer)
type Chain ¶ added in v1.8.0
type Chain struct {
// contains filtered or unexported fields
}
Chain acts as a list of http.Handler middlewares. It's effectively immutable.
func NewChain ¶ added in v1.8.0
func NewChain(mw ...Middleware) *Chain
NewChain creates a new chain, memorizing the given list of middleware handlers. New serves no other function, middlewares are only called upon a call to Then().
func (*Chain) Append ¶ added in v1.8.0
func (c *Chain) Append(mw ...Middleware) *Chain
Append extends a chain, adding the specified constructors as the last ones in the request flow.
func (*Chain) Extend ¶ added in v1.8.0
Extend extends a chain by adding the specified chain as the last one in the request flow.
type Middleware ¶ added in v1.8.0
Middleware is a piece of middleware.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
func NewServeMux ¶
func NewServeMux(logger *logging.LevelLogger) *ServeMux
func (*ServeMux) ContentType ¶
func (s *ServeMux) ContentType(w http.ResponseWriter, content string)
func (*ServeMux) HandleFunc ¶
type TemplateCache ¶
type TemplateCache struct {
// contains filtered or unexported fields
}
TemplateCache is a template engine that caches golang html/template files
func NewTemplateCache ¶
func NewTemplateCache(conf *TemplateConfig) (*TemplateCache, error)
NewTemplateCache takes a pattern to glob and an optional logger and returns a new *TemplateCache instance. On success, it returns a nil error. An example pattern to glob would be: "web/templates/*.html" or "my-path/*.tmpl.html"
func NewTemplateCacheWithFiles ¶ added in v1.3.0
func NewTemplateCacheWithFiles(conf *TemplateConfig, files ...string) (*TemplateCache, error)
func NewTemplateCacheWithSeparateStubs ¶ added in v1.1.0
func NewTemplateCacheWithSeparateStubs(conf *TemplateConfig) (*TemplateCache, error)
func (*TemplateCache) AddSeparateStubs ¶ added in v1.1.0
func (t *TemplateCache) AddSeparateStubs(stubsPattern string) error
func (*TemplateCache) ContentType ¶
func (t *TemplateCache) ContentType(w http.ResponseWriter, content string)
func (*TemplateCache) ExecuteTemplate ¶
func (t *TemplateCache) ExecuteTemplate(w io.Writer, name string, data interface{}) error
func (*TemplateCache) Handle ¶ added in v1.2.0
func (t *TemplateCache) Handle(name string) http.Handler
func (*TemplateCache) HandleWithData ¶ added in v1.2.0
func (t *TemplateCache) HandleWithData(name string, data interface{}) http.Handler
func (*TemplateCache) Raw ¶
func (t *TemplateCache) Raw(w http.ResponseWriter, format string, data ...interface{})
func (*TemplateCache) Render ¶
func (t *TemplateCache) Render(w http.ResponseWriter, r *http.Request, tmpl string, data interface{})
func (*TemplateCache) RenderWithBuffer ¶
func (t *TemplateCache) RenderWithBuffer(w http.ResponseWriter, r *http.Request, tmpl string, data interface{})
type TemplateConfig ¶
type TemplateManager ¶ added in v1.1.0
type TemplateManager struct {
// contains filtered or unexported fields
}
func NewTemplateManager ¶ added in v1.1.0
func NewTemplateManager() *TemplateManager
func (*TemplateManager) AddCache ¶ added in v1.1.0
func (tm *TemplateManager) AddCache(scope, base, tmplPattern, stubPattern string) error
func (*TemplateManager) AddCacheWithFiles ¶ added in v1.3.0
func (tm *TemplateManager) AddCacheWithFiles(scope, base string, files ...string) error
func (*TemplateManager) GetCache ¶ added in v1.1.0
func (tm *TemplateManager) GetCache(scope string) *TemplateCache