Download this file
| 1 | package mapa |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | |
| 6 | "amadan.net/oficina/mapa/internal/mapa/emoji" |
| 7 | ) |
| 8 | |
| 9 | // The icon picker's list (columns and icons spec §2.2): the RGI emoji, |
| 10 | // their groups and names, as JSON, fetched the first time the picker |
| 11 | // opens. Its URL carries a hash of its bytes, so a browser keeps it. |
| 12 | |
| 13 | // emojiPath is the list's route. |
| 14 | const emojiPath = "/emoji.json" |
| 15 | |
| 16 | // emojiHref is the list's URL, with its hash. |
| 17 | func emojiHref() string { |
| 18 | _, hash := emoji.Picker() |
| 19 | return emojiPath + "?v=" + hash |
| 20 | } |
| 21 | |
| 22 | func serveEmoji(writer http.ResponseWriter, request *http.Request) { |
| 23 | body, hash := emoji.Picker() |
| 24 | header := writer.Header() |
| 25 | header.Set("Content-Type", "application/json; charset=utf-8") |
| 26 | if request.URL.Query().Get("v") == hash { |
| 27 | header.Set("Cache-Control", "private, max-age=31536000, immutable") |
| 28 | } else { |
| 29 | header.Set("Cache-Control", "no-cache") |
| 30 | } |
| 31 | _, _ = writer.Write(body) |
| 32 | } |
| 33 | |