package main import ( "flag" "log" "net/http" "os" "path" "path/filepath" "strings" "google.golang.org/appengine" ) func main() { exePath, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { panic(err) } exePath = "." directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host") flag.Parse() http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") { r.URL.Scheme = "https" http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect) return } http.FileServer(http.Dir(*directory)).ServeHTTP(w, r) })) log.Printf("Serving %s\n", *directory) appengine.Main() }