Skip to content

Commit c5625f7

Browse files
committed
fix: use path.Clean replace filepath.Clean
1 parent d0d126d commit c5625f7

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

router_static.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"os"
7-
"path/filepath"
7+
"path"
88
"strings"
99

1010
"github.com/tonny-zhang/cotton/utils"
@@ -50,7 +50,7 @@ func (router *Router) StaticFile(prefix, root string, listDir bool) {
5050
if !listDir {
5151
fs = &onlyFilesFS{fs}
5252
}
53-
fileServer := http.StripPrefix(filepath.Join(router.prefix, prefix), http.FileServer(fs))
53+
fileServer := http.StripPrefix(path.Join(router.prefix, prefix), http.FileServer(fs))
5454

5555
router.Get(utils.CleanPath(prefix+"/*filepath"), func(ctx *Context) {
5656
fileServer.ServeHTTP(ctx.Response, ctx.Request)

router_template.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package cotton
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"path/filepath"
66
"strings"
77
"text/template"
88
)
99

1010
func getTplFiles(dir string, ext string) (list []string, err error) {
11-
files, err := ioutil.ReadDir(dir)
11+
files, err := os.ReadDir(dir)
1212
for _, f := range files {
1313
if strings.HasPrefix(f.Name(), ".") {
1414
continue
@@ -32,11 +32,12 @@ func getTplFiles(dir string, ext string) (list []string, err error) {
3232
//
3333
// funcs is functions register to template
3434
// example:
35-
// router.LoadTemplates(root, map[string]interface{}{
36-
// "md5": func(str string) string {
37-
// return str + "_md5"
38-
// },
39-
// })
35+
//
36+
// router.LoadTemplates(root, map[string]interface{}{
37+
// "md5": func(str string) string {
38+
// return str + "_md5"
39+
// },
40+
// })
4041
func (router *Router) LoadTemplates(tplRoot string, funcs map[string]interface{}) {
4142
if router.globalTemplate == nil {
4243
tpl := template.New("global")

utils/path.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package utils
22

33
import (
4-
"path/filepath"
4+
libPath "path"
55
"strings"
66
)
77

88
// CleanPath clean path
99
// example:
10-
// /a////b => /a/b
11-
// /a/b////c/ => /a/b/c/
10+
//
11+
// /a////b => /a/b
12+
// /a/b////c/ => /a/b/c/
1213
func CleanPath(path string) string {
1314
suffix := ""
1415
if strings.HasSuffix(path, "/") {
1516
suffix = "/"
1617
}
17-
return filepath.Clean(path) + suffix
18+
return libPath.Clean(path) + suffix
1819
}

0 commit comments

Comments
 (0)