fusenapi/server/ldap-admin/internal/svc/servicecontext.go

30 lines
821 B
Go
Raw Normal View History

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