diff --git a/README.md b/README.md index 6098470..366e3ec 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Sea Spy is designed to track hundreds of thousands of vessels via Google Maps wi 5. Verify Sea Spy is running * Open your browser - * Navigate to [http://localhost:8080](http://localhost:8080). + * Navigate to [http://127.0.0.1:8080](http://127.0.0.1:8080). ### Known Issues * Vessel shape clipping diff --git a/aisstream/aisstream.go b/aisstream/aisstream.go index 62e70c6..b18d8da 100644 --- a/aisstream/aisstream.go +++ b/aisstream/aisstream.go @@ -38,8 +38,9 @@ type Config struct { Url string `json:"url"` Api string `json:"api"` DefaultSub struct { - Boxes [][][]float64 `json:"boxes"` - FilterMMSI []string `json:"filterMMSI"` + Boxes [][][]float64 `json:"boxes"` + FilterMMSI []string `json:"filterMMSI"` + FilterMsgType []string `json:"filterMsgType"` } `json:"defaultSub"` } diff --git a/doc/config/seaspy-yourfleet.json b/doc/config/seaspy-yourfleet.json index e393573..f0e9e77 100644 --- a/doc/config/seaspy-yourfleet.json +++ b/doc/config/seaspy-yourfleet.json @@ -1,6 +1,7 @@ { "portal": { - "listenAddr": "127.0.0.1:8080" + "listenAddr": "127.0.0.1:8080", + "htmlDir": "./html" }, "swabby": { @@ -35,6 +36,10 @@ "", "", "" + ], + "filterMsgType": [ + "PositionReport", + "ShipStaticData" ] } } diff --git a/doc/config/seaspy.json b/doc/config/seaspy.json index 7670528..f5b8790 100644 --- a/doc/config/seaspy.json +++ b/doc/config/seaspy.json @@ -1,6 +1,7 @@ { "portal": { - "listenAddr": "127.0.0.1:8080" + "listenAddr": "127.0.0.1:8080", + "htmlDir": "./html" }, "swabby": { @@ -29,6 +30,11 @@ 180 ] ] + ], + "filterMMSI": [], + "filterMsgType": [ + "PositionReport", + "ShipStaticData" ] } } diff --git a/main.go b/main.go index 48145af..bc93328 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ func main() { ais := aisstream.NewAIS(config.Aisstream.Url, config.Aisstream.Api) ais.Sub.AddBox(config.Aisstream.DefaultSub.Boxes) ais.Sub.AddMMSI(config.Aisstream.DefaultSub.FilterMMSI) + ais.Sub.AddMsgType(config.Aisstream.DefaultSub.FilterMsgType) go ais.ConnectAndStream() dock := NewDock(10) @@ -41,7 +42,7 @@ func main() { swabby := NewSwabby(config.Swabby) go swabby.Cleanup(dock) - server := ListenAndServe(config.Portal.ListenAddr, dock, config.Google) + server := ListenAndServe(config.Portal, dock, config.Google) stop := make(chan os.Signal, 1) signal.Notify(stop, os.Interrupt) diff --git a/portal.go b/portal.go index bf0de7a..ad62fd8 100644 --- a/portal.go +++ b/portal.go @@ -6,22 +6,25 @@ import ( "html/template" "log" "net/http" + "path/filepath" "strconv" ) type Portal struct { ListenAddr string `json:"listenAddr"` + HtmlDir string `json:"htmlDir"` } type Google struct { Api string `json:"api"` } -func ListenAndServe(addr string, dock *Dock, g Google) *http.Server { +func ListenAndServe(p Portal, dock *Dock, g Google) *http.Server { mux := http.NewServeMux() - staticFs := http.FileServer(http.Dir("./html/static")) + htmlDir := filepath.Join(p.HtmlDir, "static") + staticFs := http.FileServer(http.Dir(htmlDir)) mux.Handle("GET /static/", http.StripPrefix("/static/", staticFs)) mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { @@ -46,7 +49,7 @@ func ListenAndServe(addr string, dock *Dock, g Google) *http.Server { mux.HandleFunc("GET /shipTypes", shipTypes) mux.HandleFunc("GET /shipGroups", shipGroups) - server := &http.Server{Addr: "127.0.0.1:8080", Handler: mux} + server := &http.Server{Addr: p.ListenAddr, Handler: mux} go func() { err := server.ListenAndServe() if err != nil && err != http.ErrServerClosed {