web server
This commit is contained in:
parent
f8f524013e
commit
aa7374a899
@ -13,7 +13,7 @@ type Config struct {
|
||||
|
||||
func ParseConfig(filename string) (*Config, error) {
|
||||
cfg := Config{
|
||||
Port: 80,
|
||||
Port: 8080,
|
||||
EnableInitialRendering: true,
|
||||
}
|
||||
|
||||
|
6
main.go
6
main.go
@ -7,6 +7,7 @@ import (
|
||||
"mapserver/initialrenderer"
|
||||
"mapserver/layerconfig"
|
||||
"mapserver/params"
|
||||
"mapserver/web"
|
||||
|
||||
"fmt"
|
||||
)
|
||||
@ -55,7 +56,10 @@ func main() {
|
||||
|
||||
//run initial rendering
|
||||
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
27
web/serve.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user