flag.IntVar(&Port, "p", 8877, "端口号,默认为8877") flag.Parse() ip, _ := externalIP() fmt.Println("您的访问地址是:", "http://"+ip.String()+":"+strconv.Itoa(Port)) http.HandleFunc("/up", UploadHandler) http.HandleFunc("/", IndexHandler) http.HandleFunc("/delete", DeleteHandler) fsh := http.FileServer(http.Dir("./file/")) http.Handle("/files/", http.StripPrefix("/files/", fsh)) http.ListenAndServe(":"+strconv.Itoa(Port), nil)
其中
fsh := http.FileServer(http.Dir("./file/")) http.Handle("/files/", http.StripPrefix("/files/", fsh))
就是设置静态文件的目录,这里为了和路由分开,是加了访问前缀的