-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (67 loc) · 2.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// server is an HTTP server that runs the go-www-geotag application.
package main
import (
"context"
"github.com/sfomuseum/go-flags/flagset"
"github.com/sfomuseum/go-www-geotag/app"
_ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite"
"log"
"net/http"
)
func main() {
ctx := context.Background()
fl, err := app.CommonFlags()
if err != nil {
log.Fatalf("Failed to instantiate common flags, %v", err)
}
flagset.Parse(fl)
err = flagset.SetFlagsFromEnvVars(fl, "GEOTAG")
if err != nil {
log.Fatalf("Failed to set flags from env vars, %v", err)
}
mux := http.NewServeMux()
err = app.AppendAssetHandlers(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append asset handlers, %v", err)
}
// The core "geotagging" application
err = app.AppendEditorHandlerIfEnabled(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append editor handler, %v", err)
}
// Support for point-in-polygon lookups (for things that have been geotagged)
err = app.AppendPointInPolygonHandlerIfEnabled(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append point-in-polygon handler, %v", err)
}
// Local Tilezen proxy caching layer
err = app.AppendProxyTilesHandlerIfEnabled(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append proxy tiles handler, %v", err)
}
// Local Tilezen "tilepack" tile-serving layer
err = app.AppendTilezenTilepackHandlerIfEnabled(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append proxy tiles handler, %v", err)
}
// Local Protomaps tile-serving layer
err = app.AppendProtomapsTilesHandlerIfNecessary(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append protomaps tiles handler, %v", err)
}
// Abstract writer interface(s)
err = app.AppendWriterHandlerIfEnabled(ctx, fl, mux)
if err != nil {
log.Fatalf("Failed to append writer handler, %v", err)
}
// Public-facing server
s, err := app.NewServer(ctx, fl)
if err != nil {
log.Fatalf("Failed to create application server, %v", err)
}
log.Printf("Listening on %s", s.Address())
err = s.ListenAndServe(ctx, mux)
if err != nil {
log.Fatalf("Failed to start server, %v", err)
}
}