mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-29 17:18:43 +08:00
chore (maintain): cleanup main
This commit is contained in:
20
cmd/main.go
20
cmd/main.go
@ -15,15 +15,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
router *mux.Router = mux.NewRouter()
|
||||
app = App{}
|
||||
)
|
||||
server.Build(router, app)
|
||||
Run(router, app)
|
||||
Run(mux.NewRouter(), App{})
|
||||
}
|
||||
|
||||
func Run(routes *mux.Router, app App) {
|
||||
func Run(router *mux.Router, app App) {
|
||||
Log.Info("Filestash %s starting", APP_VERSION)
|
||||
check(InitLogger(), "Logger init failed. err=%s")
|
||||
check(InitConfig(), "Config init failed. err=%s")
|
||||
@ -33,17 +28,22 @@ func Run(routes *mux.Router, app App) {
|
||||
check(ErrNotFound, "Missing starter plugin. err=%s")
|
||||
}
|
||||
for _, obj := range Hooks.Get.HttpEndpoint() {
|
||||
obj(routes, &app)
|
||||
obj(router, &app)
|
||||
}
|
||||
for _, fn := range Hooks.Get.Onload() {
|
||||
fn()
|
||||
}
|
||||
server.CatchAll(routes, app)
|
||||
server.Build(router, app)
|
||||
server.PluginRoutes(router)
|
||||
server.CatchAll(router, app)
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
server.DebugRoutes(router)
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
for _, obj := range Hooks.Get.Starter() {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
obj(routes)
|
||||
obj(router)
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
@ -153,7 +153,6 @@ func ServeFile(chroot string) func(*App, http.ResponseWriter, *http.Request) {
|
||||
),
|
||||
)
|
||||
head := res.Header()
|
||||
|
||||
if f := applyPatch(filePath); f != nil {
|
||||
head.Set("Content-Type", GetMimeType(filepath.Ext(filePath)))
|
||||
head.Set("Cache-Control", "no-cache")
|
||||
@ -447,7 +446,7 @@ func applyPatch(filePath string) (file *bytes.Buffer) {
|
||||
bytes.NewReader(outputBuffer.Bytes()),
|
||||
patchFiles[i],
|
||||
); err != nil {
|
||||
Log.Debug("ctrl::static cannot apply patch - %s", err.Error())
|
||||
Log.Debug("ctrl::static err=cannot_apply_patch path=%s err=%s", patchFiles[i].NewName, err.Error())
|
||||
return nil
|
||||
}
|
||||
outputBuffer = patched
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
@ -113,11 +112,6 @@ func Build(r *mux.Router, a App) {
|
||||
r.HandleFunc(WithBase("/healthz"), NewMiddlewareChain(HealthHandler, []Middleware{}, a)).Methods("GET", "HEAD")
|
||||
r.HandleFunc(WithBase("/custom.css"), NewMiddlewareChain(CustomCssHandler, []Middleware{}, a)).Methods("GET")
|
||||
r.PathPrefix(WithBase("/doc")).Handler(NewMiddlewareChain(DocPage, []Middleware{}, a)).Methods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
initDebugRoutes(r)
|
||||
}
|
||||
initPluginsRoutes(r, &a)
|
||||
}
|
||||
|
||||
func CatchAll(r *mux.Router, a App) {
|
||||
@ -127,7 +121,7 @@ func CatchAll(r *mux.Router, a App) {
|
||||
r.PathPrefix("/").Handler(http.HandlerFunc(NewMiddlewareChain(ServeFrontofficeHandler, middlewares, a))).Methods("GET", "POST")
|
||||
}
|
||||
|
||||
func initDebugRoutes(r *mux.Router) {
|
||||
func DebugRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
r.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||
@ -158,7 +152,7 @@ func initDebugRoutes(r *mux.Router) {
|
||||
})
|
||||
}
|
||||
|
||||
func initPluginsRoutes(r *mux.Router, a *App) {
|
||||
func PluginRoutes(r *mux.Router) {
|
||||
// frontoffice overrides: it is the mean by which plugin can interact with the frontoffice
|
||||
for _, obj := range Hooks.Get.FrontendOverrides() {
|
||||
r.HandleFunc(obj, func(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user