/
web.go
35 lines (31 loc) · 815 Bytes
/
web.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
31
32
33
34
35
package main
import (
"github.com/nelsam/goweb_angular_demo/controllers"
"github.com/stretchr/goweb"
"log"
"net"
"net/http"
"os"
"time"
)
// main initializes and starts the web server.
func main() {
controllers.MapControllers()
MapStaticFiles()
log.Print("Mapped URLs, creating server...")
address := ":" + os.Getenv("PORT")
server := &http.Server{
Addr: address,
Handler: goweb.DefaultHttpHandler(),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Print("Created server, listening for requests.")
listener, listenErr := net.Listen("tcp", address)
if listenErr != nil {
log.Printf("Could not listen for tcp connections on address %s: %s", address, listenErr.Error())
panic(listenErr)
}
server.Serve(listener)
}