Merge pull request #7 from gogf/master

sync master
This commit is contained in:
HaiLaz
2019-09-11 16:40:27 +08:00
committed by GitHub
1984 changed files with 26352 additions and 545490 deletions

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/garray"
"github.com/gogf/gf/container/garray"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/garray"
"github.com/gogf/gf/container/garray"
)
func main() {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/garray"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/garray"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/garray"
"strings"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,13 +2,14 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gmap"
"github.com/gogf/gf/container/gmap"
)
func main() {
// 创建一个默认的gmap对象
// 默认情况下该gmap对象支持并发安全特性
// 初始化时可以给定false参数关闭并发安全特性当做一个普通的map使用。
// 默认情况下该gmap对象支持并发安全特性,
// 初始化时可以给定true参数关闭并发安全特性当做一个普通的map使用。
m := gmap.New()
// 设置键值对

View File

@ -0,0 +1,24 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gmap"
)
func main() {
//m := gmap.New()
//m.Set("k", "v")
//m.Set("1", "2")
//b, err := json.Marshal(m)
//fmt.Println(err)
//fmt.Println(string(b))
m := gmap.NewIntIntMap()
m.Set(1, 2)
m.Set(3, 4)
b, err := json.Marshal(m)
fmt.Println(err)
fmt.Println(string(b))
}

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/gmap"
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/gmap"
"github.com/gogf/gf/g/util/gutil"
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gutil"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gmap"
"github.com/gogf/gf/g/util/gutil"
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/util/gutil"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gpool"
"time"
"github.com/gogf/gf/container/gpool"
)
func main() {

View File

@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gpool"
"github.com/gogf/gf/g/net/gtcp"
"github.com/gogf/gf/g/os/glog"
"time"
"github.com/gogf/gf/container/gpool"
"github.com/gogf/gf/net/gtcp"
"github.com/gogf/gf/os/glog"
)
func main() {

View File

@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gqueue"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/g/os/gtimer"
"time"
"github.com/gogf/gf/container/gqueue"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
)
func main() {

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gqueue"
"github.com/gogf/gf/g/os/gtimer"
"time"
"github.com/gogf/gf/container/gqueue"
"github.com/gogf/gf/os/gtimer"
)
func main() {

View File

@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gqueue"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/g/os/gtimer"
"time"
"github.com/gogf/gf/container/gqueue"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gring"
"github.com/gogf/gf/container/gring"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gring"
"github.com/gogf/gf/container/gring"
)
type Player struct {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gset"
"github.com/gogf/gf/container/gset"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/container/gset"
"github.com/gogf/gf/container/gset"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gtree"
"github.com/gogf/gf/g/util/gutil"
"github.com/gogf/gf/container/gtree"
"github.com/gogf/gf/util/gutil"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gtree"
"github.com/gogf/gf/container/gtree"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gtree"
"github.com/gogf/gf/g/util/gutil"
"github.com/gogf/gf/container/gtree"
"github.com/gogf/gf/util/gutil"
)
func main() {

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/gogf/gf/g/container/gtree"
"github.com/gogf/gf/container/gtree"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/container/gtype"
"github.com/gogf/gf/container/gtype"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -4,7 +4,7 @@ import (
"fmt"
_ "github.com/denisenkom/go-mssqldb"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -5,8 +5,8 @@ import (
"time"
//_ "github.com/denisenkom/go-mssqldb"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
// 本文件用于gf框架的mssql数据库操作示例不作为单元测试使用
@ -27,7 +27,7 @@ func init() {
})
db, _ = gdb.New()
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/frame")
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/frame")
//db = g.Database()
//gdb.SetConfig(gdb.ConfigNode {

View File

@ -0,0 +1,5 @@
# MySQL数据库配置
[database]
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"

View File

@ -4,8 +4,8 @@ import (
"fmt"
"time"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
// 本文件用于gf框架的mysql数据库操作示例不作为单元测试使用
@ -26,7 +26,7 @@ func init() {
})
db, _ = gdb.New()
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/frame")
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/frame")
//db = g.Database()
//gdb.SetConfig(gdb.ConfigNode {

View File

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {
@ -17,4 +17,7 @@ func main() {
"id in(?)": g.Slice{1, 2, 3},
}
db.Table("user").Where(conditions).OrderBy("id asc").All()
var params []interface{}
db.Table("user").Where("1=1", params).OrderBy("id asc").All()
}

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/crypto/gaes"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/crypto/gaes"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -0,0 +1,20 @@
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
)
func main() {
db := g.DB()
db.SetDebug(true)
r, e := db.Table("test").All()
if e != nil {
panic(e)
}
if r != nil {
fmt.Println(r.ToList())
}
}

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/g/util/gutil"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/util/gutil"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
)
func main() {

View File

@ -3,9 +3,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/g/os/glog"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/glog"
)
func main() {

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"time"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -0,0 +1,50 @@
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
)
var (
tableName = "orders"
dao = g.DB().Table(tableName).Safe()
)
type OrderServiceEntity struct {
GoodsPrice float64 `json:"goods_price" gvalid:"required"`
PayTo int8 `json:"payTo" gvalid:"required"`
PayStatus int8 `json:"payStatus" `
CreateTime string `json:"createTime" `
AppId string `json:"appId" gvalid:"required"`
PayUser string `json:"pay_user" gvalid:"required"`
QrUrl string `json:"qr_url" `
}
type Create struct {
Id int64 `json:"id" gconv:"id"`
GoodsPrice float64 `json:"goodsPrice" gconv:"goods_price"`
PayTo int8 `json:"payTo" gconv:"pay_to"`
PayStatus int8 `json:"payStatus" gconv:"pay_status"`
CreateTime string `json:"createTime" gconv:"create_time"`
UserId int `json:"user_id" `
PayUser string `json:"pay_user" `
QrUrl string `json:"qr_url" `
}
func main() {
g.DB().SetDebug(true)
userInfo := Create{
Id: 3,
}
orderService := OrderServiceEntity{
GoodsPrice: 0.1,
PayTo: 1,
}
size, err := dao.Where("user_id", userInfo.Id).
And("goods_price", float64(100.10)).
And("pay_status", 0).
And("pay_to", orderService.PayTo).Count()
fmt.Println(err)
fmt.Println(size)
}

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/g/encoding/gparser"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/encoding/gparser"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -1,8 +1,9 @@
package main
import (
"github.com/gogf/gf/g"
"time"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -0,0 +1,18 @@
package main
import (
"github.com/gogf/gf/frame/g"
)
func main() {
db := g.DB()
db.SetDebug(true)
tables, err := db.Tables()
if err != nil {
panic(err)
}
if tables != nil {
g.Dump(tables)
}
}

View File

@ -0,0 +1,25 @@
package main
import (
"github.com/gogf/gf/frame/g"
)
func main() {
db := g.DB()
db.SetDebug(true)
tables, e := db.Tables()
if e != nil {
panic(e)
}
if tables != nil {
g.Dump(tables)
for _, table := range tables {
fields, err := db.TableFields(table)
if err != nil {
panic(err)
}
g.Dump(fields)
}
}
}

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -5,8 +5,8 @@ import (
"time"
//_ "github.com/mattn/go-oci8"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/database/gdb"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
// 本文件用于gf框架的mysql数据库操作示例不作为单元测试使用
@ -26,7 +26,7 @@ func init() {
})
db, _ = gdb.New()
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/frame")
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/frame")
//db = g.Database()
//gdb.SetConfig(gdb.ConfigNode {

View File

@ -1,9 +1,9 @@
package main
//import (
// _ "github.com/gogf/gf/third/github.com/mattn/go-sqlite3"
// "github.com/gogf/gf/g/database/gdb"
// "github.com/gogf/gf/g"
// _ "github.com/mattn/go-sqlite3"
// "github.com/gogf/gf/database/gdb"
// "github.com/gogf/gf/frame/g"
// "fmt"
//)
//

View File

@ -0,0 +1,18 @@
package main
import (
"log"
"github.com/dgraph-io/badger"
)
func main() {
// Open the Badger database located in the /tmp/badger directory.
// It will be created if it doesn't exist.
db, err := badger.Open(badger.DefaultOptions("/tmp/badger"))
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Your code here…
}

View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"time"
"github.com/gogf/gf/database/gkvdb"
)
func main() {
key := []byte("key")
value := []byte("value")
db := gkvdb.Instance()
db.SetPath("/tmp/gkvdb/test")
db.Set(key, value)
fmt.Println(db.Get(key))
time.Sleep(time.Hour)
}

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/database/gredis"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/database/gredis"
"github.com/gogf/gf/util/gconv"
)
// 使用原生gredis.New操作redis但是注意需要自己调用Close方法关闭redis链接池

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
// 使用框架封装的g.Redis()方法获得redis操作对象单例不需要开发者显示调用Close方法

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -0,0 +1,60 @@
package main
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/os/gcmd"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/database/gredis"
"github.com/gogf/gf/frame/g"
)
func main() {
batchNumber := 1000
redis1Config, err := gredis.ConfigFromStr("im-redis-slave:6379,9")
if err != nil {
panic(err)
}
redis2Config, err := gredis.ConfigFromStr("r-bp1f0a5d4efd8744.redis.rds.aliyuncs.com:6379,9")
if err != nil {
panic(err)
}
gredis.SetConfig(redis1Config)
v, err := g.Redis().DoVar("keys", "*")
if err != nil {
panic(err)
}
array := garray.NewStrArrayFrom(v.Strings())
for {
slice := array.PopLefts(batchNumber)
if len(slice) > 0 {
// `migrate %s %d "" 0 2000 copy replace auth %s keys %s`,
params := g.Slice{
redis2Config.Host,
redis2Config.Port,
"",
redis2Config.Db,
2000,
"copy",
"replace",
"keys",
}
params = append(params, gconv.Interfaces(slice)...)
fmt.Println(params)
if gcmd.GetOpt("dryrun") == "0" {
if v, err := g.Redis().DoVar("migrate", params...); err != nil {
panic(err)
} else {
fmt.Println(v.String())
}
}
} else {
break
}
}
fmt.Println("done")
}

