-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
35 lines (29 loc) · 760 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/aligator/neargo/datasource/geonames"
"github.com/aligator/neargo/server"
"github.com/rs/cors"
"github.com/spf13/pflag"
)
func main() {
gn := geonames.Geonames{}
gn.PFlag()
host := pflag.String("host", "0.0.0.0:3141", "Host and Port to listen on.")
origins := pflag.StringSlice("origins", []string{"*"}, `Comma separated CORS Origins`)
pflag.Parse()
neargo := server.Neargo{
Source: gn,
}
err := neargo.Init()
if err != nil {
log.Fatal(err)
}
log.Println("Serving on " + *host)
err = http.ListenAndServe(*host, cors.New(cors.Options{
AllowedOrigins: *origins,
AllowedMethods: []string{http.MethodHead, http.MethodOptions, http.MethodGet},
}).Handler(neargo))
log.Fatal(err)
}