forked from practicalgo/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
32 lines (24 loc) · 657 Bytes
/
Copy pathserver.go
File metadata and controls
32 lines (24 loc) · 657 Bytes
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
package main
import (
"io"
"log"
"net/http"
"os"
"github.com/practicalgo/code/chap6/complex-server/config"
"github.com/practicalgo/code/chap6/complex-server/handlers"
"github.com/practicalgo/code/chap6/complex-server/middleware"
)
func setupServer(mux *http.ServeMux, w io.Writer) http.Handler {
conf := config.InitConfig(w)
handlers.Register(mux, conf)
return middleware.RegisterMiddleware(mux, conf)
}
func main() {
listenAddr := os.Getenv("LISTEN_ADDR")
if len(listenAddr) == 0 {
listenAddr = ":8080"
}
mux := http.NewServeMux()
wrappedMux := setupServer(mux, os.Stdout)
log.Fatal(http.ListenAndServe(listenAddr, wrappedMux))
}