From c481a9ffa288ad93f6f09d03b55bb17346648b10 Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Wed, 4 Nov 2020 03:28:22 +0800 Subject: [PATCH] Prototype data --- main.go | 2 ++ mime.go | 3 ++- mime_test.go | 16 ++++++++++++++++ scripts/data.go | 34 ++++++++++++++++++++++++++++++++++ templates/index.html | 6 +++--- 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 mime_test.go diff --git a/main.go b/main.go index 460ee72..4b3a48c 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,8 @@ func index(w http.ResponseWriter, req *http.Request) { templateName = "index.txt" case responseHTML: templateName = "index.html" + case responseAny: + templateName = "index.txt" case responseUnknown: w.WriteHeader(http.StatusNotAcceptable) return diff --git a/mime.go b/mime.go index 31cf1e2..3741816 100644 --- a/mime.go +++ b/mime.go @@ -57,6 +57,7 @@ type responseType int const ( responsePlain responseType = iota responseHTML responseType = iota + responseAny responseType = iota responseUnknown responseType = iota ) @@ -77,7 +78,7 @@ func chooseResponseType(accept string) responseType { return responseHTML } if m.media == responseAnyMime { - return responseHTML + return responseAny } } return responseUnknown diff --git a/mime_test.go b/mime_test.go new file mode 100644 index 0000000..a48000e --- /dev/null +++ b/mime_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "testing" +) + +func TestChooseResponseType(t *testing.T) { + r := chooseResponseType("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3") + if r != responseHTML { + t.Errorf("expecting html, got %v", r) + } + r = chooseResponseType("application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3") + if r != responseAny { + t.Errorf("expecting html, got %v", r) + } +} diff --git a/scripts/data.go b/scripts/data.go index b88afff..54cf072 100644 --- a/scripts/data.go +++ b/scripts/data.go @@ -1,3 +1,13 @@ +/* +This script reads in GeoNames data and creates a table of IDs to city names and +timezones. The IDs are created from the ASCII city name, with administrative +division level 1 name and country code as disambiguation. Examples of IDs are: + + Singapore + Ashland_Oregon_US + Ashland_Mississippi_US + +*/ package main import ( @@ -11,6 +21,29 @@ import ( "strings" ) +// City represents a city that belongs inside an administrative division level 1 +// and a country +type City struct { + // Ref is the ASCII name of the city + Ref string `json:"r"` + // Name is the full UTF-8 name of the city + Name string `json:"n"` + AlternateNames []string `json:"an"` + + // Admin1Ref is the ASCII name of the administrative division level 1 + Admin1Ref string `json:"a1r"` + Admin1Name string `json:"a1n"` + + // CountryRef is the ISO-3166 2-letter country code + CountryRef string `json:"cr"` + CountryName string `json:"cn"` +} + +func main() { +} + +/* + func main() { // Read CSV data citiesFile, err := os.Open("data/cities15000.txt") @@ -113,3 +146,4 @@ func normalizeName(name string) string { func splitNames(names string) []string { return strings.Split(names, ",") } +*/ diff --git a/templates/index.html b/templates/index.html index 8703938..9609e51 100644 --- a/templates/index.html +++ b/templates/index.html @@ -48,9 +48,9 @@
  • About datetime.link
  • Found a bug?
  • {{template "solid_adjust.svg"}} System theme{{template "solid_moon.svg"}} Dark theme{{template "solid_sun.svg"}} Light theme{{template "icon_solid_adjust.svg"}} System theme{{template "icon_solid_moon.svg"}} Dark theme{{template "icon_solid_sun.svg"}} Light theme