diff --git a/common/common.go b/common/common.go index c435ad9e..064b3f96 100644 --- a/common/common.go +++ b/common/common.go @@ -14,8 +14,8 @@ import ( "sync/atomic" "time" - qgen "github.com/Azareal/Gosora/query_gen" meta "github.com/Azareal/Gosora/common/meta" + qgen "github.com/Azareal/Gosora/query_gen" ) var SoftwareVersion = Version{Major: 0, Minor: 3, Patch: 0, Tag: "dev"} @@ -35,6 +35,8 @@ const Terabyte int = Gigabyte * 1024 const Petabyte int = Terabyte * 1024 var StartTime time.Time +var GzipStartEtag string +var StartEtag string var TmplPtrMap = make(map[string]interface{}) // Anti-spam token with rotated key @@ -176,4 +178,4 @@ func eachall(stmt *sql.Stmt, f func(r *sql.Rows) error) error { } } return rows.Err() -} \ No newline at end of file +} diff --git a/common/files.go b/common/files.go index 85e6f06c..187fcc95 100644 --- a/common/files.go +++ b/common/files.go @@ -263,7 +263,7 @@ func (list SFileList) Init() error { return err } path = strings.TrimPrefix(path, "public/") - var ext = filepath.Ext("/public/" + path) + ext := filepath.Ext("/public/" + path) mimetype := mime.TypeByExtension(ext) // Get a checksum for CSPs and cache busting diff --git a/common/phrases/phrases.go b/common/phrases/phrases.go index ad1cefa6..f2477111 100644 --- a/common/phrases/phrases.go +++ b/common/phrases/phrases.go @@ -18,6 +18,7 @@ import ( "strings" "sync" "sync/atomic" + "time" ) // TODO: Add a phrase store? @@ -39,6 +40,7 @@ type LevelPhrases struct { type LanguagePack struct { Name string IsoCode string + ModTime time.Time //LastUpdated string // Should we use a sync map or a struct for these? It would be nice, if we could keep all the phrases consistent. @@ -90,6 +92,7 @@ func InitPhrases(lang string) error { if err != nil { return err } + langPack.ModTime = f.ModTime() langPack.ErrorsBytes = make(map[string][]byte) for name, phrase := range langPack.Errors { diff --git a/main.go b/main.go index 162793b2..9e509b55 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,9 @@ func afterDBInit() (err error) { } log.Print("Exitted storeInit") + c.GzipStartEtag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "-ng\"" + c.StartEtag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "-n\"" + var uids []int tc := c.Topics.GetCache() if tc != nil { diff --git a/routes.go b/routes.go index dca85048..e9176335 100644 --- a/routes.go +++ b/routes.go @@ -75,9 +75,9 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError var etag string _, ok := w.(c.GzipResponseWriter) if ok { - etag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "-ng\"" + etag = c.GzipStartEtag } else { - etag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "-n\"" + etag = c.StartEtag } w.Header().Set("ETag", etag) if match := r.Header.Get("If-None-Match"); match != "" { @@ -219,15 +219,15 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout queryBit = strings.TrimSpace(queryBit) if queryBit[0] == '!' && len(queryBit) > 1 { queryBit = strings.TrimPrefix(queryBit, "!") - for _, char := range queryBit { - if !unicode.IsLetter(char) && char != '-' && char != '_' { + for _, ch := range queryBit { + if !unicode.IsLetter(ch) && ch != '-' && ch != '_' { return c.PreErrorJS("No symbols allowed, only - and _", w, r) } } negations = append(negations, queryBit) } else { - for _, char := range queryBit { - if !unicode.IsLetter(char) && char != '-' && char != '_' { + for _, ch := range queryBit { + if !unicode.IsLetter(ch) && ch != '-' && ch != '_' { return c.PreErrorJS("No symbols allowed, only - and _", w, r) } } @@ -242,14 +242,14 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout var etag string _, ok := w.(c.GzipResponseWriter) if ok { - etag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "-g\"" + etag = "\"" + strconv.FormatInt(phrases.GetCurrentLangPack().ModTime.Unix(), 10) + "-ng\"" } else { - etag = "\"" + strconv.FormatInt(c.StartTime.Unix(), 10) + "\"" + etag = "\"" + strconv.FormatInt(phrases.GetCurrentLangPack().ModTime.Unix(), 10) + "-n\"" } var plist map[string]string var notModified, private bool - var posLoop = func(positive string) c.RouteError { + posLoop := func(positive string) c.RouteError { // ! Constrain it to a subset of phrases for now for _, item := range phraseWhitelist { if strings.HasPrefix(positive, item) {