forked from go101/go101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 779 Bytes
/
main.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
36
37
38
39
40
41
42
43
44
package main
import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"time"
)
var portFlag = flag.String("port", "55555", "server port")
func main() {
log.SetFlags(0)
flag.Parse()
port := *portFlag
if prt := os.Getenv("PORT"); prt != "" { // appengine std
port = prt
}
l, err := net.Listen("tcp", fmt.Sprintf(":%v", port))
if err != nil {
log.Fatal(err)
}
err = openBrowser(fmt.Sprintf("http://localhost:%v", port))
if err != nil {
log.Println(err)
}
go go101.Update()
log.Println("Server started:")
log.Printf(" http://localhost:%v (non-cached version)\n", port)
log.Printf(" http://127.0.0.1:%v (cached version)\n", port)
(&http.Server{
Handler: go101,
WriteTimeout: 10 * time.Second,
ReadTimeout: 5 * time.Second,
}).Serve(l)
}