View File

@ -0,0 +1,11 @@
package main
import (
"fmt"
"github.com/gogf/gf/debug/gdebug"
)
func main() {
fmt.Println(gdebug.CallerPackage())
fmt.Println(gdebug.CallerFunction())
}

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gbase64"
"github.com/gogf/gf/encoding/gbase64"
)
func main() {

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gbinary"
"github.com/gogf/gf/g/os/glog"
"github.com/gogf/gf/encoding/gbinary"
"github.com/gogf/gf/os/glog"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gbinary"
"github.com/gogf/gf/encoding/gbinary"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gbinary"
"github.com/gogf/gf/encoding/gbinary"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/frame/g"
)
func main() {

View File

@ -2,7 +2,8 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gcharset"
"github.com/gogf/gf/encoding/gcharset"
)
func main() {

View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gcompress"
)
func main() {
err := gcompress.UnZipFile(
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg\encoding\gcompress\data.zip`,
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg`,
)
fmt.Println(err)
}

View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gcompress"
"github.com/gogf/gf/os/gfile"
)
func main() {
err := gcompress.UnZipContent(
gfile.GetBytes(`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg\encoding\gcompress\data.zip`),
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg`,
)
fmt.Println(err)
}

View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gcompress"
)
func main() {
err := gcompress.ZipPath(
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg`,
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg\encoding\gcompress\data.zip`,
"my-dir",
)
fmt.Println(err)
}

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/ghash"
"strconv"
"github.com/gogf/gf/encoding/ghash"
)
func main() {

View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gini"
)
func main() {
s := `
a = b
`
m, err := gini.Decode([]byte(s))
fmt.Println(err)
fmt.Println(m)
}

View File

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gjson"
"github.com/gogf/gf/g/os/glog"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/os/gtime"
)
func getByPattern() {

View File

@ -0,0 +1,156 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/encoding/gjson"
)
type XinYanModel struct {
Success bool `json:"success"`
Data Data `json:"data"`
ErrorCode interface{} `json:"errorCode"`
ErrorMsg interface{} `json:"errorMsg"`
}
type ApplyReportDetail struct {
ApplyScore string `json:"apply_score"`
ApplyCredibility string `json:"apply_credibility"`
QueryOrgCount string `json:"apply_query_org_count"`
QueryFinanceCount string `json:"apply_query_finance_count"`
QueryCashCount string `json:"apply_query_cash_count"`
QuerySumCount string `json:"apply_query_sum_count"`
LatestQueryTime string `json:"apply_latest_query_time"`
LatestOneMonth string `json:"apply_latest_one_month"`
LatestThreeMonth string `json:"apply_latest_three_month"`
LatestSixMonth string `json:"apply_latest_six_month"`
}
type BehaviorReportDetail struct {
LoansScore string `json:"behavior_report_detailloans_score"`
LoansCredibility string `json:"behavior_report_detailloans_credibility"`
LoansCount string `json:"behavior_report_detailloans_count"`
LoansSettleCount string `json:"behavior_report_detailloans_settle_count"`
LoansOverdueCount string `json:"behavior_report_detailloans_overdue_count"`
LoansOrgCount string `json:"behavior_report_detailloans_org_count"`
ConsfinOrgCount string `json:"behavior_report_detailconsfin_org_count"`
LoansCashCount string `json:"behavior_report_detailloans_cash_count"`
LatestOneMonth string `json:"behavior_report_detaillatest_one_month"`
LatestThreeMonth string `json:"behavior_report_detaillatest_three_month"`
LatestSixMonth string `json:"behavior_report_detaillatest_six_month"`
HistorySucFee string `json:"behavior_report_detailhistory_suc_fee"`
HistoryFailFee string `json:"behavior_report_detailhistory_fail_fee"`
LatestOneMonthSuc string `json:"behavior_report_detaillatest_one_month_suc"`
LatestOneMonthFail string `json:"behavior_report_detaillatest_one_month_fail"`
LoansLongTime string `json:"behavior_report_detailloans_long_time"`
LoansLatestTime string `json:"behavior_report_detailloans_latest_time"`
}
type CurrentReportDetail struct {
LoansCreditLimit string `json:"current_report_detailloans_credit_limit"`
LoansCredibility string `json:"current_report_detailloans_credibility"`
LoansOrgCount string `json:"current_report_detailloans_org_count"`
LoansProductCount string `json:"current_report_detailloans_product_count"`
LoansMaxLimit string `json:"current_report_detailloans_max_limit"`
LoansAvgLimit string `json:"current_report_detailloans_avg_limit"`
ConsfinCreditLimit string `json:"current_report_detailconsfin_credit_limit"`
ConsfinCredibility string `json:"current_report_detailconsfin_credibility"`
ConsfinOrgCount string `json:"current_report_detailconsfin_org_count"`
ConsfinProductCount string `json:"current_report_detailconsfin_product_count"`
ConsfinMaxLimit string `json:"current_report_detailconsfin_max_limit"`
ConsfinAvgLimit string `json:"current_report_detailconsfin_avg_limit"`
}
type ResultDetail struct {
ApplyReportDetail ApplyReportDetail `json:"apply_report_detail"`
BehaviorReportDetail BehaviorReportDetail `json:"behavior_report_detail"`
CurrentReportDetail CurrentReportDetail `json:"current_report_detail"`
}
type Data struct {
Code string `json:"code"`
Desc string `json:"desc1"`
TransID string `json:"trans_id"`
TradeNo string `json:"trade_no"`
Fee string `json:"fee"`
IDNo string `json:"id_no"`
IDName string `json:"id_name"`
Versions string `json:"versions"`
ResultDetail ResultDetail `json:"result_detail"`
}
var data = `{
"success": true,
"data": {
"code": "0",
"desc": "查询成功",
"trans_id": "14910304379231213",
"trade_no": "201704011507240100057329",
"fee": "Y",
"id_no": "0783231bcc39f4957e99907e02ae401c",
"id_name": "dd67a5943781369ddd7c594e231e9e70 ",
"versions": "1.0.0",
"result_detail":{
"apply_report_detail": {
"apply_score": "189",
"apply_credibility": "84",
"query_org_count": "7",
"query_finance_count": "2",
"query_cash_count": "2",
"query_sum_count": "13",
"latest_query_time": "2017-09-03",
"latest_one_month": "1",
"latest_three_month": "5",
"latest_six_month": "12"
},
"behavior_report_detail": {
"loans_score": "199",
"loans_credibility": "90",
"loans_count": "300",
"loans_settle_count": "280",
"loans_overdue_count": "20",
"loans_org_count": "5",
"consfin_org_count": "3",
"loans_cash_count": "2",
"latest_one_month": "3",
"latest_three_month": "20",
"latest_six_month": "23",
"history_suc_fee": "30",
"history_fail_fee": "25",
"latest_one_month_suc": "5",
"latest_one_month_fail": "20",
"loans_long_time": "130",
"loans_latest_time": "2017-09-16"
},
"current_report_detail": {
"loans_credit_limit": "1400",
"loans_credibility": "80",
"loans_org_count": "7",
"loans_product_count": "8",
"loans_max_limit": "2000",
"loans_avg_limit": "1000",
"consfin_credit_limit": "1500",
"consfin_credibility": "90",
"consfin_org_count": "8",
"consfin_product_count": "5",
"consfin_max_limit": "5000",
"consfin_avg_limit": "3000"
}
}
},
"errorCode": null,
"errorMsg": null
}`
func main() {
struct1 := new(XinYanModel)
err := json.Unmarshal([]byte(data), struct1)
fmt.Println(err)
fmt.Println(struct1)
fmt.Println()
struct2 := new(XinYanModel)
j, err := gjson.DecodeToJson(data)
fmt.Println(err)
fmt.Println(j.Get("data.desc"))
err = j.ToStruct(struct2)
fmt.Println(err)
fmt.Println(struct2)
}

View File

@ -0,0 +1,69 @@
package main
import (
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/glog"
)
type GameUser struct {
Uid int `json:"uid"`
Account string `json:"account"`
Tel string `json:"tel"`
Role string `json:"role"`
Vip int `json:"vip"`
GameLevel int `json:"gamelevel"`
Diamond int `json:"diamond"`
Coin int `json:"coin"`
Value int `json:"value"`
Area string `json:"area"`
ServerName string `json:"servername"`
Time int `json:"time"`
ClientInfo *ClientInfo `json:"client_info"`
}
type ClientInfo struct {
ClientGuid string `json:"client_guid"`
ClientType int `json:"client_type"`
ClientSDKVersion string `json:"client_sdk_version"`
ClientVersion string `json:"client_version"`
PackageId string `json:"packageid"`
PhoneType string `json:"phone_type"`
DevicesId string `json:"devices_id"`
ClientMac string `json:"client_mac"`
}
func main() {
s := `{
"uid":9527,
"account":"zhangsan",
"tel":"15248787",
"role":"test",
"vip":7,
"gamelevel":59,
"diamond ":59,
"coin ":59,
"value ":99,
"area":"s",
"servername":"灵动",
"time":15454878787,
"client_info": {
"client_guid": "aaaa",
"client_type": 1,
"client_sdk_version": "1.0.1",
"client_version": "1.0.1",
"packageid":"",
"phone_type": "vivi",
"devices_id":"",
"client_mac":""
}
}`
gameUser := &GameUser{}
err := gjson.DecodeTo(s, gameUser)
if err != nil {
glog.Error(err)
}
g.Dump(gameUser)
}

View File

@ -2,8 +2,9 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/encoding/gparser"
"github.com/gogf/gf/g/os/glog"
"github.com/gogf/gf/encoding/gparser"
"github.com/gogf/gf/os/glog"
)
func getWithPattern1() {

View File

@ -1,6 +1,6 @@
package main
import "github.com/gogf/gf/g/encoding/gparser"
import "github.com/gogf/gf/encoding/gparser"
func main() {
xml := `<?xml version="1.0" encoding="GBK"?>

View File

@ -0,0 +1,30 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gyaml"
)
func main() {
var yamlStr string = `
#即表示url属性值
url: http://www.wolfcode.cn
#即表示server.host属性的值
server:
host: http://www.wolfcode.cn
#数组即表示server为[a,b,c]
server:
- 120.168.117.21
- 120.168.117.22
- 120.168.117.23
#常量
pi: 3.14 #定义一个数值3.14
hasChild: true #定义一个boolean值
name: '你好YAML' #定义一个字符串
`
i, err := gyaml.Decode([]byte(yamlStr))
fmt.Println(err)
fmt.Println(i)
}

View File

@ -4,15 +4,15 @@ import (
"errors"
"fmt"
"github.com/gogf/gf/g/errors/gerror"
"github.com/gogf/gf/errors/gerror"
)
func Error1() error {
return errors.New("test")
return errors.New("test1")
}
func Error2() error {
return gerror.New("test")
return gerror.New("test2")
}
func main() {

View File

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gogf/gf/g/errors/gerror"
"github.com/gogf/gf/errors/gerror"
)
func OpenFile() error {

View File

@ -4,15 +4,15 @@ import (
"errors"
"fmt"
"github.com/gogf/gf/g/errors/gerror"
"github.com/gogf/gf/errors/gerror"
)
func Error1() error {
return errors.New("test")
return errors.New("test1")
}
func Error2() error {
return gerror.New("test")
return gerror.New("test2")
}
func main() {

View File

@ -0,0 +1,23 @@
package main
import (
"fmt"
"github.com/gogf/gf/errors/gerror"
)
func OpenFile() error {
return gerror.New("permission denied")
}
func OpenConfig() error {
return gerror.Wrap(OpenFile(), "configuration file opening failed")
}
func ReadConfig() error {
return gerror.Wrap(OpenConfig(), "reading configuration failed")
}
func main() {
fmt.Println(gerror.Cause(ReadConfig()))
}

View File

@ -0,0 +1,22 @@
package main
import (
"errors"
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/errors/gerror"
)
func Error1() error {
return errors.New("test1")
}
func Error2() error {
return gerror.New("test2")
}
func main() {
glog.Println(Error1())
glog.Println(Error2())
}

View File

@ -0,0 +1,4 @@
# MySQL数据库配置
[database]
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"

View File

@ -0,0 +1,13 @@
package main
import (
"github.com/gogf/gf/.example/frame/mvc/model/test"
"github.com/gogf/gf/frame/g"
)
func main() {
g.DB().SetDebug(true)
user, err := test.ModelUser().One()
g.Dump(err)
g.Dump(user)
}

View File

@ -0,0 +1,4 @@
viewpath = "/home/www/templates"
[redis]
disk = "127.0.0.1:6379,0"
cache = "127.0.0.1:6379,1"

View File

@ -1,8 +1,8 @@
package demo
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func init() {

View File

@ -1,8 +1,8 @@
package demo
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
type Order struct{}

Some files were not shown because too many files have changed in this diff Show More