improve gres with file separator replaced to /

This commit is contained in:
John
2019-09-10 14:21:11 +08:00
parent 09da0f7388
commit 2ed1854f0c
2 changed files with 5 additions and 1 deletions

View File

@ -59,7 +59,7 @@ func ParseWithArgs(args []string, supportedOptions map[string]bool) (*Parser, er
for i := 0; i < len(args); {
if option := parser.parseOption(args[i]); option != "" {
array, _ := gregex.MatchString(`^(\w+)=(.+)$`, option)
array, _ := gregex.MatchString(`^(.+?)=(.+)$`, option)
if len(array) == 3 {
if parser.isOptionValid(array[1]) {
parser.setOptionValue(array[1], array[2])

View File

@ -70,6 +70,7 @@ func (r *Resource) Get(path string) *File {
if path == "" {
return nil
}
path = strings.Replace(path, "\\", "/", -1)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]
@ -87,6 +88,7 @@ func (r *Resource) Get(path string) *File {
//
// GetWithIndex is usually used for http static file service.
func (r *Resource) GetWithIndex(path string, indexFiles []string) *File {
path = strings.Replace(path, "\\", "/", -1)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]
@ -108,6 +110,7 @@ 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()
@ -161,6 +164,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)
if path != "/" {
for path[len(path)-1] == '/' {
path = path[:len(path)-1]