Merge branch 'develop'

This commit is contained in:
john
2019-09-01 22:14:45 +08:00
17 changed files with 173 additions and 27 deletions

View File

@ -14,5 +14,5 @@ func main() {
panic(err)
}
fmt.Println(t.Translate(`hello`))
fmt.Println(t.Translate(`{#hello}}{#world}}!`))
fmt.Println(t.Translate(`{#hello}{#world}!`))
}

View File

@ -14,5 +14,5 @@ func main() {
panic(err)
}
fmt.Println(t.Translate(`hello`))
fmt.Println(t.Translate(`{#hello}}{#world}}!`))
fmt.Println(t.Translate(`{#hello}{#world}!`))
}

View File

@ -10,6 +10,6 @@ func main() {
t := gi18n.New()
t.SetLanguage("ja")
fmt.Println(t.Translate(`hello`))
fmt.Println(t.Translate(`{#hello}}{#world}}!`))
fmt.Println(t.Translate(`{#hello}{#world}!`))
}

View File

@ -16,5 +16,5 @@ func main() {
panic(err)
}
fmt.Println(m.Translate(`hello`))
fmt.Println(m.Translate(`{{hello}}{{world}}!`))
fmt.Println(m.Translate(`{#hello}{#world}!`))
}

View File

@ -8,7 +8,7 @@ import (
func main() {
gres.Dump()
g.Dump(gres.Scan("/root/image/logo", "*"))
g.Dump(gres.ScanDir("/root/image", "*"))
//g.Dump(gres.Scan("/root/image/", "*", true))
//g.Dump(gres.Scan("/template", "*"))
//g.Dump(gres.Scan("/template/layout2", "*.html", true))

View File

@ -1,12 +1,13 @@
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/glog"
"fmt"
"github.com/gogf/gf/internal/utilbytes"
)
func main() {
v := g.NewVar(1)
glog.Error(v.String())
glog.Errorfln("error")
b := []byte{48, 49, 50, 51, 52, 53}
fmt.Println(string(b))
fmt.Println([]byte("\xff\xff"))
fmt.Printf(utilbytes.Export(b))
}

View File

@ -181,7 +181,7 @@ func (m *Manager) init() {
m.data = make(map[string]map[string]string)
for _, file := range files {
path = file[len(m.options.Path)+1:]
array = strings.Split(path, "/")
array = strings.Split(path, gfile.Separator)
if len(array) > 1 {
lang = array[0]
} else {

View File

@ -9,18 +9,15 @@ package utilbytes
import (
"bytes"
"strconv"
"fmt"
)
func Export(b []byte) string {
buffer := bytes.NewBuffer(nil)
buffer.WriteString("[]byte{")
for k, v := range b {
if k > 0 {
buffer.WriteByte(',')
}
buffer.WriteString(strconv.Itoa(int(v)))
buffer.WriteString(`[]byte("`)
for _, v := range b {
fmt.Fprintf(buffer, `\x%02x`, v)
}
buffer.WriteString("}")
buffer.WriteString(`")`)
return buffer.String()
}

View File

@ -284,8 +284,8 @@ func (s *Server) listDir(r *Request, f http.File) {
}
r.Response.Write(`<tr>`)
r.Response.Writef(`<td><a href="%s/%s">%s</a></td>`, r.URL.Path, name, ghtml.SpecialChars(name))
r.Response.Writef(`<td style="width:80px;text-align:center;">%s</td>`, size)
r.Response.Writef(`<td>%s</td>`, gtime.New(file.ModTime()).ISO8601())
r.Response.Writef(`<td style="width:80px;text-align:center;">%s</td>`, size)
r.Response.Write(`</tr>`)
}
r.Response.Write(`</table>`)

View File

@ -8,6 +8,8 @@ package gres
import (
"fmt"
"github.com/gogf/gf/os/gtime"
"os"
"path/filepath"
"strings"
@ -128,6 +130,8 @@ func (r *Resource) IsEmpty() bool {
// using the ',' symbol to separate multiple patterns.
//
// It scans directory recursively if given parameter <recursive> is true.
//
// Note that the returned files does not contain given parameter <path>.
func (r *Resource) ScanDir(path string, pattern string, recursive ...bool) []*File {
isRecursive := false
if len(recursive) > 0 {
@ -209,8 +213,10 @@ func (r *Resource) doScanDir(path string, pattern string, recursive bool, onlyFi
// Dump prints the files of current resource object.
func (r *Resource) Dump() {
var info os.FileInfo
r.tree.Iterator(func(key, value interface{}) bool {
fmt.Printf("%7s %s\n", gfile.FormatSize(value.(*File).FileInfo().Size()), key)
info = value.(*File).FileInfo()
fmt.Printf("%v %7s %s\n", gtime.New(info.ModTime()).ISO8601(), gfile.FormatSize(info.Size()), key)
return true
})
fmt.Printf("TOTAL FILES: %d\n", r.tree.Size())

View File

@ -10,15 +10,14 @@ import (
"testing"
"github.com/gogf/gf/debug/gdebug"
"github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/os/gres"
"github.com/gogf/gf/test/gtest"
)
func Test_Export(t *testing.T) {
gtest.Case(t, func() {
srcPath := gfile.Dir(gdebug.CallerFilePath()) + "/testdata/files"
goFilePath := gfile.Dir(gdebug.CallerFilePath()) + "/testdata/testdata.go"
srcPath := gdebug.CallerDirectory() + "/testdata/files"
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName)
gtest.Assert(err, nil)

141
os/gres/gres_unit_2_test.go Normal file
View File

@ -0,0 +1,141 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). 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,
// You can obtain one at https://github.com/gogf/gf.
package gres_test
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/test/gtest"
"testing"
"github.com/gogf/gf/os/gres"
_ "github.com/gogf/gf/os/gres/testdata"
)
func Test_Basic(t *testing.T) {
gres.Dump()
gtest.Case(t, func() {
gtest.Assert(gres.Get("/none"), nil)
gtest.Assert(gres.Contains("/none"), false)
gtest.Assert(gres.Contains("/dir1"), true)
})
gtest.Case(t, func() {
path := "/dir1/test1"
file := gres.Get(path)
gtest.AssertNE(file, nil)
gtest.Assert(file.Name(), path)
info := file.FileInfo()
gtest.AssertNE(info, nil)
gtest.Assert(info.IsDir(), false)
gtest.Assert(info.Name(), "test1")
rc, err := file.Open()
gtest.Assert(err, nil)
defer rc.Close()
b := make([]byte, 5)
n, err := rc.Read(b)
gtest.Assert(n, 5)
gtest.Assert(err, nil)
gtest.Assert(string(b), "test1")
gtest.Assert(file.Content(), "test1 content")
})
gtest.Case(t, func() {
path := "/dir2"
file := gres.Get(path)
gtest.AssertNE(file, nil)
gtest.Assert(file.Name(), path)
info := file.FileInfo()
gtest.AssertNE(info, nil)
gtest.Assert(info.IsDir(), true)
gtest.Assert(info.Name(), "dir2")
rc, err := file.Open()
gtest.Assert(err, nil)
defer rc.Close()
gtest.Assert(file.Content(), nil)
})
gtest.Case(t, func() {
path := "/dir2/test2"
file := gres.Get(path)
gtest.AssertNE(file, nil)
gtest.Assert(file.Name(), path)
gtest.Assert(file.Content(), "test2 content")
})
}
func Test_Get(t *testing.T) {
gres.Dump()
gtest.Case(t, func() {
gtest.AssertNE(gres.Get("/dir1/test1"), nil)
})
gtest.Case(t, func() {
file := gres.GetWithIndex("/dir1", g.SliceStr{"test1"})
gtest.AssertNE(file, nil)
gtest.Assert(file.Name(), "/dir1/test1")
})
gtest.Case(t, func() {
gtest.Assert(gres.GetContent("/dir1"), "")
gtest.Assert(gres.GetContent("/dir1/test1"), "test1 content")
})
}
func Test_ScanDir(t *testing.T) {
gres.Dump()
gtest.Case(t, func() {
path := "/dir1"
files := gres.ScanDir(path, "*", false)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 2)
})
gtest.Case(t, func() {
path := "/dir1"
files := gres.ScanDir(path, "*", true)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 3)
})
gtest.Case(t, func() {
path := "/dir1"
files := gres.ScanDir(path, "*.*", true)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 1)
gtest.Assert(files[0].Name(), "/dir1/sub/sub-test1.txt")
gtest.Assert(files[0].Content(), "sub-test1 content")
})
}
func Test_ScanDirFile(t *testing.T) {
gres.Dump()
gtest.Case(t, func() {
path := "/dir2"
files := gres.ScanDirFile(path, "*", false)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 1)
})
gtest.Case(t, func() {
path := "/dir2"
files := gres.ScanDirFile(path, "*", true)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 2)
})
gtest.Case(t, func() {
path := "/dir2"
files := gres.ScanDirFile(path, "*.*", true)
gtest.AssertNE(files, nil)
gtest.Assert(len(files), 1)
gtest.Assert(files[0].Name(), "/dir2/sub/sub-test2.txt")
gtest.Assert(files[0].Content(), "sub-test2 content")
})
}

View File

@ -0,0 +1 @@
sub-test1 content

View File

@ -1 +1 @@
test1 content
test1 content

View File

@ -0,0 +1 @@
sub-test2 content

View File

@ -1 +1 @@
test2 content
test2 content

File diff suppressed because one or more lines are too long