diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
commit | 655b6b211ae6df0186abd740f248939f7ddeaec1 (patch) | |
tree | ec5cdbbc52222f62c8fbb0bcf2a1aa7a9f6eb8b6 /http_template_funcs.go | |
parent | Correct table headers in MR indices (diff) | |
download | forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.gz forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.zst forge-655b6b211ae6df0186abd740f248939f7ddeaec1.zip |
Add descriptive comments to most Go functions
Diffstat (limited to 'http_template_funcs.go')
-rw-r--r-- | http_template_funcs.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/http_template_funcs.go b/http_template_funcs.go index f466f07..526841f 100644 --- a/http_template_funcs.go +++ b/http_template_funcs.go @@ -5,31 +5,35 @@ package main import ( "net/url" - "path" "strings" ) +// These are all trivial functions that are used in HTML templates. +// See resources.go. + +// firstLine returns the first line of a string. func firstLine(s string) string { before, _, _ := strings.Cut(s, "\n") return before } -func baseName(s string) string { - return path.Base(s) -} - +// pathEscape escapes the input as an URL path segment. func pathEscape(s string) string { return url.PathEscape(s) } +// queryEscape escapes the input as an URL query segment. func queryEscape(s string) string { return url.QueryEscape(s) } +// dereference dereferences a pointer. func dereference[T any](p *T) T { return *p } +// dereferenceOrZero dereferences a pointer. If the pointer is nil, the zero +// value of its associated type is returned instead. func dereferenceOrZero[T any](p *T) T { if p != nil { return *p @@ -38,6 +42,7 @@ func dereferenceOrZero[T any](p *T) T { return z } +// minus subtracts two numbers. func minus(a, b int) int { return a - b } |