doc: Improve server

This commit is contained in:
Hajime Hoshi 2016-08-02 00:51:37 +09:00
parent ef1e558ec6
commit c1c8ba4d7e

View File

@ -19,6 +19,8 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"path/filepath"
"runtime"
"strconv" "strconv"
) )
@ -28,8 +30,15 @@ func init() {
flag.Parse() flag.Parse()
} }
var rootPath = ""
func init() {
_, path, _, _ := runtime.Caller(0)
rootPath = filepath.Join(filepath.Dir(path), "..", "public")
}
func main() { func main() {
http.Handle("/", http.FileServer(http.Dir("public"))) http.Handle("/", http.FileServer(http.Dir(rootPath)))
fmt.Printf("http://localhost:%d/\n", *port) fmt.Printf("http://localhost:%d/\n", *port)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil)) log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil))
} }