@@ -26,12 +26,26 @@ import (
2626 "github.com/coze-dev/coze-loop/backend/pkg/logs"
2727)
2828
29+ func NewUserApplication (
30+ userService service.IUserService ,
31+ configFactory conf.IConfigLoaderFactory ,
32+ ) (user.UserService , error ) {
33+ loader , _ := configFactory .NewConfigLoader ("foundation.yaml" )
34+ return & UserApplicationImpl {
35+ userService : userService ,
36+ registerController : userRegisterController {
37+ configLoader : loader ,
38+ },
39+ }, nil
40+ }
41+
2942type UserApplicationImpl struct {
3043 userService service.IUserService
3144 registerController userRegisterController
3245}
3346
3447type userRegisterController struct {
48+ // configLoader weak dependency, might be nil
3549 configLoader conf.IConfigLoader
3650}
3751
@@ -41,8 +55,11 @@ type userRegisterControlConfig struct {
4155}
4256
4357func (u * userRegisterController ) allowRegister (ctx context.Context , email string ) bool {
44- const keyUserRegisterControl = "user_register_control"
58+ if u .configLoader == nil {
59+ return true
60+ }
4561
62+ const keyUserRegisterControl = "user_register_control"
4663 var config userRegisterControlConfig
4764 if err := u .configLoader .UnmarshalKey (ctx , keyUserRegisterControl , & config ); err != nil {
4865 logs .CtxWarn (ctx , "load user_register_control config fail, err: %v" , err )
@@ -55,22 +72,6 @@ func (u *userRegisterController) allowRegister(ctx context.Context, email string
5572 return slices .Contains (config .AllowedEmails , email )
5673}
5774
58- func NewUserApplication (
59- userService service.IUserService ,
60- configFactory conf.IConfigLoaderFactory ,
61- ) (user.UserService , error ) {
62- loader , err := configFactory .NewConfigLoader ("foundation.yaml" )
63- if err != nil {
64- return nil , err
65- }
66- return & UserApplicationImpl {
67- userService : userService ,
68- registerController : userRegisterController {
69- configLoader : loader ,
70- },
71- }, nil
72- }
73-
7475func (u * UserApplicationImpl ) Register (ctx context.Context , request * user.UserRegisterRequest ) (r * user.UserRegisterResponse , err error ) {
7576 if err := u .validateRegisterReq (ctx , request ); err != nil {
7677 return nil , err
0 commit comments