From f5b7f5c9e355efdf7196ccf409ad2f8e523c6c58 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 24 Dec 2024 11:36:40 +0800 Subject: [PATCH 1/7] fix: typo uer -> user --- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- ...\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index d819b0aa42e..5a2a018e4e3 100644 --- "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -45,7 +45,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} diff --git "a/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index d4f2a8a7f07..8af22176a37 100644 --- "a/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -42,7 +42,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} diff --git "a/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index d4f2a8a7f07..8af22176a37 100644 --- "a/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -42,7 +42,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} diff --git "a/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index 2b3e7d74995..50afeef8217 100644 --- "a/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -42,7 +42,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} diff --git "a/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index 2b3e7d74995..50afeef8217 100644 --- "a/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -42,7 +42,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} diff --git "a/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" "b/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" index 80233a32187..b54e9cb2e7b 100644 --- "a/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" +++ "b/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\346\234\200\344\275\263\345\256\236\350\267\265/\345\210\251\347\224\250\346\214\207\351\222\210\345\261\236\346\200\247\345\222\214do\345\257\271\350\261\241\345\256\236\347\216\260\347\201\265\346\264\273\347\232\204\344\277\256\346\224\271\346\216\245\345\217\243.md" @@ -45,7 +45,7 @@ const ( ```go type User struct { - g.Meta `table:"uer" orm:"do:true"` + g.Meta `table:"user" orm:"do:true"` Id interface{} Passport interface{} Password interface{} From 9f446da6eecd600f4f5c37b293765da907c91942 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 25 Dec 2024 10:13:35 +0800 Subject: [PATCH 2/7] fix: r.GetString(xxx) -> r.Get(xxx).String() --- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- ...214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 1cc173c1a7b..72825279377 100644 --- "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -320,7 +320,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index ad87efee7ca..4c5e083d901 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -320,7 +320,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-1.16.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-1.16.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index af145094971..06d476b13b2 100644 --- "a/versioned_docs/version-1.16.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-1.16.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -283,7 +283,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.0.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.0.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.0.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.0.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.1.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.1.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.1.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.1.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.2.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.2.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.2.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.2.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.3.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.4.x/\346\240\270\345\277\203\347\273\204\344\273\266-\351\207\215\347\202\271/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.5.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 6c6b5b87e6e..5daa901ed31 100644 --- "a/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.6.x/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -316,7 +316,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { diff --git "a/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" "b/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" index 1cc173c1a7b..72825279377 100644 --- "a/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" +++ "b/versioned_docs/version-2.7.x/docs/\346\240\270\345\277\203\347\273\204\344\273\266/I18N\345\233\275\351\231\205\345\214\226/I18N\345\233\275\351\231\205\345\214\226-\344\275\277\347\224\250\344\273\213\347\273\215.md" @@ -320,7 +320,7 @@ func main() { s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String())) r.Middleware.Next() }) group.ALL("/", func(r *ghttp.Request) { From a9d7ee05de96fff9b89bc162ae593b06f18d69c8 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 25 Dec 2024 17:11:57 +0800 Subject: [PATCH 3/7] nav updates --- docusaurus.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 86ec3b9eb7a..516afc9f2aa 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -136,7 +136,7 @@ const config: Config = { position: 'left', label: '开发手册', sidebarId: 'mainSidebar', - to: '/docs/cli', + to: '/docs/core', }, { sidebarId: 'courseSidebar', From 81c0ac5a2955b484405f75d723e81b9ec657b983 Mon Sep 17 00:00:00 2001 From: Wlynxg Date: Thu, 26 Dec 2024 21:55:31 +0800 Subject: [PATCH 4/7] =?UTF-8?q?docs:=20gcmd=20`default|d`=20=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E4=BB=8B=E7=BB=8D=20(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...273\223\346\236\204\345\214\226\345\217\202\346\225\260.md" | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\345\221\275\344\273\244\347\256\241\347\220\206/\345\221\275\344\273\244\347\256\241\347\220\206-\347\273\223\346\236\204\345\214\226\345\217\202\346\225\260.md" "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\345\221\275\344\273\244\347\256\241\347\220\206/\345\221\275\344\273\244\347\256\241\347\220\206-\347\273\223\346\236\204\345\214\226\345\217\202\346\225\260.md" index 91683faf733..a5d30e34818 100644 --- "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\345\221\275\344\273\244\347\256\241\347\220\206/\345\221\275\344\273\244\347\256\241\347\220\206-\347\273\223\346\236\204\345\214\226\345\217\202\346\225\260.md" +++ "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\345\221\275\344\273\244\347\256\241\347\220\206/\345\221\275\344\273\244\347\256\241\347\220\206-\347\273\223\346\236\204\345\214\226\345\217\202\346\225\260.md" @@ -221,6 +221,7 @@ $ main http my-http-server -p 8199 | `root` | - | 指定子级命令名称是父级命令,其他方法是它的子级命令 | 仅用于 **主命令** 对象结构体 `Meta` 标签 | | `strict` | - | 表示该命令严格解析参数/选项,当输入不支持的参数/选项时,返回错误 | 仅用于对象结构体 `Meta` 标签 | | `config` | - | 表示该命令的选项数据支持从指定的配置读取,配置来源于默认的全局单例配置对象 | 仅用于方法输入结构体 `Meta` 标签 | +| `default` | `d` | 表示该输入参数不传递时使用默认值 | 仅用于属性标签 | ## 高级特性 @@ -236,4 +237,4 @@ $ main http my-http-server -p 8199 ### 从配置读取数据 -当命令行中没有传递对应的数据时,输入参数的结构体数据支持从配置组件中自动获取,只需要在 `Meta` 中设置 `config` 标签即可,配置来源于默认的全局单例配置对象。具体示例可以参考 `GoFrame` 框架开发工具源码: [https://github.com/gogf/gf/tree/master/cmd/gf](https://github.com/gogf/gf/tree/master/cmd/gf) \ No newline at end of file +当命令行中没有传递对应的数据时,输入参数的结构体数据支持从配置组件中自动获取,只需要在 `Meta` 中设置 `config` 标签即可,配置来源于默认的全局单例配置对象。具体示例可以参考 `GoFrame` 框架开发工具源码: [https://github.com/gogf/gf/tree/master/cmd/gf](https://github.com/gogf/gf/tree/master/cmd/gf) From 3c512f35a8daf6d4be175880bf4e4dc91973f64b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 31 Dec 2024 10:42:51 +0800 Subject: [PATCH 5/7] prepare development environment docs --- .../Go Module.md" | 0 .../QQ_1733020124554.png" | Bin .../QQ_1733020331260.png" | Bin .../QQ_1733020422698.png" | Bin .../QQ_1733020474019.png" | Bin .../QQ_1733020511081.png" | Bin .../QQ_1733020920028.png" | Bin .../QQ_1733023014586.png" | Bin ...\274\200\345\217\221\347\216\257\345\242\203.md" | 2 +- ...\216\257\345\242\203\351\205\215\347\275\256.md" | 0 ...\216\257\345\242\203\345\256\211\350\243\205.md" | 0 ...\276\235\350\265\226\347\256\241\347\220\206.md" | 0 .../Go Module.md" | 0 ...\274\200\345\217\221\347\216\257\345\242\203.md" | 0 ...\216\257\345\242\203\351\205\215\347\275\256.md" | 0 ...\216\257\345\242\203\345\256\211\350\243\205.md" | 0 ...\276\235\350\265\226\347\256\241\347\220\206.md" | 0 17 files changed, 1 insertion(+), 1 deletion(-) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020124554.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020124554.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020331260.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020331260.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020422698.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020422698.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020474019.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020474019.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020511081.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020511081.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020920028.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020920028.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733023014586.png" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733023014586.png" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" (94%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" (100%) rename "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" => "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" (100%) rename "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" => "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" (100%) rename "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" => "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" (100%) rename "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" => "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" (100%) rename "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" => "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" (100%) rename "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" => "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" (100%) diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020124554.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020124554.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020124554.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020124554.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020331260.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020331260.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020331260.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020331260.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020422698.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020422698.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020422698.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020422698.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020474019.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020474019.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020474019.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020474019.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020511081.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020511081.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020511081.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020511081.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020920028.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020920028.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733020920028.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733020920028.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733023014586.png" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733023014586.png" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/QQ_1733023014586.png" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/QQ_1733023014586.png" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" similarity index 94% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" index d163003520b..e11004315aa 100644 --- "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" +++ "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" @@ -1,6 +1,6 @@ --- slug: '/docs/install-go' -title: '准备工作' +title: '准备开发环境' sidebar_position: 0 hide_title: true keywords: [GoFrame,GoFrame框架,安装GoFrame,GoFrame快速开始,GoFrame教程,GoFrame文档,开发环境配置,安装指南,Go语言,GoFrame开发] diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" diff --git "a/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" "b/docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" similarity index 100% rename from "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" rename to "docs/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" similarity index 100% rename from "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/Go Module.md" rename to "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/Go Module.md" diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" similarity index 100% rename from "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\207\206\345\244\207\345\267\245\344\275\234.md" rename to "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203.md" diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" similarity index 100% rename from "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" rename to "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\345\274\200\345\217\221\347\216\257\345\242\203\351\205\215\347\275\256.md" diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" similarity index 100% rename from "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\216\257\345\242\203\345\256\211\350\243\205.md" rename to "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\216\257\345\242\203\345\256\211\350\243\205.md" diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" similarity index 100% rename from "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\267\245\344\275\234/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" rename to "i18n/en/docusaurus-plugin-content-docs/current/docs/\345\205\266\344\273\226\350\265\204\346\226\231/\345\207\206\345\244\207\345\274\200\345\217\221\347\216\257\345\242\203/\347\247\201\346\234\211\344\276\235\350\265\226\347\256\241\347\220\206.md" From bd38409bc585f8ae36c3cd5a7970d44ff3072fe5 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 31 Dec 2024 18:24:04 +0800 Subject: [PATCH 6/7] orm configuration doc updates --- ...15\347\275\256\346\226\207\344\273\266.md" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\344\275\277\347\224\250\351\205\215\347\275\256/ORM\344\275\277\347\224\250\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266.md" "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\344\275\277\347\224\250\351\205\215\347\275\256/ORM\344\275\277\347\224\250\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266.md" index 68546a67d75..6d2512b876d 100644 --- "a/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\344\275\277\347\224\250\351\205\215\347\275\256/ORM\344\275\277\347\224\250\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266.md" +++ "b/docs/docs/\346\240\270\345\277\203\347\273\204\344\273\266/\346\225\260\346\215\256\345\272\223ORM/ORM\344\275\277\347\224\250\351\205\215\347\275\256/ORM\344\275\277\347\224\250\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266.md" @@ -99,6 +99,28 @@ database: :::note 使用该配置方式时, **为保证数据库安全,默认底层不支持多行 `SQL` 语句执行**。为了得到更多配置项控制,请参考推荐的`link`简化配置,并了解清楚简化配置项中每个连接参数的功能作用,以及对应驱动的官方额外配置参数。 ::: + +配置示例: +```yaml +database: + default: + link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" + extra: "charset=utf8mb4&parseTime=True&loc=Local" + mysql: + type: "mysql" + host: "127.0.0.1" + port: "3306" + user: "root" + pass: "12345678" + name: "test" + charset: "utf8mb4" + timezone: "Local" + maxIdle: "10" + maxOpen: "100" + maxLifetime: "30s" + extra: "parseTime=True" +``` + ## 集群模式 `gdb` 的配置支持集群模式,数据库配置中每一项分组配置均可以是多个节点,支持负载均衡权重策略,例如: From 6feaf2ba84ecef22701465fecfa8c2a65c879ca7 Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:50:33 +0800 Subject: [PATCH 7/7] feat: improve logic in the starbook (#135) --- .../3.2.\347\231\273\345\275\225.md" | 34 ++-- ...50\346\210\267\344\277\241\346\201\257.md" | 54 ++++-- ...50\345\206\214\346\216\245\345\217\243.md" | 47 +++++- ...32\345\212\241\344\274\230\345\214\226.md" | 62 ++++--- ...45\345\271\262\345\215\225\350\257\215.md" | 49 +++--- ...14\346\217\241\347\250\213\345\272\246.md" | 29 ++-- ...60\346\215\256\346\250\241\345\236\213.md" | 33 ---- ...60\345\242\236\345\215\225\350\257\215.md" | 155 ++++++++++-------- ...26\350\276\221\345\215\225\350\257\215.md" | 104 +++++------- ...06\351\241\265\345\210\227\350\241\250.md" | 107 +++++------- ...25\350\257\215\350\257\246\346\203\205.md" | 62 +++---- ...40\351\231\244\345\215\225\350\257\215.md" | 19 ++- .../3.2.\347\231\273\345\275\225.md" | 10 +- ...50\346\210\267\344\277\241\346\201\257.md" | 32 +++- ...50\345\206\214\346\216\245\345\217\243.md" | 40 ++++- ...32\345\212\241\344\274\230\345\214\226.md" | 18 +- ...45\345\271\262\345\215\225\350\257\215.md" | 12 +- ...14\346\217\241\347\250\213\345\272\246.md" | 12 +- ...60\345\242\236\345\215\225\350\257\215.md" | 58 +++++-- ...26\350\276\221\345\215\225\350\257\215.md" | 16 +- ...06\351\241\265\345\210\227\350\241\250.md" | 8 +- ...25\350\257\215\350\257\246\346\203\205.md" | 9 +- ...40\351\231\244\345\215\225\350\257\215.md" | 8 +- 23 files changed, 529 insertions(+), 449 deletions(-) diff --git "a/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" "b/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" index ee486448d9c..2429e4d1970 100644 --- "a/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" +++ "b/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" @@ -29,18 +29,20 @@ type LoginRes struct { ## 编写Logic --- -登录逻辑的的难点在于生成`Token`。准备好一个随机字符串`JwtKey`用作签名,我们将其定义在`utility`目录下。 +登录逻辑的的难点在于生成`Token`。准备好一个随机字符串`JwtKey`用作签名。 -*utility/jwt.go* +*internal/consts/consts.go* ```go -package utility +package consts -var JwtKey = []byte("db03d23b03ec405793b38f10592a2f34") +const ( + JwtKey = "db03d23b03ec405793b38f10592a2f34" +) ``` 编写核心逻辑,先根据用户名进行`Where`查询,获取到数据后,将密码再次加密,如果和数据库中的密文一致则说明是合法用户,生成`Token`返回。 -*internal/logic/users/account.go* +*internal/logic/users/users_account.go* ```go package users @@ -56,42 +58,42 @@ import ( "star/utility" ) -type UserClaims struct { +type jwtClaims struct { Id uint Username string jwt.RegisteredClaims } -func Login(ctx context.Context, username, password string) (tokenString string, err error) { +func (u *Users) Login(ctx context.Context, username, password string) (tokenString string, err error) { var user entity.Users err = dao.Users.Ctx(ctx).Where("username", username).Scan(&user) if err != nil { - return "", errors.New("用户名或密码错误") + return "", gerror.New("用户名或密码错误") } if user.Id == 0 { - return "", errors.New("用户不存在") + return "", gerror.New("用户不存在") } // 将密码加密后与数据库中的密码进行比对 - if user.Password != encryptPassword(password) { - return "", errors.New("用户名或密码错误") + if user.Password != u.encryptPassword(password) { + return "", gerror.New("用户名或密码错误") } // 生成token - userClaims := &UserClaims{ + uc := &jwtClaims{ Id: user.Id, Username: user.Username, RegisteredClaims: jwt.RegisteredClaims{ ExpiresAt: jwt.NewNumericDate(time.Now().Add(6 * time.Hour)), }, } - token := jwt.NewWithClaims(jwt.SigningMethodHS256, userClaims) - return token.SignedString(utility.JwtKey) + token := jwt.NewWithClaims(jwt.SigningMethodHS256, uc) + return token.SignedString(consts.JwtKey) } ``` -从上面的代码可以看到,我们需要声明一个结构体`UserClaims`保存签名信息,这里保存了`Id`和`Username`并设置了`Token`有效期为 6 个小时。最后的声明对象还需要调用`SignedString`方法传入`JwtKey`生成签名。 +从上面的代码可以看到,我们需要声明一个结构体`userClaims`保存签名信息,这里保存了`Id`和`Username`并设置了`Token`有效期为 6 个小时。最后的声明对象还需要调用`SignedString`方法传入`JwtKey`生成签名。 ## Controller调用Logic --- @@ -107,7 +109,7 @@ import ( ) func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) { - token, err := users.Login(ctx, req.Username, req.Password) + token, err := c.users.Login(ctx, req.Username, req.Password) if err != nil { return } diff --git "a/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" "b/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" index a52bcedc197..47465e1c52d 100644 --- "a/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" +++ "b/docs/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" @@ -74,7 +74,7 @@ type InfoRes struct { ## 编写Logic --- -*internal/logic/users/account.go* +*internal/logic/users/users_account.go* ```go package users @@ -92,15 +92,13 @@ import ( ... -func Info(ctx context.Context) (user *entity.Users, err error) { - user = new(entity.Users) +func (u *Users) Info(ctx context.Context) (user *entity.Users, err error) { tokenString := g.RequestFromCtx(ctx).Request.Header.Get("Authorization") - - tokenClaims, _ := jwt.ParseWithClaims(tokenString, &UserClaims{}, func(token *jwt.Token) (interface{}, error) { - return utility.JwtKey, nil + tokenClaims, _ := jwt.ParseWithClaims(tokenString, &jwtClaims{}, func(token *jwt.Token) (interface{}, error) { + return consts.JwtKey, nil }) - if claims, ok := tokenClaims.Claims.(*UserClaims); ok && tokenClaims.Valid { + if claims, ok := tokenClaims.Claims.(*jwtClaims); ok && tokenClaims.Valid { err = dao.Users.Ctx(ctx).Where("id", claims.Id).Scan(&user) } return @@ -113,29 +111,51 @@ func Info(ctx context.Context) (user *entity.Users, err error) { ## Controller调用Logic --- +同样将`logic`注册到控制器中。 + +*internal/controller/account/account_new.go* +```go +... + +package account + +import ( + "star/api/account" + "star/internal/logic/users" +) + +type ControllerV1 struct { + users *users.Users +} + +func NewV1() account.IAccountV1 { + return &ControllerV1{ + users: users.New(), + } +} +``` + *internal/controller/account/account_v1_info.go* ```go package account import ( "context" - + "star/api/account/v1" - "star/internal/logic/users" ) func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) { - user, err := users.Info(ctx) + user, err := c.users.Info(ctx) if err != nil { - return nil, err + return nil, err } return &v1.InfoRes{ - Username: user.Username, - Email: user.Email, - CreatedAt: user.CreatedAt, - UpdatedAt: user.UpdatedAt, - }, nil - return + Username: user.Username, + Email: user.Email, + CreatedAt: user.CreatedAt, + UpdatedAt: user.UpdatedAt, + }, nil } ``` diff --git "a/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" "b/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" index 648971e9094..e346ac73fc1 100644 --- "a/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" +++ "b/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" @@ -47,7 +47,23 @@ done! --- `Logic` 是业务逻辑层,存放在`internal/logic`下,供`Controller`调用从而实现具体的业务逻辑。 -*internal/logic/users/register.go* +定义一个`Users`对象,并新建一个`New`函数用作实例化它: + +*internal/logic/users/users.go* +```go +package users + +type Users struct { +} + +func New() *Users { + return &Users{} +} +``` + +编写注册方法: + +*internal/logic/users/users_register.go* ```go package users @@ -58,7 +74,7 @@ import ( "star/internal/model/do" ) -func Register(ctx context.Context, username, password, email string) error { +func (u *Users) Register(ctx context.Context, username, password, email string) error { _, err := dao.Users.Ctx(ctx).Data(do.Users{ Username: username, Password: password, @@ -77,6 +93,31 @@ func Register(ctx context.Context, username, password, email string) error { --- `Controller` 层负责接收 `Req` 请求对象后调用一个或多个`Logic`完成业务逻辑,一些简单的逻辑也可以直接放在`Controller`中处理。处理完成后的结果封装在约定的 `Res` 数据结构中返回。这里的`Res`数据结构为空,返回`nil`即可。 +将`Users`对象封装到控制器中,方便后续调用。 + +*internal/controller/users/users_new.go* +```go +... + +package users + +import ( + "star/api/users" + userLogic "star/internal/logic/users" +) + +type ControllerV1 struct { + users *userLogic.Users +} + +func NewV1() users.IUsersV1 { + return &ControllerV1{ + users: userLogic.New(), + } +} +``` + + *internal/controller/users/users_v1_register.go* ```go package users @@ -90,7 +131,7 @@ import ( ) func (c *ControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *v1.RegisterRes, err error) { - err = users.Register(ctx, req.Username, req.Password, req.Email) + err = c.users.Register(ctx, req.Username, req.Password, req.Email) return nil, err } ``` diff --git "a/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" "b/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" index 59d5e68518e..fd9018443f1 100644 --- "a/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" +++ "b/docs/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" @@ -147,14 +147,14 @@ $ curl -X POST http://127.0.0.1:8000/v1/users/register -H "Content-Type: applica --- 用户名是登录的重要依据,如果碰巧系统中有两个同名用户,则会出现重大的逻辑混乱。所以我们需要在数据入库前查询该用户是否存在,如果存在,则返回错误信息,提示用户已经存在。 -*internal/logic/users/register.go* +*internal/logic/users/users_register.go* ```go package users ... -func Register(ctx context.Context, username, password, email string) error { - if err := checkUser(ctx, username); err != nil { +func (u *Users) Register(ctx context.Context, username, password, email string) error { + if err := u.checkUser(ctx, username); err != nil { return err } @@ -169,7 +169,7 @@ func Register(ctx context.Context, username, password, email string) error { return nil } -func checkUser(ctx context.Context, username string) error { +func (u *Users) checkUser(ctx context.Context, username string) error { count, err := dao.Users.Ctx(ctx).Where("username", username).Count() if err != nil { return err @@ -201,33 +201,35 @@ ALTER TABLE users ADD UNIQUE (username); --- 密码明文保存是一种非常不安全的行为,通常的做法是对其`hash`计算后存入数据库,例如`md5`、`SHA-1`等。 -新增一个函数`encryptPassword`实现密码加密功能。 +新增一个方法`encryptPassword`实现密码加密功能。 -*internal/logic/users/utility.go* +*internal/logic/users/users.go* ```go package users import "github.com/gogf/gf/v2/crypto/gmd5" -func encryptPassword(password string) string { +... + +func (u *Users) encryptPassword(password string) string { return gmd5.MustEncryptString(password) } ``` `gmd5`组件帮助我们快速实现`md5`加密功能。编写注册逻辑代码,引入密码加密。 -*internal/logic/users/register.go* +*internal/logic/users/users_register.go* ```go package users ... -func Register(ctx context.Context, username, password, email string) error { +func (u *Users) Register(ctx context.Context, username, password, email string) error { ... _, err := dao.Users.Ctx(ctx).Data(do.Users{ Username: username, - Password: encryptPassword(password), + Password: u.encryptPassword(password), Email: email, }).Insert() if err != nil { @@ -257,20 +259,24 @@ curl -X POST http://127.0.0.1:8000/v1/users/register -H "Content-Type: applicati ## Register 函数优化 --- -在`model`层自定义一个数据模型,用作`Logic`层的入参。 +自定义一个数据模型,用作`Logic`层的入参。 -*internal/model/users.go* +*internal/logic/users/users_register.go* ```go package model - -type UserInput struct { + +... + +type RegisterInput struct { Username string Password string Email string } + +... ``` -*internal/logic/users/register.go* +*internal/logic/users/users_register.go* ```go package users @@ -279,8 +285,8 @@ import ( ... ) -func Register(ctx context.Context, in *model.UserInput) error { - if err := CheckUser(ctx, in.Username); err != nil { +func (u *Users) Register(ctx context.Context, in RegisterInput) error { + if err := u.checkUser(ctx, in.Username); err != nil { return err } @@ -298,22 +304,24 @@ func Register(ctx context.Context, in *model.UserInput) error { ... ``` -更改`Controller`层,将`UserInput`传入。 +更改`Controller`层,将`RegisterInput`传入。 *internal/controller/users/users_v1_register.go* ```go package users - -import ( - "star/internal/model" - ... -) + +import ( + "context" + + "star/api/users/v1" + "star/internal/logic/users" +) func (c *ControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *v1.RegisterRes, err error) { - err = users.Register(ctx, &model.UserInput{ - Username: req.Username, - Password: req.Password, - Email: req.Email, + err = c.users.Register(ctx, users.RegisterInput{ + Username: req.Username, + Password: req.Password, + Email: req.Email, }) return nil, err } diff --git "a/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" "b/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" index e0d05d284bb..f88aa030d9d 100644 --- "a/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" +++ "b/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" @@ -11,13 +11,12 @@ description: '使用GoFrame框架设计随机获取单词接口。提供路径wo - 返回的数据基本一致。 ## 添加Api --- -*api/words/v1/learn_words.go* +*api/words/v1/words_learn.go* ```go package v1 import ( "github.com/gogf/gf/v2/frame/g" - "star/internal/model" ) type RandListReq struct { @@ -36,7 +35,7 @@ type RandListRes struct { ## 编写Logic --- -*internal/controller/words/words_v1_rand_list.go* +*internal/logic/words/words_learn.go* ```go package words @@ -49,21 +48,20 @@ import ( "star/internal/model/entity" ) -// Rand 随机若干获取单词 -func Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { +func (w *Words) Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { if limit <= 0 { - limit = 50 + limit = 50 } var ( - list = make([]entity.Words, limit) - err error + err error + cls = dao.Words.Columns() + orm = dao.Words.Ctx(ctx) + list = make([]entity.Words, limit) ) - db := dao.Words.Ctx(ctx) if uid > 0 { - db = db.Where("uid", uid) + orm = orm.Where(cls.Uid, uid) } - - err = db.Limit(int(limit)).OrderRandom().Scan(&list) + err = orm.Limit(int(limit)).OrderRandom().Scan(&list) return list, err } ``` @@ -72,7 +70,7 @@ func Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { ## Controller调用Logic --- -*internal/logic/words/learn_words.go* +*internal/controller/words/words_v1_rand_list.go* ```go package words @@ -80,34 +78,31 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" - "star/internal/logic/words" - "star/internal/model" ) func (c *ControllerV1) RandList(ctx context.Context, req *v1.RandListReq) (res *v1.RandListRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { - return nil, err + return nil, err } - wordList, err := words.Rand(ctx, uid, req.Limit) + wordList, err := c.words.Rand(ctx, uid, req.Limit) if err != nil { - return nil, err + return nil, err } var list []v1.List for _, v := range wordList { - list = append(list, v1.List{ - Id: v.Id, - Word: v.Word, - Definition: v.Definition, - ProficiencyLevel: model.ProficiencyLevel(v.ProficiencyLevel), - }) + list = append(list, v1.List{ + Id: v.Id, + Word: v.Word, + Definition: v.Definition, + ProficiencyLevel: v1.ProficiencyLevel(v.ProficiencyLevel), + }) } return &v1.RandListRes{ - List: list, + List: list, }, nil } ``` diff --git "a/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" "b/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" index 70d926048a2..babaf892f8c 100644 --- "a/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" +++ "b/docs/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" @@ -8,14 +8,14 @@ description: '通过GoFrame框架实现设置单词掌握程度功能。使用PA 设置掌握程度的功能本质上是一种编辑,只改变`ProficiencyLevel`一个字段,所以这里使用`PATCH`方式比`PUT`更为合适。 ## 添加Api --- -*api/words/v1/learn_words.go* +*api/words/v1/words_learn.go* ```go ... type SetLevelReq struct { g.Meta `path:"words/{id}/level" method:"patch"` - Id uint `json:"id" v:"required"` - Level model.ProficiencyLevel `json:"level" v:"required|between:1,5"` + Id uint `json:"id" v:"required"` + Level ProficiencyLevel `json:"level" v:"required|between:1,5"` } type SetLevelRes struct { @@ -26,31 +26,34 @@ type SetLevelRes struct { ## 编写Logic --- -*internal/controller/words/words_v1_set_level.go* +*internal/logic/words/words_learn.go* ```go ... // SetLevel 设置单词熟练度 -func SetLevel(ctx context.Context, uid, id uint, level model.ProficiencyLevel) error { +func (w *Words) SetLevel(ctx context.Context, uid, id uint, level v1.ProficiencyLevel) error { if level < 0 || level > 5 { return gerror.New("熟练度值不合法") } - db := dao.Words.Ctx(ctx) + var ( + cls = dao.Words.Columns() + orm = dao.Words.Ctx(ctx) + ) if uid > 0 { - db = db.Where("uid", uid) + orm = orm.Where(cls.Uid, uid) } - _, err := db.Data("proficiency_level", level).Where("id", id).Update() + _, err := orm.Data(cls.ProficiencyLevel, level).Where(cls.Id, id).Update() return err -} +}**** ``` 为了防止数据异常,我们要在入库前检测等级是否在`1-5`之间。 ## Controller调用Logic --- -*internal/logic/words/learn_words.go* +*internal/controller/words/words_v1_set_level.go* ```go package words @@ -58,17 +61,15 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" - "star/internal/logic/words" ) func (c *ControllerV1) SetLevel(ctx context.Context, req *v1.SetLevelReq) (res *v1.SetLevelRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.SetLevel(ctx, uid, req.Id, req.Level) + err = c.words.SetLevel(ctx, uid, req.Id, req.Level) return nil, err } ``` diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.2.\346\225\260\346\215\256\346\250\241\345\236\213.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.2.\346\225\260\346\215\256\346\250\241\345\236\213.md" index 8277f2649e7..31c9e5b922f 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.2.\346\225\260\346\215\256\346\250\241\345\236\213.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.2.\346\225\260\346\215\256\346\250\241\345\236\213.md" @@ -51,36 +51,3 @@ internal/model/entity/words.go internal/dao/internal/words.go internal/dao/words.go ``` - -## 自定义数据模型 ---- -像用户模型一样,如法炮制的在`model`自定义一个数据模型,用作`Logic`入参。 - -*internal/model/words.go* -```go -package model - -type ProficiencyLevel uint - -const ( - ProficiencyLevel1 ProficiencyLevel = iota + 1 - ProficiencyLevel2 - ProficiencyLevel3 - ProficiencyLevel4 - ProficiencyLevel5 -) - -type WordInput struct { - Uid uint - Word string - Definition string - ExampleSentence string - ChineseTranslation string - Pronunciation string - ProficiencyLevel ProficiencyLevel -} -``` - -在这里我们自定义了一个数据类型`ProficiencyLevel`,表示单词的掌握程度,并定义了五个枚举值:`ProficiencyLevel1-5`从低到高表示级别。 - -这种自定义类型加上固定枚举值的方式是一种高级的程序设计技巧,可以广泛用在各类状态上,比如订单状态,项目阶段等。新手在编程总喜欢使用`int`一把梭,最后造成代码里全是`1,2,3...`这种数字状态,导致代码的可读性和可维护性较差。 \ No newline at end of file diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" index 400ad641765..208e13e675f 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" @@ -10,76 +10,78 @@ description: '使用GoFrame框架实现RESTful风格的单词创建API,包括 --- *api/words/v1/words.go* ```go +type ProficiencyLevel uint + +const ( + ProficiencyLevel1 ProficiencyLevel = iota + 1 + ProficiencyLevel2 + ProficiencyLevel3 + ProficiencyLevel4 + ProficiencyLevel5 +) + type CreateReq struct { g.Meta `path:"words" method:"post" sm:"创建" tags:"单词"` - Word string `json:"word" v:"required|length:1,100" dc:"单词"` - Definition string `json:"definition" v:"required|length:1,300" dc:"单词定义"` - ExampleSentence string `json:"example_sentence" v:"required|length:1,300" dc:"例句"` - ChineseTranslation string `json:"chinese_translation" v:"required|length:1,300" dc:"中文翻译"` - Pronunciation string `json:"pronunciation" v:"required|length:1,100" dc:"发音"` - ProficiencyLevel uint `json:"proficiency_level" v:"required|between:1,5" dc:"熟练度,1最低,5最高"` + Word string `json:"word" v:"required|length:1,100" dc:"单词"` + Definition string `json:"definition" v:"required|length:1,300" dc:"单词定义"` + ExampleSentence string `json:"example_sentence" v:"required|length:1,300" dc:"例句"` + ChineseTranslation string `json:"chinese_translation" v:"required|length:1,300" dc:"中文翻译"` + Pronunciation string `json:"pronunciation" v:"required|length:1,100" dc:"发音"` + ProficiencyLevel ProficiencyLevel `json:"proficiency_level" v:"required|between:1,5" dc:"熟练度,1最低,5最高"` } type CreateRes struct { } ``` -您是否注意到,`CreateReq`结构体中与之前定义的`model.WordInput`高度相似,我们能不能复用一下,使`api`和`logic`保持一致,精简代码呢?像这样: +在这里我们自定义了一个数据类型`ProficiencyLevel`,表示单词的掌握程度,并定义了五个枚举值:`ProficiencyLevel1-5`从低到高表示级别。 -*api/words/v1/words.go* -```go -type CreateReq struct { - g.Meta `path:"words" method:"post" sm:"创建" tags:"单词"` - model.WordInput -} +这种自定义类型加上固定枚举值的方式是一种高级的程序设计技巧,可以广泛用在各类状态上,比如订单状态,项目阶段等。新手在编程总喜欢使用`int`一把梭,最后造成代码里全是`1,2,3...`这种数字状态,导致代码的可读性和可维护性较差。 -... -``` +## 编写Logic +--- +同样的,定义`Words`对象,新建`New`函数用作实例化。 -*internal/model/words.go* +*internal/logic/words/words.go* ```go -package model +package words -... - -type WordInput struct { - Word string `json:"word" v:"required|length:1,100" dc:"单词"` - Definition string `json:"definition" v:"required|length:1,300" dc:"单词定义"` - ExampleSentence string `json:"example_sentence" v:"required|length:1,300" dc:"例句"` - ChineseTranslation string `json:"chinese_translation" v:"required|length:1,300" dc:"中文翻译"` - Pronunciation string `json:"pronunciation" v:"required|length:1,100" dc:"发音"` - ProficiencyLevel uint `json:"proficiency_level" v:"required|between:1,5" dc:"熟练度,1最低,5最高"` +type Words struct { +} + +func New() *Words { + return &Words{} } ``` -答案是,程序正常运行,但是**这种方式极不可取**。这是因为`Api`层是数据接收层,`Logic`层是逻辑操作层。这种层层透传的方式会带来如下问题: -- 方法参数定义不明确,不明确的定义意味着会增加额外的协作成本,额外的不明确风险; -- 同一数据结构与多数方法形成耦合,数据结构的任一变动将会影响所有相关方法; -- 相关方法无法充分复用。 - -最佳实验是,**宁可多写几行代码,也不要透传数据模型。** - -## 编写Logic ---- *internal/logic/words/words.go* ```go -package words - -import ( - "context" +... + +type CreateInput struct { + Uid uint + Word string + Definition string + ExampleSentence string + ChineseTranslation string + Pronunciation string + ProficiencyLevel v1.ProficiencyLevel +} - "github.com/gogf/gf/v2/errors/gerror" - "star/internal/dao" - "star/internal/model" - "star/internal/model/do" -) +func (w *Words) Create(ctx context.Context, in CreateInput) error { + var cls = dao.Words.Columns() -func Create(ctx context.Context, in *model.WordInput) error { - if err := checkWord(ctx, in); err != nil { + count, err := dao.Words.Ctx(ctx). + Where(cls.Uid, in.Uid). + Where(cls.Word, in.Word).Count() + if err != nil { return err } + if count > 0 { + return gerror.New("单词已存在") + } - _, err := dao.Words.Ctx(ctx).Data(do.Words{ + _, err = dao.Words.Ctx(ctx).Data(do.Words{ Uid: in.Uid, Word: in.Word, Definition: in.Definition, @@ -92,30 +94,18 @@ func Create(ctx context.Context, in *model.WordInput) error { return err } return nil -} - -func checkWord(ctx context.Context, in *model.WordInput) error { - count, err := dao.Words.Ctx(ctx).Where("uid", in.Uid).Where("word", in.Word).Count() - if err != nil { - return err - } - if count > 0 { - return gerror.New("单词已存在") - } - return nil } ``` 在`Logic`中我们也需要确保同一用户单词不能重复,和数据库保持一致。 -## Controller调用Logic ---- +### account logic 单词表中保存有`uid`字段,我们需要在`logic/users`包中封装一个`GetUid`函数提供`uid`。 -*internal/logic/users/account.go* +*internal/logic/users/users_account.go* ```go -func GetUid(ctx context.Context) (uint, error) { - user, err := Info(ctx) +func (u *Users) GetUid(ctx context.Context) (uint, error) { + user, err := u.Info(ctx) if err != nil { return 0, err } @@ -123,6 +113,37 @@ func GetUid(ctx context.Context) (uint, error) { } ``` +## Controller调用Logic +--- +在创建单词的控制器中,我们需要调用`account`和`words`两个`logic`,我们将他封装到控制器中。 + +*internal/controller/words/words_new.go* +```go +... + + +package words + +import ( + "star/api/words" + usersLogic "star/internal/logic/users" + wordsLogic "star/internal/logic/words" +) + +type ControllerV1 struct { + users *usersLogic.Users + words *wordsLogic.Words +} + +func NewV1() words.IWordsV1 { + return &ControllerV1{ + users: usersLogic.New(), + words: wordsLogic.New(), + } +} +``` + + *internal/controller/words/words_v1_create.go* ```go package words @@ -130,18 +151,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" "star/internal/model" "star/api/words/v1" ) func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.Create(ctx, &model.WordInput{ + err = c.words.Create(ctx, &model.WordInput{ Uid: uid, Word: req.Word, Definition: req.Definition, @@ -154,7 +173,7 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C } ``` -在`Controller`中调用两个`Logic`层级的函数:`users.GetUid`和`words.Create`来实现功能。注意,不要在`words.Create`中直接调用`users.GetUid`,删除`Controller`中的`users.GetUid`,这样会加重`words`包的耦合。 +在`Controller`中调用两个`Logic`层级的方法:`users.GetUid`和`words.Create`来实现功能。注意,不要在`words.Create`中直接调用`users.GetUid`,这样会加重`words`包的耦合。 最佳实验是,**尽量保证`Logic`函数的功能单一化,在`Controller`中多次调用`Logic`完成功能。** diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" index 63b529be737..d1c350e9126 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" @@ -12,13 +12,13 @@ description: '利用GoFrame框架中的REST API来更新单词信息,包括单 ```go type UpdateReq struct { g.Meta `path:"words/{id}" method:"put" sm:"更新" tags:"单词"` - Id uint `json:"id" v:"required"` - Word string `json:"word" v:"required|length:1,100" dc:"单词"` - Definition string `json:"definition" v:"required|length:1,300" dc:"单词定义"` - ExampleSentence string `json:"example_sentence" v:"required|length:1,300" dc:"例句"` - ChineseTranslation string `json:"chinese_translation" v:"required|length:1,300" dc:"中文翻译"` - Pronunciation string `json:"pronunciation" v:"required|length:1,100" dc:"发音"` - ProficiencyLevel uint `json:"proficiency_level" v:"required|between:1,5" dc:"熟练度,1最低,5最高"` + Id uint `json:"id" v:"required"` + Word string `json:"word" v:"required|length:1,100" dc:"单词"` + Definition string `json:"definition" v:"required|length:1,300" dc:"单词定义"` + ExampleSentence string `json:"example_sentence" v:"required|length:1,300" dc:"例句"` + ChineseTranslation string `json:"chinese_translation" v:"required|length:1,300" dc:"中文翻译"` + Pronunciation string `json:"pronunciation" v:"required|length:1,100" dc:"发音"` + ProficiencyLevel ProficiencyLevel `json:"proficiency_level" v:"required|between:1,5" dc:"熟练度,1最低,5最高"` } type UpdateRes struct { @@ -27,66 +27,45 @@ type UpdateRes struct { ## 编写Logic --- -在编辑时,我们也需要检查`word`是否唯一。现有的`checkWord`函数不能满足需要,编辑时会连同自己一起判断,所以要改进一下: -- 加上`id`字段,不为`0`时使用`id`和`word`联合判断; -- `id`为`0`时代表新增,仅使用`word`判断。 - *internal/logic/words/words.go* ```go -package words +package words ... -func Create(ctx context.Context, in *model.WordInput) error { - if err := checkWord(ctx, 0, in); err != nil { - return err - } - ... -} - -// checkWord 在更新时不检查自身 -func checkWord(ctx context.Context, id uint, in *model.WordInput) error { - db := dao.Words.Ctx(ctx).Where("uid", in.Uid).Where("word", in.Word) - if id > 0 { - db = db.WhereNot("id", id) - } - count, err := db.Count() +type UpdateInput struct { + Uid uint + Word string + Definition string + ExampleSentence string + ChineseTranslation string + Pronunciation string + ProficiencyLevel v1.ProficiencyLevel +} + +func (w *Words) Update(ctx context.Context, id uint, in UpdateInput) error { + var cls = dao.Words.Columns() + + count, err := dao.Words.Ctx(ctx). + Where(cls.Uid, in.Uid). + Where(cls.Word, in.Word). + WhereNot(cls.Id, id). + Count() if err != nil { return err } if count > 0 { return gerror.New("单词已存在") } - return nil -} -``` - -加上更新逻辑: - -*internal/logic/words/words.go* -```go -package words - -... - -func Update(ctx context.Context, id uint, in *model.WordInput) error { - if err := checkWord(ctx, id, in); err != nil { - return err - } - - db := dao.Words.Ctx(ctx).Where("uid", in.Uid).Data(do.Words{ + + _, err = dao.Words.Ctx(ctx).Data(do.Words{ Word: in.Word, Definition: in.Definition, ExampleSentence: in.ExampleSentence, ChineseTranslation: in.ChineseTranslation, Pronunciation: in.Pronunciation, ProficiencyLevel: in.ProficiencyLevel, - }).Where("id", id) - if in.Uid > 0 { - db = db.Where("uid", in.Uid) - } - - _, err := db.Update() + }).Where(cls.Id, id).Where(cls.Uid, in.Uid).Update() if err != nil { return err } @@ -96,7 +75,7 @@ func Update(ctx context.Context, id uint, in *model.WordInput) error { ... ``` -在`Uid`大于零的情况下,则必须在`ORM`链式中加上`Uid`判断条件,以防止越权,后续的查询,删除动作同样如此。 +必须在`ORM`链式中加上`Uid`判断条件,以防止越权,后续的查询,删除动作同样如此。另外加上`WhereNot`,以忽略自身的单词重复检测。 ## Controller调用Logic --- @@ -107,25 +86,18 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" - "star/internal/model" "star/api/words/v1" + "star/internal/logic/words" ) func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) { - uid, err := users.GetUid(ctx) - if err != nil { - return nil, err - } - err = words.Update(ctx, req.Id, &model.WordInput{ - Uid: uid, - Word: req.Word, - Definition: req.Definition, - ExampleSentence: req.ExampleSentence, - ChineseTranslation: req.ChineseTranslation, - Pronunciation: req.Pronunciation, - ProficiencyLevel: model.ProficiencyLevel(req.ProficiencyLevel), + err = c.words.Update(ctx, req.Id, words.UpdateInput{ + Word: req.Word, + Definition: req.Definition, + ExampleSentence: req.ExampleSentence, + ChineseTranslation: req.ChineseTranslation, + Pronunciation: req.Pronunciation, + ProficiencyLevel: req.ProficiencyLevel, }) return nil, err } diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" index 99d550042a9..68c6bbb76a7 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" @@ -14,13 +14,11 @@ description: '使用GET方式查询单词的分页列表,包含模糊查询功 | Size | `int` | `json:"size"` | `between:1,100` | 每页数量,默认10 | ## 添加Api --- -首先,我们定义一个结构体保存一个单词的字段。 +定义一个结构体`List`保存一个单词的字段。在`ListRes`中返回一个`List`切片,表示单词列表,`Total`表示所有单词数量,返回给前端方便做分页操作。 -*api/words/v1/words_struct.go* +*api/words/v1/words.go* ```go -package v1 - -import "star/internal/model" +... type List struct { Id uint `json:"id"` @@ -28,13 +26,6 @@ type List struct { Definition string `json:"definition"` ProficiencyLevel model.ProficiencyLevel `json:"proficiencyLevel"` } -``` - -在`ListRes`中返回一个`List`切片,表示单词列表,`Total`表示所有单词数量,返回给前端方便做分页操作。 - -*api/words/v1/words.go* -```go -... type ListReq struct { g.Meta `path:"words" method:"get" sm:"列表" tags:"单词"` @@ -51,62 +42,48 @@ type ListRes struct { ## 编写Logic --- -先定义一个`Query`结构体,用作查询列表入参,严格遵循每一层重新定义数据结构。 - -*internal/model/words.go* +*internal/logic/words/words.go* ```go ... -type WordQuery struct { +type ListInput struct { Uid uint Word string Page int Size int -} -``` - -*internal/logic/words/words.go* -```go -... - -func List(ctx context.Context, query *model.WordQuery) (list []entity.Words, total uint, err error) { - if query == nil { - query = &model.WordQuery{} - } +} + +func (w *Words) List(ctx context.Context, in ListInput) (list []entity.Words, total int, err error) { // 对于查询初始值的处理 - if query.Page == 0 { - query.Page = 1 + if in.Page == 0 { + in.Page = 1 } - if query.Size == 0 { - query.Size = 15 + if in.Size == 0 { + in.Size = 15 } + var ( + cls = dao.Words.Columns() + orm = dao.Words.Ctx(ctx) + ) // 组成查询链 - db := dao.Words.Ctx(ctx) - if query.Uid > 0 { - db = db.Where("uid", query.Uid) + if in.Uid > 0 { + orm = orm.Where(cls.Uid, in.Uid) } // 模糊查询 - if len(query.Word) != 0 { - db = db.WhereLike("word", fmt.Sprintf("%%%s%%", query.Word)) + if len(in.Word) != 0 { + orm = orm.WhereLike(cls.Word, "%"+in.Word+"%") } - db = db.Order("created_at desc, id desc").Page(query.Page, query.Size) - - data, totalInt, err := db.AllAndCount(true) - if err != nil { + orm = orm.OrderDesc(cls.CreatedAt).OrderDesc(cls.Id).Page(in.Page, in.Size) + if err = orm.ScanAndCount(&list, &total, true); err != nil { return } - - list = []entity.Words{} - _ = data.Structs(&list) - total = uint(totalInt) - return } ``` -上述代码用到了`db.WhereLike("word", fmt.Sprintf("%%%s%%", query.Word))`,它是模糊查询的意思,最终会生成`word LIKE '%{word}%'` 子句。 +上述代码用到了`orm.WhereLike(cls.Word, "%"+in.Word+"%")`,它是模糊查询的意思,最终会生成`word LIKE '%{word}%'` 子句。 `AllAndCount`用于同时查询数据记录列表及总数量,一般用于分页查询场景中,简化分页查询逻辑。 @@ -120,41 +97,37 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" "star/internal/logic/words" - "star/internal/model" ) func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { - return nil, err - } - - query := &model.WordQuery{ - Uid: uid, - Word: req.Word, - Page: req.Page, - Size: req.Size, + return nil, err } - wordList, total, err := words.List(ctx, query) + wordList, total, err := c.words.List(ctx, words.ListInput{ + Uid: uid, + Word: req.Word, + Page: req.Page, + Size: req.Size, + }) if err != nil { - return nil, err + return nil, err } var list []v1.List for _, v := range wordList { - list = append(list, v1.List{ - Id: v.Id, - Word: v.Word, - Definition: v.Definition, - ProficiencyLevel: model.ProficiencyLevel(v.ProficiencyLevel), - }) + list = append(list, v1.List{ + Id: v.Id, + Word: v.Word, + Definition: v.Definition, + ProficiencyLevel: v1.ProficiencyLevel(v.ProficiencyLevel), + }) } return &v1.ListRes{ - List: list, - Total: total, + List: list, + Total: uint(total), }, nil } ``` diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" index 20e601c5257..01669a56e28 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" @@ -8,7 +8,7 @@ description: '单词详情接口通过GET请求获取不在列表中的单词详 单词详情同样使用`GET`方式,用作获取单词的详细信息,会包含例句,中文翻译等列表中不存在的字段。 ## 添加Api --- -*api/words/v1/words.go*d +*api/words/v1/words.go* ```go ... @@ -18,15 +18,15 @@ type DetailReq struct { } type DetailRes struct { - Id uint `json:"id"` - Word string `json:"word"` - Definition string `json:"definition"` - ExampleSentence string `json:"exampleSentence"` - ChineseTranslation string `json:"chineseTranslation"` - Pronunciation string `json:"pronunciation"` - ProficiencyLevel uint `json:"proficiencyLevel"` - CreatedAt *gtime.Time `json:"createdAt"` - UpdatedAt *gtime.Time `json:"updatedAt"` + Id uint `json:"id"` + Word string `json:"word"` + Definition string `json:"definition"` + ExampleSentence string `json:"exampleSentence"` + ChineseTranslation string `json:"chineseTranslation"` + Pronunciation string `json:"pronunciation"` + ProficiencyLevel ProficiencyLevel `json:"proficiencyLevel"` + CreatedAt *gtime.Time `json:"createdAt"` + UpdatedAt *gtime.Time `json:"updatedAt"` } ``` @@ -38,13 +38,16 @@ type DetailRes struct { ```go ... -func Detail(ctx context.Context, uid, id uint) (word *entity.Words, err error) { - word = &entity.Words{} - db := dao.Words.Ctx(ctx).Where("id", id) +func (w *Words) Detail(ctx context.Context, uid, id uint) (word *entity.Words, err error) { + var ( + cls = dao.Words.Columns() + orm = dao.Words.Ctx(ctx) + ) + orm = orm.Where(cls.Id, id) if uid > 0 { - db = db.Where("uid", uid) + orm = orm.Where(cls.Uid, uid) } - err = db.Scan(word) + err = orm.Scan(&word) return } ``` @@ -58,33 +61,30 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" - "star/api/words/v1" ) func (c *ControllerV1) Detail(ctx context.Context, req *v1.DetailReq) (res *v1.DetailRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { - return nil, err + return nil, err } - word, err := words.Detail(ctx, uid, req.Id) + word, err := c.words.Detail(ctx, uid, req.Id) if err != nil { - return nil, err + return nil, err } return &v1.DetailRes{ - Id: word.Id, - Word: word.Word, - Definition: word.Definition, - ExampleSentence: word.ExampleSentence, - ChineseTranslation: word.ChineseTranslation, - Pronunciation: word.Pronunciation, - ProficiencyLevel: word.ProficiencyLevel, - CreatedAt: word.CreatedAt, - UpdatedAt: word.UpdatedAt, + Id: word.Id, + Word: word.Word, + Definition: word.Definition, + ExampleSentence: word.ExampleSentence, + ChineseTranslation: word.ChineseTranslation, + Pronunciation: word.Pronunciation, + ProficiencyLevel: v1.ProficiencyLevel(word.ProficiencyLevel), + CreatedAt: word.CreatedAt, + UpdatedAt: word.UpdatedAt, }, nil } ``` diff --git "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" index 583eed9e5cb..e87a3ab266e 100644 --- "a/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" +++ "b/docs/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" @@ -25,12 +25,17 @@ type DeleteRes struct { *internal/logic/words/words.go* ```go ... -func Delete(ctx context.Context, uid, id uint) (err error) { - db := dao.Words.Ctx(ctx).Where("id", id) + +func (w *Words) Delete(ctx context.Context, uid, id uint) (err error) { + var ( + cls = dao.Words.Columns() + orm = dao.Words.Ctx(ctx) + ) + orm = orm.Where(cls.Id, id) if uid > 0 { - db = db.Where("uid", uid) + orm = orm.Where(cls.Uid, uid) } - _, err = db.Delete() + _, err = orm.Delete() return } ``` @@ -44,18 +49,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" "star/api/words/v1" ) func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.Delete(ctx, uid, req.Id) + err = c.words.Delete(ctx, uid, req.Id) return } ``` diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" index 9081885a4fc..475d4e02b77 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.2.\347\231\273\345\275\225.md" @@ -56,13 +56,13 @@ import ( "star/utility" ) -type UserClaims struct { +type userClaims struct { Id uint Username string jwt.RegisteredClaims } -func Login(ctx context.Context, username, password string) (tokenString string, err error) { +func (u *Users) Login(ctx context.Context, username, password string) (tokenString string, err error) { var user entity.Users err = dao.Users.Ctx(ctx).Where("username", username).Scan(&user) if err != nil { @@ -79,14 +79,14 @@ func Login(ctx context.Context, username, password string) (tokenString string, } // Generate token - userClaims := &UserClaims{ + uc := &userClaims{ Id: user.Id, Username: user.Username, RegisteredClaims: jwt.RegisteredClaims{ ExpiresAt: jwt.NewNumericDate(time.Now().Add(6 * time.Hour)), }, } - token := jwt.NewWithClaims(jwt.SigningMethodHS256, userClaims) + token := jwt.NewWithClaims(jwt.SigningMethodHS256, uc) return token.SignedString(utility.JwtKey) } ``` @@ -107,7 +107,7 @@ import ( ) func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) { - token, err := users.Login(ctx, req.Username, req.Password) + token, err := c.users.Login(ctx, req.Username, req.Password) if err != nil { return } diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" index aeb18f7b79a..9f31b0170f8 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\211\347\253\240-\344\274\232\350\257\235\347\256\241\347\220\206/3.3.\350\216\267\345\217\226\347\224\250\346\210\267\344\277\241\346\201\257.md" @@ -92,15 +92,15 @@ import ( ... -func Info(ctx context.Context) (user *entity.Users, err error) { +func (u *Users) Info(ctx context.Context) (user *entity.Users, err error) { user = new(entity.Users) tokenString := g.RequestFromCtx(ctx).Request.Header.Get("Authorization") - tokenClaims, _ := jwt.ParseWithClaims(tokenString, &UserClaims{}, func(token *jwt.Token) (interface{}, error) { + tokenClaims, _ := jwt.ParseWithClaims(tokenString, &userClaims{}, func(token *jwt.Token) (interface{}, error) { return utility.JwtKey, nil }) - if claims, ok := tokenClaims.Claims.(*UserClaims); ok && tokenClaims.Valid { + if claims, ok := tokenClaims.Claims.(*userClaims); ok && tokenClaims.Valid { err = dao.Users.Ctx(ctx).Where("id", claims.Id).Scan(&user) } return @@ -113,6 +113,30 @@ The `Scan` method is a powerful one that automatically recognizes and converts b ## Controller Calls Logic --- +Also register 'logic' with the controller. + +*internal/controller/users/users_new.go* +```go +... + +package account + +import ( + "star/api/account" + usersL "star/internal/logic/users" +) + +type ControllerV1 struct { + users *usersL.Users +} + +func NewV1() account.IAccountV1 { + return &ControllerV1{ + users: &usersL.Users{}, + } +} +``` + *internal/controller/account/account_v1_info.go* ```go package account @@ -125,7 +149,7 @@ import ( ) func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) { - user, err := users.Info(ctx) + user, err := c.users.Info(ctx) if err != nil { return nil, err } diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" index 20cc530193d..93e3a74ec42 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.3.\346\263\250\345\206\214\346\216\245\345\217\243.md" @@ -47,6 +47,18 @@ Among the four generated files, we only need to focus on `users_v1_register.go`, --- `Logic` is the business logic layer, stored in `internal/logic`, which is called by the `Controller` to implement specific business logic. +Define a 'Users' object: + +*internal/logic/users/users.go* +```go +package users + +type Users struct { +} +``` + +Write registration methods: + *internal/logic/users/register.go* ```go package users @@ -58,7 +70,7 @@ import ( "star/internal/model/do" ) -func Register(ctx context.Context, username, password, email string) error { +func (u *Users) Register(ctx context.Context, username, password, email string) error { _, err := dao.Users.Ctx(ctx).Data(do.Users{ Username: username, Password: password, @@ -77,6 +89,30 @@ func Register(ctx context.Context, username, password, email string) error { --- The `Controller` layer is responsible for receiving `Req` request objects and then calling one or more `Logic` to complete the business logic. Some simple logic can also be directly handled in the `Controller`. The results of the processing are wrapped in the agreed `Res` data structure and returned. Here, the `Res` data structure is empty, so returning `nil` is sufficient. +Encapsulate the 'Users' object into the controller for easy subsequent calls. + +*internal/controller/users/users_new.go* +```go +... + +package users + +import ( + "star/api/users" + usersL "star/internal/logic/users" +) + +type ControllerV1 struct { + users *usersL.Users +} + +func NewV1() users.IUsersV1 { + return &ControllerV1{ + users: &usersL.Users{}, + } +} +``` + *internal/controller/users/users_v1_register.go* ```go package users @@ -90,7 +126,7 @@ import ( ) func (c *ControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *v1.RegisterRes, err error) { - err = users.Register(ctx, req.Username, req.Password, req.Email) + err = c.users.Register(ctx, req.Username, req.Password, req.Email) return nil, err } ``` diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" index 8c1a42dd534..67ea541584c 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\214\347\253\240-\347\224\250\346\210\267\346\263\250\345\206\214/2.4.\344\270\232\345\212\241\344\274\230\345\214\226.md" @@ -153,8 +153,8 @@ package users ... -func Register(ctx context.Context, username, password, email string) error { - if err := checkUser(ctx, username); err != nil { +func (u *Users) Register(ctx context.Context, username, password, email string) error { + if err := u.checkUser(ctx, username); err != nil { return err } @@ -169,7 +169,7 @@ func Register(ctx context.Context, username, password, email string) error { return nil } -func checkUser(ctx context.Context, username string) error { +func (u *Users) checkUser(ctx context.Context, username string) error { count, err := dao.Users.Ctx(ctx).Where("username", username).Count() if err != nil { return err @@ -222,7 +222,7 @@ package users ... -func Register(ctx context.Context, username, password, email string) error { +func (u *Users) Register(ctx context.Context, username, password, email string) error { ... _, err := dao.Users.Ctx(ctx).Data(do.Users{ @@ -263,7 +263,7 @@ Customize a data model in the `model` layer for use as input parameters in the ` ```go package model -type UserInput struct { +type RegisterInput struct { Username string Password string Email string @@ -279,8 +279,8 @@ import ( ... ) -func Register(ctx context.Context, in *model.UserInput) error { - if err := CheckUser(ctx, in.Username); err != nil { +func (u *Users) Register(ctx context.Context, in *model.RegisterInput) error { + if err := u.checkUser(ctx, in.Username); err != nil { return err } @@ -298,7 +298,7 @@ func Register(ctx context.Context, in *model.UserInput) error { ... ``` -Change the `Controller` layer to pass in `UserInput`. +Change the `Controller` layer to pass in `RegisterInput`. *internal/controller/users/users_v1_register.go* ```go @@ -310,7 +310,7 @@ import ( ) func (c *ControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *v1.RegisterRes, err error) { - err = users.Register(ctx, &model.UserInput{ + err = c.users.Register(ctx, &model.RegisterInput{ Username: req.Username, Password: req.Password, Email: req.Email, diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" index a01179e68a4..7843020f1fe 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.2.\351\232\217\346\234\272\350\216\267\345\217\226\350\213\245\345\271\262\345\215\225\350\257\215.md" @@ -36,7 +36,7 @@ type RandListRes struct { ## Write Logic --- -*internal/controller/words/words_v1_rand_list.go* +*internal/logic/words/learn_words.go* ```go package words @@ -50,7 +50,7 @@ import ( ) // Rand Randomly retrieve a few words -func Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { +func (w *Words) Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { if limit <= 0 { limit = 50 } @@ -72,7 +72,7 @@ func Rand(ctx context.Context, uid, limit uint) ([]entity.Words, error) { ## Controller Calls Logic --- -*internal/logic/words/learn_words.go* +*internal/controller/words/words_v1_rand_list.go* ```go package words @@ -80,18 +80,16 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" - "star/internal/logic/words" "star/internal/model" ) func (c *ControllerV1) RandList(ctx context.Context, req *v1.RandListReq) (res *v1.RandListRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - wordList, err := words.Rand(ctx, uid, req.Limit) + wordList, err := c.words.Rand(ctx, uid, req.Limit) if err != nil { return nil, err } diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" index 22c7422f917..86da10b92cb 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\272\224\347\253\240-\345\255\246\344\271\240\345\215\225\350\257\215/5.3.\350\256\276\347\275\256\346\216\214\346\217\241\347\250\213\345\272\246.md" @@ -26,12 +26,12 @@ Both `words/{id}/level` and `words/level/{id}` route styles are acceptable, but ## Write Logic --- -*internal/controller/words/words_v1_set_level.go* +*internal/logic/words/learn_words.go* ```go ... // SetLevel sets the word proficiency level -func SetLevel(ctx context.Context, uid, id uint, level model.ProficiencyLevel) error { +func (w *Words) SetLevel(ctx context.Context, uid, id uint, level model.ProficiencyLevel) error { if level < 0 || level > 5 { return gerror.New("Invalid proficiency level value") } @@ -50,7 +50,7 @@ To prevent data anomalies, we need to check if the level is between `1-5` before ## Controller calls Logic --- -*internal/logic/words/learn_words.go* +*internal/controller/words/words_v1_set_level.go* ```go package words @@ -58,17 +58,15 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" - "star/internal/logic/words" ) func (c *ControllerV1) SetLevel(ctx context.Context, req *v1.SetLevelReq) (res *v1.SetLevelRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.SetLevel(ctx, uid, req.Id, req.Level) + err = c.words.SetLevel(ctx, uid, req.Id, req.Level) return nil, err } ``` diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" index 172e8acd36f..9bef0cf085b 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.3.\346\226\260\345\242\236\345\215\225\350\257\215.md" @@ -73,10 +73,13 @@ import ( "star/internal/dao" "star/internal/model" "star/internal/model/do" -) +) + +type Words struct { +} -func Create(ctx context.Context, in *model.WordInput) error { - if err := checkWord(ctx, in); err != nil { +func (w *Words) Create(ctx context.Context, in *model.WordInput) error { + if err := w.checkWord(ctx, in); err != nil { return err } @@ -95,7 +98,7 @@ func Create(ctx context.Context, in *model.WordInput) error { return nil } -func checkWord(ctx context.Context, in *model.WordInput) error { +func (w *Words) checkWord(ctx context.Context, in *model.WordInput) error { count, err := dao.Words.Ctx(ctx).Where("uid", in.Uid).Where("word", in.Word).Count() if err != nil { return err @@ -109,14 +112,13 @@ func checkWord(ctx context.Context, in *model.WordInput) error { In the `Logic` layer, we also need to ensure that the same user's words cannot be duplicated, keeping consistency with the database. -## Controller Calls Logic ---- -The word table contains a `uid` field, and we need to encapsulate a `GetUid` function in the `logic/users` package to provide `uid`. +### account logic +The 'uid' field is stored in the word list, and we need to provide the 'uid' by wrapping a 'GetUid' function in the 'logic/users' package. *internal/logic/users/account.go* ```go -func GetUid(ctx context.Context) (uint, error) { - user, err := Info(ctx) +func (u *Users) GetUid(ctx context.Context) (uint, error) { + user, err := u.Info(ctx) if err != nil { return 0, err } @@ -124,6 +126,38 @@ func GetUid(ctx context.Context) (uint, error) { } ``` +## Controller Calls Logic +--- +In the controller where the words are created, we need to call both 'account' and 'Words' logic, which we encapsulate in the controller. + + +*internal/controller/words/words_new.go* +```go +... + + +package words + +import ( + "star/api/words" + usersL "star/internal/logic/users" + wordsL "star/internal/logic/words" +) + +type ControllerV1 struct { + users *usersL.Users + words *wordsL.Words +} + +func NewV1() words.IWordsV1 { + return &ControllerV1{ + users: &usersL.Users{}, + words: &wordsL.Words{}, + } +} +``` + + *internal/controller/words/words_v1_create.go* ```go package words @@ -131,18 +165,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" "star/internal/model" "star/api/words/v1" ) func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.Create(ctx, &model.WordInput{ + err = c.words.Create(ctx, &model.WordInput{ Uid: uid, Word: req.Word, Definition: req.Definition, diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" index 8573fa53e0f..de3547001f0 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.4.\347\274\226\350\276\221\345\215\225\350\257\215.md" @@ -37,15 +37,15 @@ package words ... -func Create(ctx context.Context, in *model.WordInput) error { - if err := checkWord(ctx, 0, in); err != nil { +func (w *Words) Create(ctx context.Context, in *model.WordInput) error { + if err := w.checkWord(ctx, 0, in); err != nil { return err } ... } // checkWord does not check itself during an update -func checkWord(ctx context.Context, id uint, in *model.WordInput) error { +func (w *Words) checkWord(ctx context.Context, id uint, in *model.WordInput) error { db := dao.Words.Ctx(ctx).Where("uid", in.Uid).Where("word", in.Word) if id > 0 { db = db.WhereNot("id", id) @@ -69,8 +69,8 @@ package words ... -func Update(ctx context.Context, id uint, in *model.WordInput) error { - if err := checkWord(ctx, id, in); err != nil { +func (w *Words) Update(ctx context.Context, id uint, in *model.WordInput) error { + if err := w.checkWord(ctx, id, in); err != nil { return err } @@ -107,18 +107,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" "star/internal/model" "star/api/words/v1" ) func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.Update(ctx, req.Id, &model.WordInput{ + err = c.words.Update(ctx, req.Id, &model.WordInput{ Uid: uid, Word: req.Word, Definition: req.Definition, diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" index 04030686170..6cd96a23eb9 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.5.\345\215\225\350\257\215\345\210\206\351\241\265\345\210\227\350\241\250.md" @@ -70,7 +70,7 @@ type WordQuery struct { ```go ... -func List(ctx context.Context, query *model.WordQuery) (list []entity.Words, total uint, err error) { +func (w *Words) List(ctx context.Context, query *model.WordQuery) (list []entity.Words, total uint, err error) { if query == nil { query = &model.WordQuery{} } @@ -121,13 +121,11 @@ import ( "context" "star/api/words/v1" - "star/internal/logic/users" - "star/internal/logic/words" "star/internal/model" ) func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } @@ -138,7 +136,7 @@ func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListR Page: req.Page, Size: req.Size, } - wordList, total, err := words.List(ctx, query) + wordList, total, err := c.words.List(ctx, query) if err != nil { return nil, err } diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" index 12f9e5c1560..e7aa5a5d920 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.6.\345\215\225\350\257\215\350\257\246\346\203\205.md" @@ -38,7 +38,7 @@ type DetailRes struct { ```go ... -func Detail(ctx context.Context, uid, id uint) (word *entity.Words, err error) { +func (w *Words) Detail(ctx context.Context, uid, id uint) (word *entity.Words, err error) { word = &entity.Words{} db := dao.Words.Ctx(ctx).Where("id", id) if uid > 0 { @@ -58,19 +58,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" - "star/api/words/v1" ) func (c *ControllerV1) Detail(ctx context.Context, req *v1.DetailReq) (res *v1.DetailRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - word, err := words.Detail(ctx, uid, req.Id) + word, err := c.words.Detail(ctx, uid, req.Id) if err != nil { return nil, err } diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" index f390a634208..2490f84b562 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\345\233\233\347\253\240-\345\215\225\350\257\215\347\256\241\347\220\206/4.7.\345\210\240\351\231\244\345\215\225\350\257\215.md" @@ -25,7 +25,7 @@ type DeleteRes struct { *internal/logic/words/words.go* ```go ... -func Delete(ctx context.Context, uid, id uint) (err error) { +func (w *Words) Delete(ctx context.Context, uid, id uint) (err error) { db := dao.Words.Ctx(ctx).Where("id", id) if uid > 0 { db = db.Where("uid", uid) @@ -44,18 +44,16 @@ package words import ( "context" - "star/internal/logic/users" - "star/internal/logic/words" "star/api/words/v1" ) func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) { - uid, err := users.GetUid(ctx) + uid, err := c.users.GetUid(ctx) if err != nil { return nil, err } - err = words.Delete(ctx, uid, req.Id) + err = c.words.Delete(ctx, uid, req.Id) return } ```