summaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-12 14:56:37 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-12 14:56:37 +0200
commit792b2bd299b611e378679e5a269cc249e079c60e (patch)
tree1c601d00398b79460a0f5694aad02536fec39897 /main.go
parent0003a3d51b2a7be791bf60b2cddaebb14dc65183 (diff)
Use a new mintage format
Diffstat (limited to 'main.go')
-rw-r--r--main.go26
1 files changed, 8 insertions, 18 deletions
diff --git a/main.go b/main.go
index 270eabb..25049dd 100644
--- a/main.go
+++ b/main.go
@@ -82,14 +82,8 @@ func i18nHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var p, pZero lib.Printer
- if c, err := r.Cookie("locale"); errors.Is(err, http.ErrNoCookie) {
- log.Println("Language cookie not set")
- } else {
- var ok bool
- p, ok = lib.Printers[strings.ToLower(c.Value)]
- if !ok {
- log.Printf("Language ā€˜%sā€™ is unsupported\n", c.Value)
- }
+ if c, err := r.Cookie("locale"); err == nil {
+ p = lib.Printers[strings.ToLower(c.Value)]
}
ctx := context.WithValue(
@@ -112,26 +106,22 @@ func mintageHandler(next http.Handler) http.Handler {
countries := lib.SortedCountries(
r.Context().Value("printer").(lib.Printer))
code := strings.ToLower(cmp.Or(r.FormValue("code"), countries[0].Code))
- ctype := strings.ToLower(cmp.Or(r.FormValue("type"), "circ"))
+ ctype := strings.ToLower(r.FormValue("type"))
path := filepath.Join("data", "mintages", code)
f, _ := os.Open(path) // TODO: Handle error
defer f.Close()
- set, _ := mintage.Parse(f, path) // TODO: Handle error
+ data, _ := mintage.Parse(f, path) // TODO: Handle error
- var idx mintage.CoinType
switch ctype {
- case "circ":
- idx = mintage.TypeCirculated
- case "nifc":
- idx = mintage.TypeNIFC
- case "proof":
- idx = mintage.TypeProof
+ case "circ", "nifc", "proof":
+ default:
+ ctype = "circ"
}
ctx := context.WithValue(r.Context(), "code", code)
ctx = context.WithValue(ctx, "type", ctype)
- ctx = context.WithValue(ctx, "table", set.Tables[idx])
+ ctx = context.WithValue(ctx, "mintages", data)
ctx = context.WithValue(ctx, "countries", countries)
next.ServeHTTP(w, r.WithContext(ctx))
})