aboutsummaryrefslogtreecommitdiff
path: root/static/templates-noembed.go
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-15 02:25:20 -0500
committerChristian Cleberg <[email protected]>2026-07-15 02:25:20 -0500
commitd6789522d3dd076f7c98dafa3e7d42df09252093 (patch)
tree4f27291432e367a32be581654b010ad19c5497aa /static/templates-noembed.go
parent7eb5e5e2230b6fb5b1bed6f0eaa03279aa61555b (diff)
downloadskunky-art-1.3.3.tar.gz
skunky-art-1.3.3.tar.bz2
skunky-art-1.3.3.zip
fix: document exported API, fix naming, and harden Downloadv1.3.3
The remaining golangci-lint findings. These land together because the Url -> URL rename spans util.go, parsers.go and wrapper.go, and splitting it would leave an intermediate commit that does not compile. Download() carried the most serious bug here: try() only prints an error, it does not return, so a failed request fell through to resp.Body.Close() on a nil resp and panicked. Every failure path now returns the zero Downloaded, and callers check Status. ReturnHTTPError guards against the resulting status 0, which would otherwise panic WriteHeader. Requests carry a context with a timeout (noctx), and a download-proxy now routes through ProxiedTransport so it keeps the DA throttle and timeouts. Also: - doc comments on all 48 exported symbols (revive's exported rule, with checkPrivateReceivers, since most of app is exported methods on the unexported skunkyart type), plus package docs in new doc.go files so both the embed and non-embed builds are covered. - ST1003 naming: UrlBuilder -> URLBuilder, id_search -> idSearch, cache_config -> cacheConfig, TXT_RAW -> TxtRaw, mediaUrl -> mediaURL. - explicit json tags on structs that are unmarshaled (musttag); the hyphenated keys already had tags, the rest relied on case-insensitive fallback. Behaviour is unchanged. - modernization: range-over-int, WaitGroup.Go, stale +build lines, interface{} -> any, strings.Builder over string concatenation in a loop.
Diffstat (limited to 'static/templates-noembed.go')
-rwxr-xr-xstatic/templates-noembed.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/static/templates-noembed.go b/static/templates-noembed.go
index c0dfe7f..ee97ca7 100755
--- a/static/templates-noembed.go
+++ b/static/templates-noembed.go
@@ -1,5 +1,4 @@
//go:build !embed
-// +build !embed
package static
@@ -11,6 +10,7 @@ import (
"time"
)
+// Templates is the in-memory asset filesystem populated by CopyTemplatesToMemory.
var Templates FS
type file struct {
@@ -21,8 +21,12 @@ type file struct {
var templateNames = []string{}
var templates = make(map[string][]file)
+
+// StaticPath is the directory assets are read from at startup.
var StaticPath string
+// CopyTemplatesToMemory reads every asset under StaticPath into memory. It exits
+// the process on failure, since the frontend cannot serve anything without them.
func CopyTemplatesToMemory() {
baseDir, err := os.ReadDir(StaticPath)
try(err)
@@ -53,8 +57,11 @@ func CopyTemplatesToMemory() {
}
}
+// FS serves the in-memory assets. It implements the subset of fs.FS that
+// template.ParseFS requires.
type FS struct{}
+// Open returns the asset stored at name, or an fs.PathError if there is none.
func (FS) Open(name string) (fs.File, error) {
for i, l := 0, len(templateNames); i < l; i++ {
for _, x := range templates[templateNames[i]] {
@@ -69,6 +76,8 @@ func (FS) Open(name string) (fs.File, error) {
return nil, &fs.PathError{}
}
+// Glob returns the paths of every asset in the directory named by pattern's
+// first segment, or an fs.PathError if none match.
func (FS) Glob(pattern string) ([]string, error) {
trimmed := strings.Split(pattern, "/")
var matches = []string{}
@@ -91,47 +100,60 @@ func try(err error) {
}
}
-/* based on https://github.com/psanford/memfs; required for templates.ParseFS to work correctly */
+// fileInfo is a minimal fs.FileInfo. Assets are held in memory and never stat'd
+// for anything but their name, so the remaining fields report fixed values.
+//
+// Based on https://github.com/psanford/memfs; required for templates.ParseFS to
+// work correctly.
type fileInfo struct {
name string
}
+// Name returns the asset's path.
func (fi fileInfo) Name() string {
return fi.name
}
+// Size reports a fixed placeholder size; callers here never use it.
func (fi fileInfo) Size() int64 {
return 4096
}
+// Mode reports no mode bits: in-memory assets have no filesystem permissions.
func (fileInfo) Mode() fs.FileMode {
return 0
}
+// ModTime reports the zero time, as in-memory assets are never modified.
func (fileInfo) ModTime() time.Time {
return time.Time{}
}
+// IsDir always reports false: only files are stored, never directories.
func (fileInfo) IsDir() bool {
return false
}
-func (fileInfo) Sys() interface{} {
+// Sys returns nil, as there is no underlying data source.
+func (fileInfo) Sys() any {
return nil
}
+// File is a read-once handle to an in-memory asset.
type File struct {
name string
content *bytes.Buffer
closed bool
}
+// Stat returns the file's fileInfo. It never fails.
func (f *File) Stat() (fs.FileInfo, error) {
return fileInfo{
name: f.name,
}, nil
}
+// Read consumes the asset's contents, reporting fs.ErrClosed once closed.
func (f *File) Read(b []byte) (int, error) {
if f.closed {
return 0, fs.ErrClosed
@@ -139,6 +161,7 @@ func (f *File) Read(b []byte) (int, error) {
return f.content.Read(b)
}
+// Close marks the file closed. Closing twice reports fs.ErrClosed.
func (f *File) Close() error {
if f.closed {
return fs.ErrClosed