fusenapi/server/ldap-admin/internal/svc/servicecontext.go
laodaming 53a99c36b1 fix
2023-11-22 10:12:46 +08:00

30 lines
821 B
Go

package svc
import (
"fusenapi/initalize"
"fusenapi/model/gmodel"
"fusenapi/server/ldap-admin/internal/config"
"fusenapi/utils/ldap_lib"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
RabbitMq *initalize.RabbitMqHandle
Ldap *ldap_lib.Ldap
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
ldapConn := initalize.InitLdap(c.Ldap.Host, c.Ldap.BindDN, c.Ldap.Password)
return &ServiceContext{
Config: c,
MysqlConn: conn,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
Ldap: ldap_lib.NewLdap(ldapConn, c.Ldap.BaseDN, c.Ldap.RootDN, c.Ldap.PeopleGroupDN, c.Auth.AccessSecret),
}
}