aboutsummaryrefslogtreecommitdiff
path: root/app/config.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 /app/config.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 'app/config.go')
-rwxr-xr-xapp/config.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/app/config.go b/app/config.go
index acd9b71..3b85527 100755
--- a/app/config.go
+++ b/app/config.go
@@ -11,36 +11,41 @@ import (
"github.com/zerolabsco/devianter"
)
+// Release carries the build's version and description, set at link time and
+// shown by --help and the API.
var Release struct {
Version string
Description string
}
-type cache_config struct {
- Enabled bool
- MemCache bool `json:"memcache"`
- Path string
- MaxSize int64 `json:"max-size"`
- Lifetime string
- UpdateInterval int64 `json:"update-interval"`
+type cacheConfig struct {
+ Enabled bool `json:"enabled"`
+ MemCache bool `json:"memcache"`
+ Path string `json:"path"`
+ MaxSize int64 `json:"max-size"`
+ Lifetime string `json:"lifetime"`
+ UpdateInterval int64 `json:"update-interval"`
}
type config struct {
cfg string
- Listen string
- URI string `json:"uri"`
- Cache cache_config
- Proxy, Nsfw bool
- UserAgent string `json:"user-agent"`
- DownloadProxy string `json:"download-proxy"`
- StaticPath string `json:"static-path"`
+ Listen string `json:"listen"`
+ URI string `json:"uri"`
+ Cache cacheConfig `json:"cache"`
+ Proxy bool `json:"proxy"`
+ Nsfw bool `json:"nsfw"`
+ UserAgent string `json:"user-agent"`
+ DownloadProxy string `json:"download-proxy"`
+ StaticPath string `json:"static-path"`
}
+// CFG is the running instance's configuration, holding the defaults below until
+// ExecuteConfig overwrites them from the config file.
var CFG = config{
cfg: "config.json",
Listen: "127.0.0.1:3003",
URI: "/",
- Cache: cache_config{
+ Cache: cacheConfig{
Enabled: false,
Path: "cache",
UpdateInterval: 1,
@@ -53,6 +58,9 @@ var CFG = config{
var lifetimeParsed int64
+// ExecuteConfig loads the config file into CFG, validates it, and starts the
+// cache rotation loop if caching is on. It exits the process on a config that
+// cannot be read or that asks for caching without proxying.
func ExecuteConfig() {
if CFG.cfg != "" {
f, err := os.ReadFile(CFG.cfg)