web

package
v0.0.0-...-b19cdf9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Templates = tmplutil.Templater{
	FileSystem: embedFS,
	Includes: map[string]string{
		"error":  "components/error.html",
		"title":  "components/title.html",
		"header": "components/header.html",
	},
	Functions: template.FuncMap{
		"sprint":   fmt.Sprint,
		"sprintf":  fmt.Sprintf,
		"sprintln": fmt.Sprintln,
		"initials": func(str string) string {
			r := []rune(str)
			if len(r) == 0 {
				return ""
			}
			return string(unicode.ToUpper(r[0]))
		},
		"map": func(v ...interface{}) map[string]interface{} {
			m := make(map[string]interface{}, len(v)/2)
			for i := 0; i < len(v); i++ {
				switch k := v[i].(type) {
				case string:
					i++
					m[k] = v[i]
				case map[string]interface{}:
					for k, v := range k {
						m[k] = v
					}
				default:
					log.Panicf("invalid map key type %T", k)
				}
			}
			return m
		},
		"datetime": func(t time.Time) string {

			return t.UTC().Format("2006-01-02T15:04:05Z")
		},
		"datestamp": func(t time.Time) string {
			return t.Format(time.Stamp)
		},
	},
	OnRenderFail: func(sub *tmplutil.Subtemplate, w io.Writer, err error) {
		self := sub.Templater()
		self.Subtemplate("error").Execute(w, err)
	},
}

Templates is a collection of templates.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes the password into an opaque format.

func OverrideFS

func OverrideFS(overrideFS fs.FS)

OverrideFS overrides the template filesystem with the given filesystem.

func StaticHandler

func StaticHandler() http.Handler

StaticHandler is an http.Handler that serves the static files.

Types

type BasicUser

type BasicUser struct {
	Username  string
	Passhash  string
	ExpiresAt time.Time
}

BasicUser is a user used for Basic Authentication.

type PasswordSafe

type PasswordSafe struct {
	// contains filtered or unexported fields
}

PasswordSafe stores users and their passwords. A zero value is safe to use.

func (*PasswordSafe) Add

func (s *PasswordSafe) Add(users []BasicUser)

Add adds users. It is NOT safe to use concurrently.

func (*PasswordSafe) Authenticate

func (s *PasswordSafe) Authenticate(username, password string) bool

Authenticate checks if the given username and password is valid. It is safe to use concurrently as long as Add is not called.

For reference, refer to Caddy's modules/caddyhttp/caddyauth/basicauth.go.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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