瀏覽代碼

support running on $PORT

Lucas Stadler 11 年之前
父節點
當前提交
b02660f20c
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      go/favicon.go

+ 7 - 1
go/favicon.go

@ -13,12 +13,18 @@ import (
13 13
	"github.com/golang/groupcache/lru"
14 14
)
15 15
16
var port = "8080"
17
16 18
var faviconCache = lru.New(10000)
17 19
var lock sync.RWMutex
18 20
19 21
func main() {
20 22
	http.HandleFunc("/favicon", HandleGetFavicon)
21
	err := http.ListenAndServe(":8080", nil)
23
	if p := os.Getenv("PORT"); p != "" {
24
		port = p
25
	}
26
	fmt.Printf("listening on :%s\n", port)
27
	err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
22 28
23 29
	if err != nil {
24 30
		fmt.Println("error: ", err)