37 lines
771 B
Smarty
Raw Normal View History

2023-06-05 17:56:55 +08:00
package svc
import (
{{.configImport}}
2023-06-21 12:21:56 +08:00
"errors"
"fmt"
"net/http"
2023-07-26 10:52:33 +08:00
"fusenapi/utils/autoconfig"
2023-06-12 14:05:35 +08:00
"fusenapi/initalize"
2023-06-21 12:21:56 +08:00
"fusenapi/model/gmodel"
2023-06-12 14:05:35 +08:00
"gorm.io/gorm"
2023-06-13 12:15:06 +08:00
"github.com/golang-jwt/jwt"
2023-06-05 17:56:55 +08:00
)
type ServiceContext struct {
Config {{.config}}
{{.middleware}}
2023-07-26 10:52:33 +08:00
SharedState *fsm.StateCluster
2023-06-12 14:05:35 +08:00
MysqlConn *gorm.DB
2023-06-21 12:21:56 +08:00
AllModels *gmodel.AllModelsGen
2023-06-05 17:56:55 +08:00
}
func NewServiceContext(c {{.config}}) *ServiceContext {
2023-07-26 10:52:33 +08:00
conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.Name, fmt.Sprintf("localhost:%d", c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
2023-06-12 15:17:42 +08:00
2023-06-05 17:56:55 +08:00
return &ServiceContext{
2023-07-26 10:52:33 +08:00
Config: c,
MysqlConn: conn,
SharedState: StateServer,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
2023-06-05 17:56:55 +08:00
{{.middlewareAssignment}}
}
2023-06-12 15:17:42 +08:00
}