add listen flag

pull/1/head
kun 2018-09-03 11:09:50 +08:00
parent 1224447fc4
commit b7175d8f9a
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"flag"
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
@ -13,6 +14,12 @@ import (
) )
var cacheDir string var cacheDir string
var listen string
func init() {
flag.StringVar(&listen, "listen", "0.0.0.0:8081", "service listen address")
flag.Parse()
}
func main() { func main() {
gp := os.Getenv("GOPATH") gp := os.Getenv("GOPATH")
@ -21,7 +28,7 @@ func main() {
} }
cacheDir = filepath.Join(gp, "pkg", "mod", "cache", "download") cacheDir = filepath.Join(gp, "pkg", "mod", "cache", "download")
http.Handle("/", mainHandler(http.FileServer(http.Dir(cacheDir)))) http.Handle("/", mainHandler(http.FileServer(http.Dir(cacheDir))))
err := http.ListenAndServe(":8081", nil) err := http.ListenAndServe(listen, nil)
if nil != err { if nil != err {
panic(err) panic(err)
} }