/
server.go
30 lines (24 loc) · 922 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"fmt"
"github.com/paulbellamy/mango"
)
func hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
return 200, mango.Headers{}, mango.Body("Hello World!")
}
func bye(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
return 200, mango.Headers{}, mango.Body("Bye Bye!")
}
func routeNotFound(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
return 404, mango.Headers{}, mango.Body("You probably got lost :(")
}
func StartServer() {
routes := make(map[string]mango.App)
routes["/hello"] = new(mango.Stack).Compile(hello)
routes["/bye"] = new(mango.Stack).Compile(bye)
testServer := new(mango.Stack)
testServer.Middleware(mango.ShowErrors("<html><body>{Error|html}</body></html>"), mango.Routing(routes))
testServer.Address = "localhost:" + Configuration.Server_Port
testServer.Run(routeNotFound)
fmt.Printf("Running server on: %s\n", testServer.Address)
}