summaryrefslogtreecommitdiffhomepage
path: root/src/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.go')
-rw-r--r--src/http.go57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/http.go b/src/http.go
index 3feda8c..4a56430 100644
--- a/src/http.go
+++ b/src/http.go
@@ -1,4 +1,4 @@
-package src
+package app
import (
"cmp"
@@ -8,14 +8,14 @@ import (
"log"
"math"
"net/http"
- "os"
- "path/filepath"
"slices"
"strconv"
"strings"
+ . "git.thomasvoss.com/euro-cash.eu/pkg/try"
+
+ "git.thomasvoss.com/euro-cash.eu/src/dbx"
"git.thomasvoss.com/euro-cash.eu/src/email"
- "git.thomasvoss.com/euro-cash.eu/src/mintage"
)
type middleware = func(http.Handler) http.Handler
@@ -29,6 +29,7 @@ func Run(port int) {
mwareC := chain(mwareB, countryHandler) // [C]ountry
mwareM := chain(mwareC, mintageHandler) // [M]intage
+ mux.Handle("GET /codes/", fs)
mux.Handle("GET /designs/", fs)
mux.Handle("GET /favicon.ico", fs)
mux.Handle("GET /fonts/", fs)
@@ -42,7 +43,7 @@ func Run(port int) {
portStr := ":" + strconv.Itoa(port)
log.Println("Listening on", portStr)
- log.Fatal(http.ListenAndServe(portStr, mux))
+ Try(http.ListenAndServe(portStr, mux))
}
func chain(xs ...middleware) middleware {
@@ -137,20 +138,14 @@ func mintageHandler(next http.Handler) http.Handler {
td.Type = "circ"
}
- path := filepath.Join("data", "mintages", td.Code)
- f, err := os.Open(path)
- if err != nil {
- throwError(http.StatusInternalServerError, err, w, r)
- return
- }
- defer f.Close()
-
- td.Mintages, err = mintage.Parse(f, path)
+ var err error
+ td.Mintages, err = dbx.GetMintages(td.Code, dbx.NewMintageType(td.Type))
if err != nil {
throwError(http.StatusInternalServerError, err, w, r)
return
}
+ /* processMintages(&td.Mintages, td.Type) */
next.ServeHTTP(w, r)
})
}
@@ -184,7 +179,7 @@ func throwError(status int, err error, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status)
go func() {
if err := email.ServerError(err); err != nil {
- log.Print(err)
+ log.Println(err)
}
}()
errorTmpl.Execute(w, struct {
@@ -195,3 +190,35 @@ func throwError(status int, err error, w http.ResponseWriter, r *http.Request) {
Msg: http.StatusText(status),
})
}
+
+/* func processMintages(md *dbx.MintageData, typeStr string) {
+ var typ int
+ switch typeStr {
+ case "nifc":
+ typ = dbx.TypeNifc
+ case "proof":
+ typ = dbx.TypeProof
+ default:
+ typ = dbx.TypeCirc
+ }
+
+ md.Standard = slices.DeleteFunc(md.Standard,
+ func(x dbx.MSRow) bool { return x.Type != typ })
+ md.Commemorative = slices.DeleteFunc(md.Commemorative,
+ func(x dbx.MCRow) bool { return x.Type != typ })
+ slices.SortFunc(md.Standard, func(x, y dbx.MSRow) int {
+ if x.Year != y.Year {
+ return x.Year - y.Year
+ }
+ return strings.Compare(x.Mintmark, y.Mintmark)
+ })
+ slices.SortFunc(md.Commemorative, func(x, y dbx.MCRow) int {
+ if x.Year != y.Year {
+ return x.Year - y.Year
+ }
+ if x.Number != y.Number {
+ return x.Number - y.Number
+ }
+ return strings.Compare(x.Mintmark, y.Mintmark)
+ })
+} */