修改为龙舟
This commit is contained in:
parent
7fd48edef8
commit
fe51e85983
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -52,4 +52,6 @@ server/product-model/product-model
|
||||||
server/product-template/product-template
|
server/product-template/product-template
|
||||||
server/shopping-cart-confirmation/shopping-cart-confirmation
|
server/shopping-cart-confirmation/shopping-cart-confirmation
|
||||||
server/upload/upload
|
server/upload/upload
|
||||||
server/webset/webset
|
server/webset/webset
|
||||||
|
|
||||||
|
shared-state
|
115
fsm/main.go
115
fsm/main.go
|
@ -3,11 +3,9 @@ package fsm
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/utils/autoconfig"
|
"fusenapi/utils/autoconfig"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -44,17 +42,14 @@ var addresses []string = []string{
|
||||||
"localhost:5502",
|
"localhost:5502",
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartNode(replicaID uint64, exampleShardID uint64, addr string, gdb *gorm.DB) *dragonboat.NodeHost {
|
var shardID uint64 = 128
|
||||||
|
|
||||||
|
func StartNode(ServerID uint64, serverconfigs []*autoconfig.ConfigServer, gdb *gorm.DB) *SharedState {
|
||||||
|
|
||||||
// addr := "localhost"
|
// addr := "localhost"
|
||||||
|
|
||||||
// addr = fmt.Sprintf("%s:%d", addr, port)
|
// addr = fmt.Sprintf("%s:%d", addr, port)
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
if len(addr) == 0 && replicaID != 1 && replicaID != 2 && replicaID != 3 {
|
|
||||||
fmt.Fprintf(os.Stderr, "node id must be 1, 2 or 3 when address is not specified\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
// https://github.com/golang/go/issues/17393
|
// https://github.com/golang/go/issues/17393
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
signal.Ignore(syscall.Signal(0xd))
|
signal.Ignore(syscall.Signal(0xd))
|
||||||
|
@ -67,17 +62,18 @@ func StartNode(replicaID uint64, exampleShardID uint64, addr string, gdb *gorm.D
|
||||||
// leave the initialMembers to be empty. we still populate the initialMembers
|
// leave the initialMembers to be empty. we still populate the initialMembers
|
||||||
// here for simplicity.
|
// here for simplicity.
|
||||||
|
|
||||||
for idx, v := range addresses {
|
for _, v := range serverconfigs {
|
||||||
// key is the ReplicaID, ReplicaID is not allowed to be 0
|
// key is the ReplicaID, ReplicaID is not allowed to be 0
|
||||||
// value is the raft address
|
// value is the raft address
|
||||||
initialMembers[uint64(idx+1)] = v
|
|
||||||
|
initialMembers[v.ReplicaId] = fmt.Sprintf("%s:%d", v.Host, v.Port-2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for simplicity, in this example program, addresses of all those 3 initial
|
// for simplicity, in this example program, addresses of all those 3 initial
|
||||||
// raft members are hard coded. when address is not specified on the command
|
// raft members are hard coded. when address is not specified on the command
|
||||||
// line, we assume the node being launched is an initial raft member.
|
// line, we assume the node being launched is an initial raft member.
|
||||||
|
|
||||||
var nodeAddr = initialMembers[uint64(replicaID)]
|
var nodeAddr = initialMembers[ServerID]
|
||||||
|
|
||||||
fmt.Fprintf(os.Stdout, "node address: %s\n", nodeAddr)
|
fmt.Fprintf(os.Stdout, "node address: %s\n", nodeAddr)
|
||||||
// change the log verbosity
|
// change the log verbosity
|
||||||
|
@ -89,8 +85,8 @@ func StartNode(replicaID uint64, exampleShardID uint64, addr string, gdb *gorm.D
|
||||||
// See GoDoc for all available options
|
// See GoDoc for all available options
|
||||||
rc := config.Config{
|
rc := config.Config{
|
||||||
// ShardID and ReplicaID of the raft node
|
// ShardID and ReplicaID of the raft node
|
||||||
ReplicaID: uint64(replicaID),
|
ReplicaID: uint64(ServerID),
|
||||||
ShardID: exampleShardID,
|
ShardID: shardID,
|
||||||
|
|
||||||
ElectionRTT: 10,
|
ElectionRTT: 10,
|
||||||
|
|
||||||
|
@ -102,9 +98,8 @@ func StartNode(replicaID uint64, exampleShardID uint64, addr string, gdb *gorm.D
|
||||||
CompactionOverhead: 5,
|
CompactionOverhead: 5,
|
||||||
}
|
}
|
||||||
datadir := filepath.Join(
|
datadir := filepath.Join(
|
||||||
"example-data",
|
"shared-state",
|
||||||
"queue-data",
|
fmt.Sprintf("node%d", ServerID))
|
||||||
fmt.Sprintf("node%d", replicaID))
|
|
||||||
|
|
||||||
nhc := config.NodeHostConfig{
|
nhc := config.NodeHostConfig{
|
||||||
|
|
||||||
|
@ -124,95 +119,19 @@ func StartNode(replicaID uint64, exampleShardID uint64, addr string, gdb *gorm.D
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := nh.StartReplica(initialMembers, false, New, rc); err != nil {
|
if err := nh.StartReplica(initialMembers, false, NewFsStateMachine, rc); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to add cluster, %v\n", err)
|
fmt.Fprintf(os.Stderr, "failed to add cluster, %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nh
|
ss := &SharedState{
|
||||||
|
shardID: shardID,
|
||||||
}
|
replicaID: ServerID,
|
||||||
|
nh: nh,
|
||||||
// StartNode 启动节点
|
|
||||||
func StartNode1(ServerID string, RaftBind string, serverconfigs []*autoconfig.ConfigServer, gdb *gorm.DB) *FsStateMachine {
|
|
||||||
|
|
||||||
fsm := &FsStateMachine{
|
|
||||||
store: make(map[int64]*UserState),
|
|
||||||
|
|
||||||
gdb: gdb,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var retainSnapshotCount = 2
|
return ss
|
||||||
// var ServerID string = "fs1"
|
|
||||||
// var RaftBind string = "localhost:5500"
|
|
||||||
var RaftDir string = fmt.Sprintf("/tmp/raftdir/%s", ServerID)
|
|
||||||
|
|
||||||
// Setup Raft configuration.
|
|
||||||
config := raft.DefaultConfig()
|
|
||||||
config.LocalID = raft.ServerID(ServerID)
|
|
||||||
|
|
||||||
// Setup Raft communication.
|
|
||||||
addr, err := net.ResolveTCPAddr("tcp", RaftBind)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
transport, err := raft.NewTCPTransport(RaftBind, addr, 3, 30*time.Second, os.Stderr)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the snapshot store. This allows the Raft to truncate the log.
|
|
||||||
snapshots, err := raft.NewFileSnapshotStore(RaftDir, retainSnapshotCount, os.Stderr)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("file snapshot store: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the log store and stable store.
|
|
||||||
logStore := raft.NewInmemStore()
|
|
||||||
stableStore := raft.NewInmemStore()
|
|
||||||
|
|
||||||
// Create the Raft system.
|
|
||||||
fsm.ra, err = raft.NewRaft(config, fsm, logStore, stableStore, snapshots, transport)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dup map[string]bool = make(map[string]bool)
|
|
||||||
var rserver []raft.Server = []raft.Server{
|
|
||||||
{
|
|
||||||
Suffrage: raft.Voter,
|
|
||||||
ID: config.LocalID,
|
|
||||||
Address: transport.LocalAddr(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
dup[string(config.LocalID)] = true
|
|
||||||
dup[string("backend")] = true
|
|
||||||
dup[string("product-model")] = true
|
|
||||||
dup[string("product-template")] = true
|
|
||||||
|
|
||||||
for _, cfg := range serverconfigs {
|
|
||||||
if _, ok := dup[cfg.Name]; !ok {
|
|
||||||
dup[cfg.Name] = true
|
|
||||||
rserver = append(rserver, raft.Server{
|
|
||||||
Suffrage: raft.Voter,
|
|
||||||
ID: raft.ServerID(cfg.Name),
|
|
||||||
Address: raft.ServerAddress(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port-2000)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
configuration := raft.Configuration{
|
|
||||||
Servers: rserver,
|
|
||||||
}
|
|
||||||
|
|
||||||
fu := fsm.ra.BootstrapCluster(configuration)
|
|
||||||
if err := fu.Error(); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForCluster(fsm.ra)
|
|
||||||
|
|
||||||
return fsm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func JoinCluster(ServerID string, LeaderAddress string, RaftBind string, gdb *gorm.DB) *StateCluster {
|
// func JoinCluster(ServerID string, LeaderAddress string, RaftBind string, gdb *gorm.DB) *StateCluster {
|
||||||
|
|
|
@ -26,7 +26,7 @@ type ServiceContext struct {
|
||||||
|
|
||||||
func NewServiceContext(c {{.config}}) *ServiceContext {
|
func NewServiceContext(c {{.config}}) *ServiceContext {
|
||||||
conn := initalize.InitMysql(c.SourceMysql)
|
conn := initalize.InitMysql(c.SourceMysql)
|
||||||
StateServer := fsm.StartNode(c.Name, fmt.Sprintf("localhost:%d", c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,6 +10,7 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
|
|
||||||
MainAddress string
|
MainAddress string
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("localhost:%d", c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.SharedState
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
AllModels *gmodel.AllModelsGen
|
AllModels *gmodel.AllModelsGen
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/canteen/internal/types"
|
"fusenapi/server/canteen/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
types "fusenapi/server/data-transfer/internal/types"
|
types "fusenapi/server/data-transfer/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,6 +10,7 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
|
|
||||||
MainAddress string
|
MainAddress string
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/inventory/internal/types"
|
"fusenapi/server/inventory/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/map-library/internal/types"
|
"fusenapi/server/map-library/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/orders/internal/types"
|
"fusenapi/server/orders/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,6 +10,7 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
PayConfig struct {
|
PayConfig struct {
|
||||||
Stripe struct {
|
Stripe struct {
|
||||||
EndpointSecret string
|
EndpointSecret string
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/product-model/internal/types"
|
"fusenapi/server/product-model/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/product-template-tag/internal/types"
|
"fusenapi/server/product-template-tag/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/product-template/internal/types"
|
"fusenapi/server/product-template/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.SharedState
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
AllModels *gmodel.AllModelsGen
|
AllModels *gmodel.AllModelsGen
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,6 +10,7 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
Env string
|
Env string
|
||||||
AWS struct {
|
AWS struct {
|
||||||
S3 struct {
|
S3 struct {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.SharedState
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
AllModels *gmodel.AllModelsGen
|
AllModels *gmodel.AllModelsGen
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -10,5 +10,6 @@ type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
ReplicaId uint64
|
||||||
SourceRabbitMq string
|
SourceRabbitMq string
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *fsm.FsStateMachine
|
SharedState *fsm.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.Name, fmt.Sprintf("%s:%d", c.Host, c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
|
StateServer := fsm.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
|
@ -12,9 +12,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigServer struct {
|
type ConfigServer struct {
|
||||||
Name string
|
Name string
|
||||||
Host string `yaml:"Host"`
|
Host string `yaml:"Host"`
|
||||||
Port int `yaml:"Port"`
|
Port int `yaml:"Port"`
|
||||||
|
ReplicaId uint64 `yaml:"ReplicaId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func AutoGetAllServerConfig() []*ConfigServer {
|
func AutoGetAllServerConfig() []*ConfigServer {
|
||||||
|
|
|
@ -51,7 +51,7 @@ func NormalAfterLogic(w http.ResponseWriter, r *http.Request, resp *Response) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestParse(w http.ResponseWriter, r *http.Request, state *fsm.FsStateMachine, LogicRequest any) (*auth.UserInfo, error) {
|
func RequestParse(w http.ResponseWriter, r *http.Request, state *fsm.SharedState, LogicRequest any) (*auth.UserInfo, error) {
|
||||||
|
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user