Skip to content

Commit 0fba106

Browse files
committed
Use a http function to serve assets
1 parent d175dba commit 0fba106

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

modules/public/public.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,28 @@ type Options struct {
2222
}
2323

2424
// AssetsHandler implements the static handler for serving custom or original assets.
25-
func AssetsHandler(opts *Options) func(http.Handler) http.Handler {
26-
return func(next http.Handler) http.Handler {
27-
var custPath = filepath.Join(setting.CustomPath, "public")
28-
if !filepath.IsAbs(custPath) {
29-
custPath = filepath.Join(setting.AppWorkPath, custPath)
30-
}
25+
func AssetsHandler(opts *Options) func(resp http.ResponseWriter, req *http.Request) {
26+
var custPath = filepath.Join(setting.CustomPath, "public")
27+
if !filepath.IsAbs(custPath) {
28+
custPath = filepath.Join(setting.AppWorkPath, custPath)
29+
}
3130

32-
if !filepath.IsAbs(opts.Directory) {
33-
opts.Directory = filepath.Join(setting.AppWorkPath, opts.Directory)
34-
}
31+
if !filepath.IsAbs(opts.Directory) {
32+
opts.Directory = filepath.Join(setting.AppWorkPath, opts.Directory)
33+
}
3534

36-
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
37-
// custom files
38-
if opts.handle(resp, req, http.Dir(custPath), opts.Prefix) {
39-
return
40-
}
35+
return func(resp http.ResponseWriter, req *http.Request) {
36+
// custom files
37+
if opts.handle(resp, req, http.Dir(custPath), opts.Prefix) {
38+
return
39+
}
4140

42-
// internal files
43-
if opts.handle(resp, req, fileSystem(opts.Directory), opts.Prefix) {
44-
return
45-
}
41+
// internal files
42+
if opts.handle(resp, req, fileSystem(opts.Directory), opts.Prefix) {
43+
return
44+
}
4645

47-
resp.WriteHeader(404)
48-
})
46+
resp.WriteHeader(404)
4947
}
5048
}
5149

0 commit comments

Comments
 (0)