diff --git a/.gitignore b/.gitignore index 3963131..d7c3743 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ .idea -*.exe -config.yaml -test \ No newline at end of file +*.exe \ No newline at end of file diff --git a/@doc/faq.md b/@doc/faq.md index c2dd5fd..a4c43d6 100644 --- a/@doc/faq.md +++ b/@doc/faq.md @@ -2,6 +2,6 @@ 1. 这东西有什么用? 2. 我的接口业务流程很复杂怎么处理? -3. 你知道graphql吗? +3. 知道graphql吗? 4. 如何完成文件上传下载、微信支付等操作? 5. 我项目中没有使用goframe, 会有gin、beego等框架的版本吗? \ No newline at end of file diff --git a/drivers/framework_goframe/gf.go b/drivers/framework_goframe/gf.go index 77df9aa..f8a1525 100644 --- a/drivers/framework_goframe/gf.go +++ b/drivers/framework_goframe/gf.go @@ -27,6 +27,22 @@ func New(a *apijson.ApiJson) *GF { } } +func (gf *GF) Run(s ...*ghttp.Server) { + + var server *ghttp.Server + + if len(s) == 0 { + server = g.Server("apijson") + } else { + server = s[0] + } + + server.Group("/", func(group *ghttp.RouterGroup) { + gf.Bind(group) + }) + server.Run() +} + func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) { if len(mode) == 0 { mode = []Mode{InDataMode} @@ -38,11 +54,11 @@ func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) { group.POST("/delete", gf.commonResponse(gf.Delete, mode[0])) } -func (g *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) { +func (gf *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) { q := query.New(ctx, req) - q.NoAccessVerify = g.apijson.Config().Access.NoVerify - q.Access = g.apijson.Config().Access - q.AccessCondition = g.apijson.Config().Access.ConditionFunc + q.NoAccessVerify = gf.apijson.Config().Access.NoVerify + q.Access = gf.apijson.Config().Access + q.AccessCondition = gf.apijson.Config().Access.ConditionFunc return q.Result() } diff --git a/test/config.toml b/test/config.toml new file mode 100644 index 0000000..a670c08 --- /dev/null +++ b/test/config.toml @@ -0,0 +1,15 @@ +[server] + address = ":8091" + dumpRouterMap = false + debug = false + +[logger] + level = "info" + +[database.logger] + level = "all" + stdout = true + +[database.default] + debug = true + link = "sqlite::@file(./db.sqlite3)" diff --git a/test/test.http b/test/test.http new file mode 100644 index 0000000..5afa735 --- /dev/null +++ b/test/test.http @@ -0,0 +1,7 @@ +### list +POST http://localhost:8091/get +Content-Type: application/json + +{ + "t_todo": {} +} \ No newline at end of file diff --git a/test/z_app_test.go b/test/z_app_test.go new file mode 100644 index 0000000..e6e72c8 --- /dev/null +++ b/test/z_app_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "context" + "github.com/glennliao/apijson-go" +) + +type User struct { +} + +type Todo struct { +} + +func App(ctx context.Context, a *apijson.ApiJson) { + +} diff --git a/test/z_main_test.go b/test/z_main_test.go new file mode 100644 index 0000000..18d6ff9 --- /dev/null +++ b/test/z_main_test.go @@ -0,0 +1,72 @@ +package main + +import ( + "github.com/glennliao/apijson-go" + _ "github.com/glennliao/apijson-go/drivers/executor/goframe" // need import for executor with goframe + "github.com/glennliao/apijson-go/drivers/framework_goframe" + "github.com/glennliao/apijson-go/model" + "github.com/glennliao/apijson-go/query" + _ "github.com/gogf/gf/contrib/drivers/sqlite/v2" // need import for sqlite + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" + "testing" +) + +var a *apijson.ApiJson + +func init() { + a = apijson.Load(App) +} + +// notice: import section +func TestServer(t *testing.T) { + s := framework_goframe.New(a) + s.Run() + // then test in test.http +} + +func TestQuery(t *testing.T) { + + ctx := gctx.New() + q := query.New(ctx, model.Map{ + "t_user": model.Map{ + "id": "123", + "id{}": []string{"123", "456"}, + "id>": "222", + "@column": "id,userId", + }, + "t_user[]": model.Map{ + //"userId": "123", + }, + //"t_todo": model.Map{}, + //"_access": model.Map{}, + }) + + q.NoAccessVerify = true //config.AccessVerify + q.Access = a.Config().Access + + result, err := q.Result() + + if err != nil { + panic(err) + } + + g.Dump(result) + +} + +func BenchmarkName(b *testing.B) { + for i := 0; i < b.N; i++ { + ctx := gctx.New() + + q := query.New(ctx, model.Map{ + "Todo": model.Map{}, + "User": model.Map{}, + }) + + _, err := q.Result() + if err != nil { + panic(err) + } + } +}