main.go

v1.5.1
skunky-art/main.go history · blame · raw

53 lines · 1453 bytes · executable

 1package main
 2
 3import (
 4	"skunkyart/app"
 5	"skunkyart/static"
 6	"time"
 7
 8	"github.com/krazywarez/devianter"
 9)
10
11// version is the release this binary was built from. The release workflow links
12// it in from the git tag so that --help and /api/instance cannot drift from the
13// tag the image was built at:
14//
15//	go build -ldflags "-X main.version=1.3.7"
16//
17// A plain `go build` leaves it as "dev".
18var version = "dev"
19
20func main() {
21	app.Release.Version = version
22	app.Release.Description = "Upstream request caching and rate limiting, escaped output, a valid Atom feed, and a translated interface"
23
24	app.ExecuteCommandLineArguments()
25	app.ExecuteConfig()
26	static.CopyTemplatesToMemory()
27
28	// After the copy, not before: the catalogues are assets, and ExecuteConfig
29	// runs while static/ is still unread.
30	app.LoadLanguages()
31	app.ParseTemplates()
32
33	// Rate/concurrency-limit + time-out outbound DeviantArt requests so bot floods
34	// can't exhaust the process or get our egress IP banned by CloudFront/WAF.
35	app.InstallDAThrottle()
36
37	// Only once the config is loaded and the throttle installed: this fetches over
38	// the network, so starting it earlier both raced ExecuteConfig's writes to CFG
39	// and let the request escape the throttle and the configured User-Agent.
40	go app.RefreshInstances()
41
42	go func() {
43		for {
44			err := devianter.UpdateCSRF()
45			if err != nil {
46				println(err.Error())
47			}
48			time.Sleep(12 * time.Hour)
49		}
50	}()
51
52	app.Router()
53}