repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

591 B · 26 lines · Go Raw History
 1package main
 2
 3import (
 4	"fmt"
 5	"html/template"
 6)
 7
 8// dict lets a partial take more than one value, since a Go template has a
 9// single dot.
10var templateFuncs = template.FuncMap{"dict": dict}
11
12func dict(pairs ...any) (map[string]any, error) {
13	if len(pairs)%2 != 0 {
14		return nil, fmt.Errorf("dict: odd number of arguments (%d)", len(pairs))
15	}
16	out := make(map[string]any, len(pairs)/2)
17	for i := 0; i < len(pairs); i += 2 {
18		key, ok := pairs[i].(string)
19		if !ok {
20			return nil, fmt.Errorf("dict: key %d is %T, want string", i, pairs[i])
21		}
22		out[key] = pairs[i+1]
23	}
24	return out, nil
25}