improve package gres

This commit is contained in:
John Guo
2021-01-07 19:34:46 +08:00
parent a9f332fdd6
commit 788ade2db0
4 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -74,6 +74,7 @@ func (r *Resource) Get(path string) *File {
return nil
}
path = strings.Replace(path, "\\", "/", -1)
path = strings.Replace(path, "//", "/", -1)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]
@ -93,6 +94,7 @@ func (r *Resource) Get(path string) *File {
func (r *Resource) GetWithIndex(path string, indexFiles []string) *File {
// Necessary for double char '/' replacement in prefix.
path = strings.Replace(path, "\\", "/", -1)
path = strings.Replace(path, "//", "/", -1)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]
@ -114,7 +116,6 @@ func (r *Resource) GetWithIndex(path string, indexFiles []string) *File {
// GetContent directly returns the content of <path>.
func (r *Resource) GetContent(path string) []byte {
path = strings.Replace(path, "\\", "/", -1)
file := r.Get(path)
if file != nil {
return file.Content()
@ -169,6 +170,7 @@ func (r *Resource) ScanDirFile(path string, pattern string, recursive ...bool) [
// It scans directory recursively if given parameter <recursive> is true.
func (r *Resource) doScanDir(path string, pattern string, recursive bool, onlyFile bool) []*File {
path = strings.Replace(path, "\\", "/", -1)
path = strings.Replace(path, "//", "/", -1)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]

View File

@ -1,4 +1,4 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long