Documentation
¶
Index ¶
- Variables
- func FileServerHandler(root fs.FS) http.HandlerFunc
- func GenerateHashString(data []byte) string
- type Cache
- func (c *Cache) DisableFileCache()
- func (c *Cache) DumpStatus() string
- func (c *Cache) EnableFileCache()
- func (c *Cache) Handler() http.Handler
- func (c *Cache) NewContent(content Content) error
- func (c *Cache) ServeContent(w http.ResponseWriter, r *http.Request, uri string)
- func (c *Cache) ServeStatic(w http.ResponseWriter, r *http.Request)
- func (c *Cache) SetFileCacheTTL(ttl time.Duration)
- func (c *Cache) UpdateCache() error
- func (c *Cache) UpdateContent(uri string) error
- type Content
- type ContentInfo
- type CookieManager
- func (cm *CookieManager) DeleteCookie(w http.ResponseWriter, name string)
- func (cm *CookieManager) GetCookie(r *http.Request, name string, value any) error
- func (cm *CookieManager) GetCookiePerm(r *http.Request, name string, value any) error
- func (cm *CookieManager) SetCookie(w http.ResponseWriter, name string, value any, maxAge int, ...) error
- func (cm *CookieManager) SetCookiePerm(w http.ResponseWriter, name string, value any, maxAge int, ...) error
- type CookieOption
Constants ¶
This section is empty.
Variables ¶
var ( DefaultExtensions = [...]string{".txt", ".html", ".css", ".js", ".json", ".webmanifest", ".xml", ".ico"} ErrCacheDisabled = errors.New("cache disabled") )
Functions ¶
func FileServerHandler ¶
func FileServerHandler(root fs.FS) http.HandlerFunc
func GenerateHashString ¶
GenerateHashString generate a hash with sha256 from data
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) DisableFileCache ¶
func (c *Cache) DisableFileCache()
func (*Cache) DumpStatus ¶
func (*Cache) EnableFileCache ¶
func (c *Cache) EnableFileCache()
func (*Cache) NewContent ¶
func (*Cache) ServeContent ¶
func (*Cache) ServeStatic ¶
func (c *Cache) ServeStatic(w http.ResponseWriter, r *http.Request)
func (*Cache) SetFileCacheTTL ¶
func (*Cache) UpdateCache ¶
func (*Cache) UpdateContent ¶
type Content ¶
type Content interface { URI() string Name() string Info() (ContentInfo, error) Reader() (io.ReadSeekCloser, error) }
type ContentInfo ¶
type CookieManager ¶
type CookieManager struct {
// contains filtered or unexported fields
}
func GetCookieManager ¶
func GetCookieManager(r *http.Request) *CookieManager
func NewCookieManager ¶
func NewCookieManager(hashKey []byte, blockKey []byte, sz securecookie.Serializer) (*CookieManager, error)
func (*CookieManager) DeleteCookie ¶
func (cm *CookieManager) DeleteCookie(w http.ResponseWriter, name string)
DeleteCookie instantly removes a cookie with the given name before set with route.SetCookie or route.SetCookiePerm
func (*CookieManager) GetCookie ¶
DecodeCookie decodes a previously set cookie with the given name using the method route.SetCookie.
If the cookie was not found, it will return false and the relative error (probably an http.ErrNoCookie), otherwise it will return true and, possibly, the decode error. It happends when:
- the server was restarted, so the keys used for decoding are different
- you provided the wrong value type
- the cookie was not set by the server
The argument value must be a pointer, otherwise the value will not be returned. A workaround might be using the type parametric function server.DecodeCookie
func (*CookieManager) GetCookiePerm ¶
DecodeCookiePerm decodes a previously set cookie with the given name using the method route.SetCookiePerm.
If the cookie was not found, it will return false and the relative error (probably an http.ErrNoCookie), otherwise it will return true and, possibly, the decode error. It happends when:
- you provided the wrong value type
- the cookie was not set by the server
The argument value must be a pointer, otherwise the value will not be returned. A workaround might be using the type parametric function server.DecodeCookiePerm
func (*CookieManager) SetCookie ¶
func (cm *CookieManager) SetCookie(w http.ResponseWriter, name string, value any, maxAge int, opts ...CookieOption) error
SetCookie creates a new cookie with the given name and value, maxAge can be used to sex the expiration date:
- maxAge = 0 means no expiration specified
- maxAge > 0 sets the expiration date from the current date adding the given time in seconds (- maxAge < 0 will remove the cookie instantly, like route.DeleteCookie)
The cookie value is encoded and encrypted using a pair of keys created randomly at server creation, so if the same cookie is later decoded between server restart, it can't be decoded. To have such a behaviour see SetCookiePerm.
The encoding of the value is managed by the package encoding/gob. If you are just encoding and decoding plain structs and each field type is a primary type or a struct (with the same rules), nothing should be done, but if you are dealing with interfaces, you must first register every concrete structure or type implementing that interface before encoding or decoding
func (*CookieManager) SetCookiePerm ¶
func (cm *CookieManager) SetCookiePerm(w http.ResponseWriter, name string, value any, maxAge int, opts ...CookieOption) error
SetCookiePerm creates a new cookie with the given name and value, maxAge can be used to sex the expiration date:
- maxAge = 0 means no expiration specified
- maxAge > 0 sets the expiration date from the current date adding the given time in seconds (- maxAge < 0 will remove the cookie instantly, like route.DeleteCookie)
The cookie value is encoded and encrypted using a pair of keys at package level that MUST be set at program startup. This differs for the method route.SetCookie to ensure that even after server restart these cookies can still be decoded.
type CookieOption ¶
func CookieDomainOpt ¶
func CookieDomainOpt(value string) CookieOption
func CookieExpiresOpt ¶
func CookieExpiresOpt(value time.Time) CookieOption
func CookieHTTPOnlyOpt ¶
func CookieHTTPOnlyOpt(value bool) CookieOption
func CookiePathOpt ¶
func CookiePathOpt(value string) CookieOption
func CookieSameSiteOpt ¶
func CookieSameSiteOpt(value http.SameSite) CookieOption
func CookieSecureOpt ¶
func CookieSecureOpt(value bool) CookieOption