mapserver/web/serve.go

28 lines
519 B
Go
Raw Normal View History

2019-01-18 11:30:51 +03:00
package web
import (
2019-01-18 12:11:40 +03:00
"github.com/sirupsen/logrus"
"mapserver/app"
"mapserver/vfs"
"net/http"
"strconv"
2019-01-18 11:30:51 +03:00
)
2019-01-18 12:11:40 +03:00
func Serve(ctx *app.App) {
fields := logrus.Fields{
"port": ctx.Config.Port,
"webdev": ctx.Config.Webdev,
}
logrus.WithFields(fields).Info("Starting http server")
2019-01-18 11:30:51 +03:00
2019-01-18 12:11:40 +03:00
mux := http.NewServeMux()
2019-01-18 11:30:51 +03:00
2019-01-18 12:11:40 +03:00
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
2019-01-18 12:44:10 +03:00
mux.Handle("/tile/", &Tiles{ctx: ctx})
2019-01-18 12:11:40 +03:00
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
if err != nil {
panic(err)
}
2019-01-18 11:30:51 +03:00
}