This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
/
main.go
71 lines (57 loc) · 1.65 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
package main // import "github.com/Luzifer/locationmaps"
//go:generate go-bindata assets
import (
"fmt"
"net/http"
"os"
"github.com/Luzifer/rconfig"
"github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/mux"
"github.com/lancecarlson/couchgo"
)
var (
config = struct {
Listen string `flag:"listen" default:":3000" description:"Address and port to listen on"`
CouchDBConnection string `flag:"couchdb" description:"Connection string for CouchDB"`
Version bool `flag:"version" default:"false" description:"Print version and quit"`
}{}
couchConn *couch.Client
version = "dev"
)
func init() {
if err := rconfig.Parse(&config); err != nil {
fmt.Printf("Unable to load config: %s\n", err)
os.Exit(1)
}
if config.Version {
fmt.Printf("locationmaps %s\n", version)
os.Exit(0)
}
c, err := couch.NewClientURL(config.CouchDBConnection)
if err != nil {
fmt.Printf("Unable to connect to CouchDB: %s\n", err)
os.Exit(1)
}
couchConn = c
}
func main() {
if err := loadUserDB(); err != nil {
fmt.Printf("Error while loading userdb: %s\n", err)
os.Exit(1)
}
fmt.Printf("%+v\n", users)
r := mux.NewRouter()
r.HandleFunc("/{user:.+}.html", handleMap).
Methods("GET")
r.HandleFunc("/{user:.+}.json", handleGetLatest).
Methods("GET")
r.HandleFunc("/{user:.+}.png", handleGetMarkerImage).
Methods("GET")
r.HandleFunc("/api/v1/simple.add", handleSimpleAdd).
Methods("POST")
r.HandleFunc("/api/v1/gpx.add", handleGPXAdd).
Methods("POST")
r.PathPrefix("/assets").Handler(http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: ""})).
Methods("GET")
http.ListenAndServe(config.Listen, r)
}