mirror of
https://gitee.com/sjqzhang/go-fastdfs.git
synced 2024-11-29 17:57:41 +08:00
support pporf debug option in config
This commit is contained in:
parent
c237f148ff
commit
6a4b29cd01
2
main.go
2
main.go
@ -6,7 +6,7 @@ import (
|
||||
"github.com/sjqzhang/go-fastdfs/cmd/version"
|
||||
dfs "github.com/sjqzhang/go-fastdfs/server"
|
||||
"github.com/spf13/cobra"
|
||||
_ "go.uber.org/automaxprocs" // 根据容器配额设置 maxprocs
|
||||
//_ "go.uber.org/automaxprocs" // 根据容器配额设置 maxprocs
|
||||
_ "net/http/pprof" // 注册 pprof 接口
|
||||
)
|
||||
|
||||
|
@ -112,6 +112,7 @@ const (
|
||||
"rename_file": false,
|
||||
"是否支持web上传,方便调试": "默认支持web上传",
|
||||
"enable_web_upload": true,
|
||||
"enable_pprof_debug": false,
|
||||
"是否支持非日期路径": "默认支持非日期路径,也即支持自定义路径,需要上传文件时指定path",
|
||||
"enable_custom_path": true,
|
||||
"下载域名": "用于外网下载文件的域名",
|
||||
@ -223,11 +224,12 @@ type GlobalConfig struct {
|
||||
ImageMaxWidth int `json:"image_max_width"`
|
||||
ImageMaxHeight int `json:"image_max_height"`
|
||||
Proxies []Proxy `json:"proxies"`
|
||||
EnablePprofDebug bool `json:"enable_pprof_debug"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Dir string `json:"dir"`
|
||||
Addr string `json:"addr"`
|
||||
Addr string `json:"addr"`
|
||||
Origin string `json:"origin"`
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,8 @@ func (HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||
if Config().EnableCrossOrigin {
|
||||
server.CrossOrigin(res, req)
|
||||
}
|
||||
http.DefaultServeMux.ServeHTTP(res, req)
|
||||
//http.DefaultServeMux.ServeHTTP(res, req)
|
||||
mux.ServeHTTP(res,req)
|
||||
}
|
||||
|
||||
type HttpProxyHandler struct {
|
||||
|
@ -5,42 +5,49 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var mux *http.ServeMux
|
||||
|
||||
func (c *Server) initRouter() {
|
||||
if Config().EnablePprofDebug {
|
||||
mux = http.DefaultServeMux
|
||||
} else {
|
||||
mux = http.NewServeMux()
|
||||
}
|
||||
groupRoute := ""
|
||||
if Config().SupportGroupManage && Config().Group!="" {
|
||||
if Config().SupportGroupManage && Config().Group != "" {
|
||||
groupRoute = "/" + Config().Group
|
||||
}
|
||||
uploadPage := "upload.html"
|
||||
if groupRoute == "" {
|
||||
http.HandleFunc(fmt.Sprintf("%s", "/"), c.Download)
|
||||
http.HandleFunc(fmt.Sprintf("/%s", uploadPage), c.Index)
|
||||
mux.HandleFunc(fmt.Sprintf("%s", "/"), c.Download)
|
||||
mux.HandleFunc(fmt.Sprintf("/%s", uploadPage), c.Index)
|
||||
} else {
|
||||
http.HandleFunc(fmt.Sprintf("%s", "/"), c.Download)
|
||||
http.HandleFunc(fmt.Sprintf("%s", groupRoute), c.Download)
|
||||
http.HandleFunc(fmt.Sprintf("%s/%s", groupRoute, uploadPage), c.Index)
|
||||
mux.HandleFunc(fmt.Sprintf("%s", "/"), c.Download)
|
||||
mux.HandleFunc(fmt.Sprintf("%s", groupRoute), c.Download)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/%s", groupRoute, uploadPage), c.Index)
|
||||
}
|
||||
http.HandleFunc(fmt.Sprintf("%s/check_files_exist", groupRoute), c.CheckFilesExist)
|
||||
http.HandleFunc(fmt.Sprintf("%s/check_file_exist", groupRoute), c.CheckFileExist)
|
||||
http.HandleFunc(fmt.Sprintf("%s/upload", groupRoute), c.Upload)
|
||||
http.HandleFunc(fmt.Sprintf("%s/delete", groupRoute), c.RemoveFile)
|
||||
http.HandleFunc(fmt.Sprintf("%s/get_file_info", groupRoute), c.GetFileInfo)
|
||||
http.HandleFunc(fmt.Sprintf("%s/sync", groupRoute), c.Sync)
|
||||
http.HandleFunc(fmt.Sprintf("%s/stat", groupRoute), c.Stat)
|
||||
http.HandleFunc(fmt.Sprintf("%s/repair_stat", groupRoute), c.RepairStatWeb)
|
||||
http.HandleFunc(fmt.Sprintf("%s/status", groupRoute), c.Status)
|
||||
http.HandleFunc(fmt.Sprintf("%s/repair", groupRoute), c.Repair)
|
||||
http.HandleFunc(fmt.Sprintf("%s/report", groupRoute), c.Report)
|
||||
http.HandleFunc(fmt.Sprintf("%s/backup", groupRoute), c.BackUp)
|
||||
http.HandleFunc(fmt.Sprintf("%s/search", groupRoute), c.Search)
|
||||
http.HandleFunc(fmt.Sprintf("%s/list_dir", groupRoute), c.ListDir)
|
||||
http.HandleFunc(fmt.Sprintf("%s/remove_empty_dir", groupRoute), c.RemoveEmptyDir)
|
||||
http.HandleFunc(fmt.Sprintf("%s/repair_fileinfo", groupRoute), c.RepairFileInfo)
|
||||
http.HandleFunc(fmt.Sprintf("%s/reload", groupRoute), c.Reload)
|
||||
http.HandleFunc(fmt.Sprintf("%s/syncfile_info", groupRoute), c.SyncFileInfo)
|
||||
http.HandleFunc(fmt.Sprintf("%s/get_md5s_by_date", groupRoute), c.GetMd5sForWeb)
|
||||
http.HandleFunc(fmt.Sprintf("%s/receive_md5s", groupRoute), c.ReceiveMd5s)
|
||||
http.HandleFunc(fmt.Sprintf("%s/gen_google_secret", groupRoute), c.GenGoogleSecret)
|
||||
http.HandleFunc(fmt.Sprintf("%s/gen_google_code", groupRoute), c.GenGoogleCode)
|
||||
http.Handle(fmt.Sprintf("%s/static/", groupRoute), http.StripPrefix(fmt.Sprintf("%s/static/", groupRoute), http.FileServer(http.Dir("./static"))))
|
||||
http.HandleFunc("/"+Config().Group+"/", c.Download)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/check_files_exist", groupRoute), c.CheckFilesExist)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/check_file_exist", groupRoute), c.CheckFileExist)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/upload", groupRoute), c.Upload)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/delete", groupRoute), c.RemoveFile)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/get_file_info", groupRoute), c.GetFileInfo)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/sync", groupRoute), c.Sync)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/stat", groupRoute), c.Stat)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/repair_stat", groupRoute), c.RepairStatWeb)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/status", groupRoute), c.Status)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/repair", groupRoute), c.Repair)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/report", groupRoute), c.Report)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/backup", groupRoute), c.BackUp)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/search", groupRoute), c.Search)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/list_dir", groupRoute), c.ListDir)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/remove_empty_dir", groupRoute), c.RemoveEmptyDir)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/repair_fileinfo", groupRoute), c.RepairFileInfo)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/reload", groupRoute), c.Reload)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/syncfile_info", groupRoute), c.SyncFileInfo)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/get_md5s_by_date", groupRoute), c.GetMd5sForWeb)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/receive_md5s", groupRoute), c.ReceiveMd5s)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/gen_google_secret", groupRoute), c.GenGoogleSecret)
|
||||
mux.HandleFunc(fmt.Sprintf("%s/gen_google_code", groupRoute), c.GenGoogleCode)
|
||||
mux.Handle(fmt.Sprintf("%s/static/", groupRoute), http.StripPrefix(fmt.Sprintf("%s/static/", groupRoute), http.FileServer(http.Dir("./static"))))
|
||||
mux.HandleFunc("/"+Config().Group+"/", c.Download)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -233,23 +232,23 @@ func (c *Server) Start() {
|
||||
|
||||
c.initRouter()
|
||||
|
||||
if Config().Proxies != nil && len(Config().Proxies) > 0 {
|
||||
for _, proxy := range Config().Proxies {
|
||||
go func(proxy Proxy) {
|
||||
handler := HttpProxyHandler{
|
||||
Proxy: proxy,
|
||||
}
|
||||
fmt.Println("Proxy on " + proxy.Addr)
|
||||
server := &http.Server{
|
||||
Addr: proxy.Addr,
|
||||
Handler: &handler,
|
||||
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
|
||||
}
|
||||
server.ListenAndServe()
|
||||
|
||||
}(proxy)
|
||||
}
|
||||
}
|
||||
//if Config().Proxies != nil && len(Config().Proxies) > 0 {
|
||||
// for _, proxy := range Config().Proxies {
|
||||
// go func(proxy Proxy) {
|
||||
// handler := HttpProxyHandler{
|
||||
// Proxy: proxy,
|
||||
// }
|
||||
// fmt.Println("Proxy on " + proxy.Addr)
|
||||
// server := &http.Server{
|
||||
// Addr: proxy.Addr,
|
||||
// Handler: &handler,
|
||||
// TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
|
||||
// }
|
||||
// server.ListenAndServe()
|
||||
//
|
||||
// }(proxy)
|
||||
// }
|
||||
//}
|
||||
|
||||
fmt.Println("Listen on " + Config().Addr)
|
||||
if Config().EnableHttps {
|
||||
|
Loading…
Reference in New Issue
Block a user