add example for package gres

This commit is contained in:
John
2020-03-28 21:32:29 +08:00
parent 4c610b4f58
commit 8ecd62d3de
10 changed files with 61 additions and 40 deletions

View File

@ -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))
}

View File

@ -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()
}

View File

@ -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)
}
}