mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-29 06:49:05 +08:00
Added -http flag for specifying listening address
This commit is contained in:
8
main.go
8
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
"github.com/boltdb/bolt"
|
||||
)
|
||||
|
||||
var addr = flag.String("http", ":8000", "HTTP listen address")
|
||||
|
||||
func makeHandler(name string, fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
validPath := regexp.MustCompile(fmt.Sprintf(`^/%s/([a-zA-Z0-9\-_\/\.]+)$`, name))
|
||||
@@ -71,6 +74,7 @@ func initDB() error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := os.MkdirAll("repos/src/github.com", 0755); err != nil && !os.IsExist(err) {
|
||||
log.Fatal("ERROR: could not create repos dir: ", err)
|
||||
}
|
||||
@@ -89,6 +93,6 @@ func main() {
|
||||
http.HandleFunc("/about/", handlers.AboutHandler)
|
||||
http.HandleFunc("/", handlers.HomeHandler)
|
||||
|
||||
fmt.Println("Running on :8080...")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
log.Printf("Running on %s ...", *addr)
|
||||
log.Fatal(http.ListenAndServe(*addr, nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user