修改状态机的写法

This commit is contained in:
eson 2023-08-09 16:54:52 +08:00
parent ca80a94f72
commit 1913beb3f7
24 changed files with 55 additions and 60 deletions

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/auth/internal/config" "fusenapi/server/auth/internal/config"
"fusenapi/shared"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -18,7 +18,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -28,7 +28,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/backend/internal/config" "fusenapi/server/backend/internal/config"
"fusenapi/shared"
"net/http" "net/http"
"time" "time"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/canteen/internal/config" "fusenapi/server/canteen/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/data-transfer/internal/config" "fusenapi/server/data-transfer/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -1,9 +1,9 @@
package svc package svc
import ( import (
"fusenapi/fsm"
"fusenapi/initalize" "fusenapi/initalize"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"github.com/golang-jwt/jwt" "github.com/golang-jwt/jwt"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/inventory/internal/config" "fusenapi/server/inventory/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/map-library/internal/config" "fusenapi/server/map-library/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/orders/internal/config" "fusenapi/server/orders/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/pay/internal/config" "fusenapi/server/pay/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/product-template-tag/internal/config" "fusenapi/server/product-template-tag/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/product/internal/config" "fusenapi/server/product/internal/config"
"fusenapi/shared"
"net/http" "net/http"
"fusenapi/initalize" "fusenapi/initalize"
@ -16,7 +16,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/render/internal/config" "fusenapi/server/render/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -26,7 +26,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -15,7 +15,7 @@ func LogoCombineHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.LogoCombineReq var req types.LogoCombineReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req) userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil { if err != nil {
return return
} }

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/resource/internal/config" "fusenapi/server/resource/internal/config"
"fusenapi/shared"
"net/http" "net/http"
"fusenapi/initalize" "fusenapi/initalize"
@ -19,7 +19,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/shopping-cart-confirmation/internal/config" "fusenapi/server/shopping-cart-confirmation/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/upload/internal/config" "fusenapi/server/upload/internal/config"
"fusenapi/shared"
"net/http" "net/http"
"fusenapi/initalize" "fusenapi/initalize"
@ -19,7 +19,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/webset/internal/config" "fusenapi/server/webset/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -25,7 +25,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -3,8 +3,8 @@ package svc
import ( import (
"errors" "errors"
"fmt" "fmt"
"fusenapi/fsm"
"fusenapi/server/websocket/internal/config" "fusenapi/server/websocket/internal/config"
"fusenapi/shared"
"fusenapi/utils/autoconfig" "fusenapi/utils/autoconfig"
"net/http" "net/http"
@ -17,7 +17,7 @@ import (
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
SharedState *fsm.SharedState SharedState *shared.SharedState
MysqlConn *gorm.DB MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen AllModels *gmodel.AllModelsGen
@ -26,7 +26,7 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql) conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,

View File

@ -1,4 +1,4 @@
package fsm package shared
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package fsm package shared
import "testing" import "testing"

View File

@ -1,4 +1,4 @@
package fsm package shared
import ( import (
"context" "context"
@ -25,11 +25,6 @@ func (ss *SharedState) GetUserState(Userid int64) (us *UserState, err error) {
return ius.(*UserState), nil return ius.(*UserState), nil
} }
// cmd := &Command{
// Op: OP_Update,
// Key: Userid,
// }
cs := ss.nh.GetNoOPSession(128) cs := ss.nh.GetNoOPSession(128)
cmd := &CmdUpdate{UserId: Userid} cmd := &CmdUpdate{UserId: Userid}

View File

@ -1,4 +1,4 @@
package fsm package shared
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package fsm package shared
import ( import (
"context" "context"

View File

@ -2,7 +2,7 @@ package basic
import ( import (
"errors" "errors"
"fusenapi/fsm" "fusenapi/shared"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"net/http" "net/http"
"reflect" "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)) // log.Println(io.ReadAll(r.Body))
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息 token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息
if err != nil { if err != nil {