Ai
1 Star 0 Fork 0

g8up/go-uploader

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
g8up 提交于 2018-05-27 15:16 +08:00 . template
package main
import(
"github.com/gorilla/mux"
"net/http"
"log"
"flag"
"awesomeProject/router"
)
var (
hostname string
port string
static string
)
func init() {
flag.StringVar(&hostname, "hostname", "0.0.0.0", "The hostname or IP on which the REST server will listen")
flag.StringVar(&port, "port", "8000", "The port on which the REST server will listen")
flag.StringVar(&static, "static", "./static", "静态资源路径")
}
func main() {
flag.Parse()
r := mux.NewRouter()
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(static))))
r.HandleFunc( "/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Gorilla!\n"))
})
r.HandleFunc("/upload", router.UploadPage).Methods("get")
r.HandleFunc("/upload/{category}", router.UploadPage).Methods("get")
r.HandleFunc("/upload/{category}", router.Upload).Methods("post")
r.HandleFunc("/show/{category}", router.Show).Methods("get")
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":" + port, r))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/g8up/go-uploader.git
git@gitee.com:g8up/go-uploader.git
g8up
go-uploader
go-uploader
master

搜索帮助