1 Star 0 Fork 1

freely随意/BaiduPCS-Go

forked from ttpc2008/BaiduPCS-Go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pcsweb.go 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
// Package pcsweb web前端包
package pcsweb
import (
"fmt"
"github.com/GeertJohan/go.rice"
"net/http"
)
var (
staticBox *rice.Box // go.rice 文件盒子
templatesBox *rice.Box // go.rice 文件盒子
)
func boxInit() (err error) {
staticBox, err = rice.FindBox("static")
if err != nil {
return
}
templatesBox, err = rice.FindBox("template")
if err != nil {
return
}
return nil
}
// StartServer 开启web服务
func StartServer(port uint) error {
if port <= 0 || port > 65535 {
return fmt.Errorf("invalid port %d", port)
}
err := boxInit()
if err != nil {
return err
}
http.HandleFunc("/", rootMiddleware)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(staticBox.HTTPBox())))
http.HandleFunc("/about.html", middleware(aboutPage))
http.HandleFunc("/index.html", middleware(indexPage))
http.HandleFunc("/cgi-bin/baidu/pcs/file/list", activeAuthMiddleware(fileList))
return http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
}
func aboutPage(w http.ResponseWriter, r *http.Request) {
tmpl := boxTmplParse("index", "index.html", "about.html")
checkErr(tmpl.Execute(w, nil))
}
func indexPage(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
tmpl := boxTmplParse("index", "index.html", "baidu/userinfo.html")
checkErr(tmpl.Execute(w, r.Form.Get("path")))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/freelysuiyi/BaiduPCS-Go.git
git@gitee.com:freelysuiyi/BaiduPCS-Go.git
freelysuiyi
BaiduPCS-Go
BaiduPCS-Go
v3.5.5

搜索帮助

0d507c66 1850385 C8b1a773 1850385