From 1913beb3f79dd5869f651db77ec375c0f041df2d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 9 Aug 2023 16:54:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81=E6=9C=BA?= =?UTF-8?q?=E7=9A=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/auth/internal/svc/servicecontext.go | 6 +++--- server/backend/internal/svc/servicecontext.go | 4 ++-- server/canteen/internal/svc/servicecontext.go | 6 +++--- server/data-transfer/internal/svc/servicecontext.go | 6 +++--- server/home-user-auth/internal/svc/servicecontext.go | 6 +++--- server/inventory/internal/svc/servicecontext.go | 6 +++--- server/map-library/internal/svc/servicecontext.go | 6 +++--- server/orders/internal/svc/servicecontext.go | 6 +++--- server/pay/internal/svc/servicecontext.go | 6 +++--- server/product-template-tag/internal/svc/servicecontext.go | 6 +++--- server/product/internal/svc/servicecontext.go | 4 ++-- server/render/internal/svc/servicecontext.go | 6 +++--- server/resource/internal/handler/logocombinehandler.go | 2 +- server/resource/internal/svc/servicecontext.go | 4 ++-- .../internal/svc/servicecontext.go | 6 +++--- server/upload/internal/svc/servicecontext.go | 4 ++-- server/webset/internal/svc/servicecontext.go | 6 +++--- server/websocket/internal/svc/servicecontext.go | 6 +++--- {fsm => shared}/main.go | 2 +- {fsm => shared}/main_test.go | 2 +- {fsm => shared}/shared_state.go | 7 +------ {fsm => shared}/sm.go | 2 +- {fsm => shared}/sm_update_handler.go | 2 +- utils/basic/request_parse.go | 4 ++-- 24 files changed, 55 insertions(+), 60 deletions(-) rename {fsm => shared}/main.go (99%) rename {fsm => shared}/main_test.go (80%) rename {fsm => shared}/shared_state.go (90%) rename {fsm => shared}/sm.go (99%) rename {fsm => shared}/sm_update_handler.go (98%) diff --git a/server/auth/internal/svc/servicecontext.go b/server/auth/internal/svc/servicecontext.go index 4b5bd92d..bd2be563 100644 --- a/server/auth/internal/svc/servicecontext.go +++ b/server/auth/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/auth/internal/config" + "fusenapi/shared" "fusenapi/utils/auth" "fusenapi/utils/autoconfig" "net/http" @@ -18,7 +18,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -28,7 +28,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/backend/internal/svc/servicecontext.go b/server/backend/internal/svc/servicecontext.go index ecf8fd2a..49689eb0 100644 --- a/server/backend/internal/svc/servicecontext.go +++ b/server/backend/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/backend/internal/config" + "fusenapi/shared" "net/http" "time" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen diff --git a/server/canteen/internal/svc/servicecontext.go b/server/canteen/internal/svc/servicecontext.go index 61a3a516..e70048f5 100644 --- a/server/canteen/internal/svc/servicecontext.go +++ b/server/canteen/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/canteen/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/data-transfer/internal/svc/servicecontext.go b/server/data-transfer/internal/svc/servicecontext.go index 692e7ace..2cfc4926 100644 --- a/server/data-transfer/internal/svc/servicecontext.go +++ b/server/data-transfer/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/data-transfer/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/home-user-auth/internal/svc/servicecontext.go b/server/home-user-auth/internal/svc/servicecontext.go index d2a1256a..9acce867 100644 --- a/server/home-user-auth/internal/svc/servicecontext.go +++ b/server/home-user-auth/internal/svc/servicecontext.go @@ -1,9 +1,9 @@ package svc import ( - "fusenapi/fsm" "fusenapi/initalize" "fusenapi/model/gmodel" + "fusenapi/shared" "fusenapi/utils/autoconfig" "github.com/golang-jwt/jwt" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/inventory/internal/svc/servicecontext.go b/server/inventory/internal/svc/servicecontext.go index 8d3dc8c2..18251bcc 100644 --- a/server/inventory/internal/svc/servicecontext.go +++ b/server/inventory/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/inventory/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/map-library/internal/svc/servicecontext.go b/server/map-library/internal/svc/servicecontext.go index d4bb4043..9b25dd0c 100644 --- a/server/map-library/internal/svc/servicecontext.go +++ b/server/map-library/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/map-library/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/orders/internal/svc/servicecontext.go b/server/orders/internal/svc/servicecontext.go index fec62caf..6e07178e 100644 --- a/server/orders/internal/svc/servicecontext.go +++ b/server/orders/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/orders/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/pay/internal/svc/servicecontext.go b/server/pay/internal/svc/servicecontext.go index 9e048ef0..146721fd 100644 --- a/server/pay/internal/svc/servicecontext.go +++ b/server/pay/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/pay/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/product-template-tag/internal/svc/servicecontext.go b/server/product-template-tag/internal/svc/servicecontext.go index 64b7d6c8..e5976906 100644 --- a/server/product-template-tag/internal/svc/servicecontext.go +++ b/server/product-template-tag/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/product-template-tag/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/product/internal/svc/servicecontext.go b/server/product/internal/svc/servicecontext.go index 1815c519..9f2456cf 100644 --- a/server/product/internal/svc/servicecontext.go +++ b/server/product/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/product/internal/config" + "fusenapi/shared" "net/http" "fusenapi/initalize" @@ -16,7 +16,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen diff --git a/server/render/internal/svc/servicecontext.go b/server/render/internal/svc/servicecontext.go index c720554c..0615ddda 100644 --- a/server/render/internal/svc/servicecontext.go +++ b/server/render/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/render/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -26,7 +26,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/resource/internal/handler/logocombinehandler.go b/server/resource/internal/handler/logocombinehandler.go index 23c1589c..fd2801b4 100644 --- a/server/resource/internal/handler/logocombinehandler.go +++ b/server/resource/internal/handler/logocombinehandler.go @@ -15,7 +15,7 @@ func LogoCombineHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.LogoCombineReq - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req) if err != nil { return } diff --git a/server/resource/internal/svc/servicecontext.go b/server/resource/internal/svc/servicecontext.go index 69f90fb9..2ed5fca3 100644 --- a/server/resource/internal/svc/servicecontext.go +++ b/server/resource/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/resource/internal/config" + "fusenapi/shared" "net/http" "fusenapi/initalize" @@ -19,7 +19,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen diff --git a/server/shopping-cart-confirmation/internal/svc/servicecontext.go b/server/shopping-cart-confirmation/internal/svc/servicecontext.go index 251c4f47..35bd8a39 100644 --- a/server/shopping-cart-confirmation/internal/svc/servicecontext.go +++ b/server/shopping-cart-confirmation/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/shopping-cart-confirmation/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/upload/internal/svc/servicecontext.go b/server/upload/internal/svc/servicecontext.go index 5263c0af..be5f2f25 100644 --- a/server/upload/internal/svc/servicecontext.go +++ b/server/upload/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/upload/internal/config" + "fusenapi/shared" "net/http" "fusenapi/initalize" @@ -19,7 +19,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen diff --git a/server/webset/internal/svc/servicecontext.go b/server/webset/internal/svc/servicecontext.go index 142cdfef..546f6ab4 100644 --- a/server/webset/internal/svc/servicecontext.go +++ b/server/webset/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/webset/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -25,7 +25,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/server/websocket/internal/svc/servicecontext.go b/server/websocket/internal/svc/servicecontext.go index 153148f8..c5132776 100644 --- a/server/websocket/internal/svc/servicecontext.go +++ b/server/websocket/internal/svc/servicecontext.go @@ -3,8 +3,8 @@ package svc import ( "errors" "fmt" - "fusenapi/fsm" "fusenapi/server/websocket/internal/config" + "fusenapi/shared" "fusenapi/utils/autoconfig" "net/http" @@ -17,7 +17,7 @@ import ( type ServiceContext struct { Config config.Config - SharedState *fsm.SharedState + SharedState *shared.SharedState MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen @@ -26,7 +26,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) - StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) + StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) return &ServiceContext{ Config: c, diff --git a/fsm/main.go b/shared/main.go similarity index 99% rename from fsm/main.go rename to shared/main.go index f4ed95c9..67b70cfe 100644 --- a/fsm/main.go +++ b/shared/main.go @@ -1,4 +1,4 @@ -package fsm +package shared import ( "bytes" diff --git a/fsm/main_test.go b/shared/main_test.go similarity index 80% rename from fsm/main_test.go rename to shared/main_test.go index 8e635b6a..0e1b77de 100644 --- a/fsm/main_test.go +++ b/shared/main_test.go @@ -1,4 +1,4 @@ -package fsm +package shared import "testing" diff --git a/fsm/shared_state.go b/shared/shared_state.go similarity index 90% rename from fsm/shared_state.go rename to shared/shared_state.go index 57516193..46c9c446 100644 --- a/fsm/shared_state.go +++ b/shared/shared_state.go @@ -1,4 +1,4 @@ -package fsm +package shared import ( "context" @@ -25,11 +25,6 @@ func (ss *SharedState) GetUserState(Userid int64) (us *UserState, err error) { return ius.(*UserState), nil } - // cmd := &Command{ - // Op: OP_Update, - // Key: Userid, - // } - cs := ss.nh.GetNoOPSession(128) cmd := &CmdUpdate{UserId: Userid} diff --git a/fsm/sm.go b/shared/sm.go similarity index 99% rename from fsm/sm.go rename to shared/sm.go index f9301e79..117ca7b4 100644 --- a/fsm/sm.go +++ b/shared/sm.go @@ -1,4 +1,4 @@ -package fsm +package shared import ( "context" diff --git a/fsm/sm_update_handler.go b/shared/sm_update_handler.go similarity index 98% rename from fsm/sm_update_handler.go rename to shared/sm_update_handler.go index f0fa1d8b..a6105df0 100644 --- a/fsm/sm_update_handler.go +++ b/shared/sm_update_handler.go @@ -1,4 +1,4 @@ -package fsm +package shared import ( "context" diff --git a/utils/basic/request_parse.go b/utils/basic/request_parse.go index 71443c83..5603aa5b 100644 --- a/utils/basic/request_parse.go +++ b/utils/basic/request_parse.go @@ -2,7 +2,7 @@ package basic import ( "errors" - "fusenapi/fsm" + "fusenapi/shared" "fusenapi/utils/auth" "net/http" "reflect" @@ -51,7 +51,7 @@ func NormalAfterLogic(w http.ResponseWriter, r *http.Request, resp *Response) { } } -func RequestParse(w http.ResponseWriter, r *http.Request, state *fsm.SharedState, LogicRequest any) (*auth.UserInfo, error) { +func RequestParse(w http.ResponseWriter, r *http.Request, state *shared.SharedState, LogicRequest any) (*auth.UserInfo, error) { // log.Println(io.ReadAll(r.Body)) token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息 if err != nil {