Skip to content

Commit

Permalink
Add aisstream MessageType filter to config
Browse files Browse the repository at this point in the history
Add config element to specify html directory

Fix ListenAndServe to use config element
  • Loading branch information
bbailey1024 committed May 14, 2024
1 parent 129a137 commit 5fbd1a2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions aisstream/aisstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
7 changes: 6 additions & 1 deletion doc/config/seaspy-yourfleet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"portal": {
"listenAddr": "127.0.0.1:8080"
"listenAddr": "127.0.0.1:8080",
"htmlDir": "./html"

},
"swabby": {
Expand Down Expand Up @@ -35,6 +36,10 @@
"<your mmsi 2>",
"<your mmsi 3>",
"<your mmsi 4>"
],
"filterMsgType": [
"PositionReport",
"ShipStaticData"
]
}
}
Expand Down
8 changes: 7 additions & 1 deletion doc/config/seaspy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"portal": {
"listenAddr": "127.0.0.1:8080"
"listenAddr": "127.0.0.1:8080",
"htmlDir": "./html"

},
"swabby": {
Expand Down Expand Up @@ -29,6 +30,11 @@
180
]
]
],
"filterMMSI": [],
"filterMsgType": [
"PositionReport",
"ShipStaticData"
]
}
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 5fbd1a2

Please sign in to comment.