Prototype data
parent
93287f5551
commit
c481a9ffa2
2
main.go
2
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
|
||||
|
|
3
mime.go
3
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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, ",")
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -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"> System theme</span><!--
|
||||
--><span class="icon theme-toggle-dark">{{template "solid_moon.svg"}}</span><span class="theme-toggle-name theme-toggle-dark"> Dark theme</span><!--
|
||||
--><span class="icon theme-toggle-light">{{template "solid_sun.svg"}}</span><span class="theme-toggle-name theme-toggle-light"> Light theme</span><!--
|
||||
--><span class="icon theme-toggle-system">{{template "icon_solid_adjust.svg"}}</span><span class="theme-toggle-name theme-toggle-system"> System theme</span><!--
|
||||
--><span class="icon theme-toggle-dark">{{template "icon_solid_moon.svg"}}</span><span class="theme-toggle-name theme-toggle-dark"> Dark theme</span><!--
|
||||
--><span class="icon theme-toggle-light">{{template "icon_solid_sun.svg"}}</span><span class="theme-toggle-name theme-toggle-light"> Light theme</span><!--
|
||||
--></li>
|
||||
</ul>
|
||||
</footer>
|
||||
|
|
Loading…
Reference in New Issue