1
0
Fork 0

Prototype data

main
Ambrose Chua 2020-11-04 03:28:22 +08:00
parent 93287f5551
commit c481a9ffa2
5 changed files with 57 additions and 4 deletions

View File

@ -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

View File

@ -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

16
mime_test.go Normal file
View File

@ -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)
}
}

View File

@ -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, ",")
}
*/

View File

@ -48,9 +48,9 @@
<li><a href="https://github.com/serverwentdown/datetime.link" target="_blank">About datetime.link</a></li><!--
--><li><a href="https://github.com/serverwentdown/datetime.link/issues/new" target="_blank">Found a bug?</a></li><!--
--><li onclick="toggleTheme()"><!--
--><span class="icon theme-toggle-system">{{template "solid_adjust.svg"}}</span><span class="theme-toggle-name theme-toggle-system">&nbsp;System theme</span><!--
--><span class="icon theme-toggle-dark">{{template "solid_moon.svg"}}</span><span class="theme-toggle-name theme-toggle-dark">&nbsp;Dark theme</span><!--
--><span class="icon theme-toggle-light">{{template "solid_sun.svg"}}</span><span class="theme-toggle-name theme-toggle-light">&nbsp;Light theme</span><!--
--><span class="icon theme-toggle-system">{{template "icon_solid_adjust.svg"}}</span><span class="theme-toggle-name theme-toggle-system">&nbsp;System theme</span><!--
--><span class="icon theme-toggle-dark">{{template "icon_solid_moon.svg"}}</span><span class="theme-toggle-name theme-toggle-dark">&nbsp;Dark theme</span><!--
--><span class="icon theme-toggle-light">{{template "icon_solid_sun.svg"}}</span><span class="theme-toggle-name theme-toggle-light">&nbsp;Light theme</span><!--
--></li>
</ul>
</footer>