fusenapi/goctl_template/api/context.tpl
2023-07-27 10:18:49 +08:00

37 lines
771 B
Smarty

package svc
import (
{{.configImport}}
"errors"
"fmt"
"net/http"
"fusenapi/utils/autoconfig"
"fusenapi/initalize"
"fusenapi/model/gmodel"
"gorm.io/gorm"
"github.com/golang-jwt/jwt"
)
type ServiceContext struct {
Config {{.config}}
{{.middleware}}
SharedState *fsm.StateCluster
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
}
func NewServiceContext(c {{.config}}) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
StateServer := fsm.StartNode(c.Name, fmt.Sprintf("localhost:%d", c.Port-2000), autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{
Config: c,
MysqlConn: conn,
SharedState: StateServer,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
{{.middlewareAssignment}}
}
}