webutil

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 11 Imported by: 0

README

webutil

Roadmap

  • logging middleware

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(srv *http.Server) error

Serve requests using the given http.Server. If srv.Addr has the format `hostname:https`, then use autocert to manage certificates for the domain.

For http on port 80, you can use :http.

func ParseTemplateSet

func ParseTemplateSet(funcs template.FuncMap, fs embed.FS) map[string]*template.Template

ParseTemplateSet parses sets of templates from an embed.FS.

Each directory constitutes a set of templates that are parsed together.

Structure (within a directory):

  • share/* are always parsed.
  • base.html will be parsed with each other file in same dir

Call a template with m[path].Execute(w, data) (root dir name is excluded).

For example, if you have

  • /user/share/*
  • /user/base.html
  • /user/home.html

Then you call m["/user/home.html"].Execute(w, data).

func WithLogging

func WithLogging(inner http.HandlerFunc) http.HandlerFunc

Types

type CookieHandler added in v0.0.7

type CookieHandler struct {
	Secure   bool
	SameSite http.SameSite // Defaults to strict.
	MaxAge   int           // Default 10 years
}

func NewCookieHandler added in v0.0.7

func NewCookieHandler(listenAddr string) *CookieHandler

func (*CookieHandler) Get added in v0.0.7

func (h *CookieHandler) Get(r *http.Request, name string) string

func (*CookieHandler) Set added in v0.0.7

func (h *CookieHandler) Set(w http.ResponseWriter, name, value string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL