feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package authMethod
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/perfect-panel/server/internal/svc"
|
|
"github.com/perfect-panel/server/internal/types"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
"github.com/perfect-panel/server/pkg/tool"
|
|
"github.com/perfect-panel/server/pkg/xerr"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type GetAuthMethodListLogic struct {
|
|
logger.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// NewGetAuthMethodListLogic Get auth method list
|
|
func NewGetAuthMethodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAuthMethodListLogic {
|
|
return &GetAuthMethodListLogic{
|
|
Logger: logger.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetAuthMethodListLogic) GetAuthMethodList() (resp *types.GetAuthMethodListResponse, err error) {
|
|
methods, err := l.svcCtx.AuthModel.FindAll(l.ctx)
|
|
if err != nil {
|
|
l.Errorw("find all failed", logger.Field("error", err.Error()))
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find all failed: %v", err.Error())
|
|
}
|
|
var list []types.AuthMethodConfig
|
|
for _, method := range methods {
|
|
var item types.AuthMethodConfig
|
|
tool.DeepCopy(&item, method)
|
|
if method.Config != "" {
|
|
if err := json.Unmarshal([]byte(method.Config), &item.Config); err != nil {
|
|
l.Errorw("unmarshal config failed", logger.Field("config", method.Config), logger.Field("error", err.Error()))
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "unmarshal config failed: %v", err.Error())
|
|
}
|
|
}
|
|
list = append(list, item)
|
|
}
|
|
return &types.GetAuthMethodListResponse{List: list}, nil
|
|
}
|