1
0
forked from MTSR/mapserver

web server

This commit is contained in:
NatureFreshMilk 2019-01-18 09:30:51 +01:00
parent f8f524013e
commit aa7374a899
3 changed files with 33 additions and 2 deletions

View File

@ -13,7 +13,7 @@ type Config struct {
func ParseConfig(filename string) (*Config, error) { func ParseConfig(filename string) (*Config, error) {
cfg := Config{ cfg := Config{
Port: 80, Port: 8080,
EnableInitialRendering: true, EnableInitialRendering: true,
} }

View File

@ -7,6 +7,7 @@ import (
"mapserver/initialrenderer" "mapserver/initialrenderer"
"mapserver/layerconfig" "mapserver/layerconfig"
"mapserver/params" "mapserver/params"
"mapserver/web"
"fmt" "fmt"
) )
@ -55,7 +56,10 @@ func main() {
//run initial rendering //run initial rendering
if ctx.Config.EnableInitialRendering { if ctx.Config.EnableInitialRendering {
initialrenderer.Render(ctx.Tilerenderer, layerconfig.DefaultLayers) go initialrenderer.Render(ctx.Tilerenderer, layerconfig.DefaultLayers)
} }
//Start http server
web.Serve(ctx)
} }

27
web/serve.go Normal file
View File

@ -0,0 +1,27 @@
package web
import (
"github.com/sirupsen/logrus"
"mapserver/app"
"net/http"
"strconv"
"fmt"
)
func Serve(ctx *app.App){
fields := logrus.Fields{
"port": ctx.Config.Port,
}
logrus.WithFields(fields).Info("Starting http server")
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website!")
})
err := http.ListenAndServe(":" + strconv.Itoa(ctx.Config.Port), mux)
if err != nil {
panic(err)
}
}