diff --git a/.example/os/gres/gres.go b/.example/os/gres/gres.go deleted file mode 100644 index 13ac19252..000000000 --- a/.example/os/gres/gres.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata" -) - -func main() { - gres.Dump() - //file := gres.Get("www") - //fmt.Println(file.Open()) - //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)) -} diff --git a/.example/os/gres/gres_example.go b/.example/os/gres/gres_example.go new file mode 100644 index 000000000..767583927 --- /dev/null +++ b/.example/os/gres/gres_example.go @@ -0,0 +1,19 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" + _ "github.com/gogf/gf/os/gres/testdata/example/boot" +) + +func main() { + s := g.Server() + s.Group("/", func(group *ghttp.RouterGroup) { + group.GET("/template", func(r *ghttp.Request) { + r.Response.WriteTplDefault(g.Map{ + "name": "GoFrame", + }) + }) + }) + s.Run() +} diff --git a/.example/other/test.go b/.example/other/test.go index d9dc550f4..d9382c9d3 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,31 +1,25 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gins" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/crypto/gaes" + "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/os/gres" ) -func getNameLogger(name, path string) *glog.Logger { - inst := gins.Get(name) - if inst == nil { - logger := g.Log(name) - logConf := map[string]interface{}{ - "Path": path, - "Level": "ALL", - } - if err := logger.SetConfigWithMap(logConf); err != nil { - panic(err) - } - return logger - } - return inst.(*glog.Logger) -} +var ( + CryptoKey = []byte("x76cgqt36i9c863bzmotuf8626dxiwu0") +) func main() { - alog := getNameLogger("logger.日志1", "c:/logger1") - alog.Print(1) - - blog := getNameLogger("logger.日志2", "c:/logger2") - blog.Print(2) + binContent, err := gres.Pack("public,config") + if err != nil { + panic(err) + } + binContent, err = gaes.Encrypt(binContent, CryptoKey) + if err != nil { + panic(err) + } + if err := gfile.PutBytes("data.bin", binContent); err != nil { + panic(err) + } } diff --git a/os/gres/gres_unit_1_test.go b/os/gres/gres_z_unit_1_test.go similarity index 100% rename from os/gres/gres_unit_1_test.go rename to os/gres/gres_z_unit_1_test.go diff --git a/os/gres/gres_unit_2_test.go b/os/gres/gres_z_unit_2_test.go similarity index 99% rename from os/gres/gres_unit_2_test.go rename to os/gres/gres_z_unit_2_test.go index d4b01bb52..f051f952b 100644 --- a/os/gres/gres_unit_2_test.go +++ b/os/gres/gres_z_unit_2_test.go @@ -7,13 +7,14 @@ package gres_test import ( + _ "github.com/gogf/gf/os/gres/testdata/data" + "testing" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/test/gtest" "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata/data" ) func Test_Basic(t *testing.T) { diff --git a/os/gres/testdata/example/boot/data.go b/os/gres/testdata/example/boot/data.go new file mode 100644 index 000000000..4269a270a --- /dev/null +++ b/os/gres/testdata/example/boot/data.go @@ -0,0 +1,9 @@ +package boot + +import "github.com/gogf/gf/os/gres" + +func init() { + if err := gres.Add("1f8b08000000000002ff0af066661161e060606048cea809604002420c9c0cc9f9796999e9fa104aaf243f37273484958191cbbb3e8e2bba38b5a82cb528964b414141c13125a528b5b818c4b45550b2b2b0b0b050024b04831505e5e79780240a4a9372329395b8b8a2cb3253cb619a5d52d3124b734adc327352418a32f352522bf44a0a7294a0b23999b99925a945c520b315a29554aa957414946a9562b9b8b8b802bcd939b81c64d7b63330308030c23fad68fe6183fb07ec072feffa389066642508cdd6e9a89a05193819208ed787382fa3041a16973cebe33c527372f21541a6859dd19acb06b68c905320a611e1940c2cf152929a5b90935892aa0f0f2bb041a2de50b728a854ebe525e6a6d6821d75255b6e263f0303033f5e477120998bc7598c4c22cc8804831cf42087c1c09246108927f9201b842d7860c1cee070016e1092ab109a4131851cea8228aee06564c0136fc43b221a6e0e564780e2083994518362062303be18c3e70a0e14577c403208c91dac6c1007b3314c666460d06702f100010000ffffc7c852f1d8030000"); err != nil { + panic(err) + } +} diff --git a/os/gres/testdata/example/files/config/config.toml b/os/gres/testdata/example/files/config/config.toml new file mode 100644 index 000000000..a8544540d --- /dev/null +++ b/os/gres/testdata/example/files/config/config.toml @@ -0,0 +1,11 @@ + +[server] + Address = ":8888" + ServerRoot = "public" + +[viewer] + DefaultFile = "index.tpl" + Delimiters = ["${", "}"] + + + diff --git a/os/gres/testdata/example/files/public/index.html b/os/gres/testdata/example/files/public/index.html new file mode 100644 index 000000000..05a682bd4 --- /dev/null +++ b/os/gres/testdata/example/files/public/index.html @@ -0,0 +1 @@ +Hello! \ No newline at end of file diff --git a/os/gres/testdata/example/files/template/index.tpl b/os/gres/testdata/example/files/template/index.tpl new file mode 100644 index 000000000..962aff629 --- /dev/null +++ b/os/gres/testdata/example/files/template/index.tpl @@ -0,0 +1 @@ +Hello ${.name}! \ No newline at end of file diff --git a/util/gutil/gutil_map.go b/util/gutil/gutil_map.go index 0b5d7e0dd..960b7282b 100644 --- a/util/gutil/gutil_map.go +++ b/util/gutil/gutil_map.go @@ -40,6 +40,7 @@ func MapPossibleItemByKey(data map[string]interface{}, key string) (string, inte } // Loop for check. for k, v := range data { + // Remove all special chars and compare with case insensitive. if strings.EqualFold(replaceCharReg.ReplaceAllString(k, ""), replacedKey) { return k, v }