From 367e0b018bd00f309e8c35de85486733846890dc Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 11 Nov 2022 14:44:57 +0800 Subject: [PATCH] optimize source code layout --- internal/mirc/README.md | 1 + internal/proto/RADME.md | 2 ++ internal/servants/{ => core}/core.go | 10 +++---- internal/servants/servants.go | 4 +-- .../servants/{web_admin.go => web/admin.go} | 2 +- .../servants/{web_alipay.go => web/alipay.go} | 2 +- .../servants/{web_core.go => web/core.go} | 27 ++++++++----------- .../{web_followship.go => web/followship.go} | 2 +- .../{web_friendship.go => web/friendship.go} | 2 +- .../servants/{web_loose.go => web/loose.go} | 2 +- .../servants/{web_priv.go => web/priv.go} | 2 +- internal/servants/{web_pub.go => web/pub.go} | 2 +- internal/servants/web/web.go | 17 ++++++++++++ internal/version/version.go | 8 ++++++ 14 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 internal/mirc/README.md create mode 100644 internal/proto/RADME.md rename internal/servants/{ => core}/core.go (60%) rename internal/servants/{web_admin.go => web/admin.go} (69%) rename internal/servants/{web_alipay.go => web/alipay.go} (69%) rename internal/servants/{web_core.go => web/core.go} (50%) rename internal/servants/{web_followship.go => web/followship.go} (71%) rename internal/servants/{web_friendship.go => web/friendship.go} (71%) rename internal/servants/{web_loose.go => web/loose.go} (69%) rename internal/servants/{web_priv.go => web/priv.go} (68%) rename internal/servants/{web_pub.go => web/pub.go} (67%) create mode 100644 internal/servants/web/web.go create mode 100644 internal/version/version.go diff --git a/internal/mirc/README.md b/internal/mirc/README.md new file mode 100644 index 00000000..5b2162a2 --- /dev/null +++ b/internal/mirc/README.md @@ -0,0 +1 @@ +### RESTful API for paopao-ce use [go-mir](https://github.com/alimy/mir) to generate service interface code automatic. diff --git a/internal/proto/RADME.md b/internal/proto/RADME.md new file mode 100644 index 00000000..05d78ece --- /dev/null +++ b/internal/proto/RADME.md @@ -0,0 +1,2 @@ +### gRPC API +This directory contain some gRPC API define files. diff --git a/internal/servants/core.go b/internal/servants/core/core.go similarity index 60% rename from internal/servants/core.go rename to internal/servants/core/core.go index 6deb274c..6bedfa92 100644 --- a/internal/servants/core.go +++ b/internal/servants/core/core.go @@ -1,23 +1,23 @@ -package servants +package core import ( "github.com/gin-gonic/gin" "github.com/rocboss/paopao-ce/internal/model" ) -type baseServant struct { +type BaseServant struct { // TODO } -type baseBinding struct { +type BaseBinding struct { // TODO } -type baseRender struct { +type BaseRender struct { // TODO } -func (baseServant) userFrom(c *gin.Context) (*model.User, bool) { +func (BaseServant) userFrom(c *gin.Context) (*model.User, bool) { if u, exists := c.Get("USER"); exists { user, ok := u.(*model.User) return user, ok diff --git a/internal/servants/servants.go b/internal/servants/servants.go index cc808cdb..9cd595c7 100644 --- a/internal/servants/servants.go +++ b/internal/servants/servants.go @@ -2,11 +2,11 @@ package servants import ( "github.com/gin-gonic/gin" - api "github.com/rocboss/paopao-ce/internal/mirc/auto/api/v1" + "github.com/rocboss/paopao-ce/internal/servants/web" ) // RegisterServants register all the servants to gin.Engine func RegisterServants(e *gin.Engine) { - api.RegisterWebCoreServant(e, newWebCoreSrv(), newWebCoreBinding(), newWebCoreRender()) + api.RegisterWebCoreServant(e, web.NewWebCoreSrv(), web.NewWebCoreBinding(), web.NewWebCoreRender()) } diff --git a/internal/servants/web_admin.go b/internal/servants/web/admin.go similarity index 69% rename from internal/servants/web_admin.go rename to internal/servants/web/admin.go index f527df8a..f97832ce 100644 --- a/internal/servants/web_admin.go +++ b/internal/servants/web/admin.go @@ -1,4 +1,4 @@ -package servants +package web type webAdminSrv struct { // TODO diff --git a/internal/servants/web_alipay.go b/internal/servants/web/alipay.go similarity index 69% rename from internal/servants/web_alipay.go rename to internal/servants/web/alipay.go index 680a3df8..a4f71e9f 100644 --- a/internal/servants/web_alipay.go +++ b/internal/servants/web/alipay.go @@ -1,4 +1,4 @@ -package servants +package web type webAlipaySrv struct { // TODO diff --git a/internal/servants/web_core.go b/internal/servants/web/core.go similarity index 50% rename from internal/servants/web_core.go rename to internal/servants/web/core.go index 027676b8..579b51b4 100644 --- a/internal/servants/web_core.go +++ b/internal/servants/web/core.go @@ -1,32 +1,27 @@ -package servants +package web import ( api "github.com/rocboss/paopao-ce/internal/mirc/auto/api/v1" + "github.com/rocboss/paopao-ce/internal/servants/core" +) + +var ( + _ api.WebCore = (*webCoreSrv)(nil) + _ api.WebCoreBinding = (*webCoreBinding)(nil) + _ api.WebCoreRender = (*webCoreRender)(nil) ) type webCoreSrv struct { - baseServant + core.BaseServant api.UnimplementedWebCoreServant } type webCoreBinding struct { - baseBinding + core.BaseBinding api.UnimplementedWebCoreBinding } type webCoreRender struct { - baseRender + core.BaseRender api.UnimplementedWebCoreRender } - -func newWebCoreSrv() api.WebCore { - return &webCoreSrv{} -} - -func newWebCoreBinding() api.WebCoreBinding { - return &webCoreBinding{} -} - -func newWebCoreRender() api.WebCoreRender { - return &webCoreRender{} -} diff --git a/internal/servants/web_followship.go b/internal/servants/web/followship.go similarity index 71% rename from internal/servants/web_followship.go rename to internal/servants/web/followship.go index f069d8e7..6965c4a5 100644 --- a/internal/servants/web_followship.go +++ b/internal/servants/web/followship.go @@ -1,4 +1,4 @@ -package servants +package web type webFollowshipSrv struct { // TODO diff --git a/internal/servants/web_friendship.go b/internal/servants/web/friendship.go similarity index 71% rename from internal/servants/web_friendship.go rename to internal/servants/web/friendship.go index 63bd9896..87690037 100644 --- a/internal/servants/web_friendship.go +++ b/internal/servants/web/friendship.go @@ -1,4 +1,4 @@ -package servants +package web type webFriendshipSrv struct { // TODO diff --git a/internal/servants/web_loose.go b/internal/servants/web/loose.go similarity index 69% rename from internal/servants/web_loose.go rename to internal/servants/web/loose.go index 04eaa907..051a86ef 100644 --- a/internal/servants/web_loose.go +++ b/internal/servants/web/loose.go @@ -1,4 +1,4 @@ -package servants +package web type webLooseSrv struct { // TODO diff --git a/internal/servants/web_priv.go b/internal/servants/web/priv.go similarity index 68% rename from internal/servants/web_priv.go rename to internal/servants/web/priv.go index 8a0a830e..efe80d49 100644 --- a/internal/servants/web_priv.go +++ b/internal/servants/web/priv.go @@ -1,4 +1,4 @@ -package servants +package web type webPrivSrv struct { // TODO diff --git a/internal/servants/web_pub.go b/internal/servants/web/pub.go similarity index 67% rename from internal/servants/web_pub.go rename to internal/servants/web/pub.go index d66a09b2..2b55e3ac 100644 --- a/internal/servants/web_pub.go +++ b/internal/servants/web/pub.go @@ -1,4 +1,4 @@ -package servants +package web type webPubSrv struct { // TODO diff --git a/internal/servants/web/web.go b/internal/servants/web/web.go new file mode 100644 index 00000000..5f505dc1 --- /dev/null +++ b/internal/servants/web/web.go @@ -0,0 +1,17 @@ +package web + +import ( + api "github.com/rocboss/paopao-ce/internal/mirc/auto/api/v1" +) + +func NewWebCoreSrv() api.WebCore { + return &webCoreSrv{} +} + +func NewWebCoreBinding() api.WebCoreBinding { + return &webCoreBinding{} +} + +func NewWebCoreRender() api.WebCoreRender { + return &webCoreRender{} +} diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 00000000..b3bcb903 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,8 @@ +package version + +var ( + // GitHash Value will be set during build + GitHash = "" + // BuildTime Value will be set during build + BuildTime = "" +)