remove interfaces
This commit is contained in:
11
config.toml
11
config.toml
@@ -88,12 +88,12 @@ ShowLine = true
|
||||
LogInConsole = true
|
||||
|
||||
[Database]
|
||||
Driver = "sqlite"
|
||||
Driver = "mysql"
|
||||
|
||||
[Database.MySQL]
|
||||
Host = "localhost"
|
||||
Host = "10.47.119.226"
|
||||
Port = 3306
|
||||
Database = "demos11"
|
||||
Database = "atom"
|
||||
Username = "root"
|
||||
Password = "root"
|
||||
Prefix = ""
|
||||
@@ -106,8 +106,7 @@ Engine = "InnoDB"
|
||||
File = "sqlite.db"
|
||||
|
||||
[Database.Redis]
|
||||
Host = "localhost"
|
||||
Port = 3306
|
||||
Host = "10.47.119.226"
|
||||
Port = 6379
|
||||
Database = 0
|
||||
Username = ""
|
||||
Password = ""
|
||||
|
||||
@@ -10,11 +10,7 @@ import (
|
||||
"github.com/rogeecn/gen"
|
||||
)
|
||||
|
||||
type PermissionController interface {
|
||||
Get(ctx *gin.Context) (string, error)
|
||||
}
|
||||
|
||||
type permissionControllerImpl struct {
|
||||
type PermissionController struct {
|
||||
jwt *jwt.JWT
|
||||
rbac rbac.IRbac
|
||||
}
|
||||
@@ -22,11 +18,11 @@ type permissionControllerImpl struct {
|
||||
func NewPermissionController(
|
||||
jwt *jwt.JWT,
|
||||
rbac rbac.IRbac,
|
||||
) PermissionController {
|
||||
return &permissionControllerImpl{rbac: rbac, jwt: jwt}
|
||||
) *PermissionController {
|
||||
return &PermissionController{rbac: rbac, jwt: jwt}
|
||||
}
|
||||
|
||||
func (c *permissionControllerImpl) Get(ctx *gin.Context) (string, error) {
|
||||
func (c *PermissionController) Get(ctx *gin.Context) (string, error) {
|
||||
claimsCtx, exists := ctx.Get(jwt.CtxKey)
|
||||
if !exists {
|
||||
return "", gen.NewBusError(http.StatusBadRequest, http.StatusBadRequest, "Token 获取失败")
|
||||
|
||||
@@ -10,45 +10,37 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type RoleController interface {
|
||||
GetByFilter(*gin.Context, dto.RoleRequestFilter, request.PageFilter) (*response.PageResponse[*models.SysRole], error)
|
||||
Tree(*gin.Context) ([]*dto.RoleTree, error)
|
||||
Create(*gin.Context, dto.RoleRequestForm) error
|
||||
Delete(*gin.Context, int) error
|
||||
UpdateByID(*gin.Context, int, dto.RoleRequestForm) error
|
||||
}
|
||||
|
||||
type roleControllerImpl struct {
|
||||
type RoleController struct {
|
||||
roleSvc service.RoleService
|
||||
}
|
||||
|
||||
func NewRoleController(
|
||||
roleSvc service.RoleService,
|
||||
) RoleController {
|
||||
return &roleControllerImpl{
|
||||
) *RoleController {
|
||||
return &RoleController{
|
||||
roleSvc: roleSvc,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *roleControllerImpl) GetByFilter(
|
||||
func (c *RoleController) GetByFilter(
|
||||
ctx *gin.Context,
|
||||
filter dto.RoleRequestFilter,
|
||||
page request.PageFilter,
|
||||
) (*response.PageResponse[*models.SysRole], error) {
|
||||
return c.roleSvc.GetByFilter(ctx, filter, page)
|
||||
}
|
||||
func (c *roleControllerImpl) Tree(ctx *gin.Context) ([]*dto.RoleTree, error) {
|
||||
func (c *RoleController) Tree(ctx *gin.Context) ([]*dto.RoleTree, error) {
|
||||
return c.roleSvc.Tree(ctx)
|
||||
}
|
||||
|
||||
func (c *roleControllerImpl) Create(ctx *gin.Context, req dto.RoleRequestForm) error {
|
||||
func (c *RoleController) Create(ctx *gin.Context, req dto.RoleRequestForm) error {
|
||||
_, err := c.roleSvc.Create(ctx, req)
|
||||
return err
|
||||
}
|
||||
func (c *roleControllerImpl) UpdateByID(ctx *gin.Context, id int, req dto.RoleRequestForm) error {
|
||||
func (c *RoleController) UpdateByID(ctx *gin.Context, id int, req dto.RoleRequestForm) error {
|
||||
_, err := c.roleSvc.UpdateByID(ctx, uint64(id), req)
|
||||
return err
|
||||
}
|
||||
func (c *roleControllerImpl) Delete(ctx *gin.Context, id int) error {
|
||||
func (c *RoleController) Delete(ctx *gin.Context, id int) error {
|
||||
return c.roleSvc.DeleteByID(ctx, uint64(id))
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UserController interface {
|
||||
Login(*gin.Context, dto.LoginRequestForm) (*dto.LoginResponse, error)
|
||||
}
|
||||
|
||||
type userControllerImpl struct {
|
||||
type UserController struct {
|
||||
conf *config.Config
|
||||
user service.UserService
|
||||
jwt *jwt.JWT
|
||||
@@ -23,15 +19,15 @@ func NewUserController(
|
||||
conf *config.Config,
|
||||
user service.UserService,
|
||||
jwt *jwt.JWT,
|
||||
) UserController {
|
||||
return &userControllerImpl{
|
||||
) *UserController {
|
||||
return &UserController{
|
||||
conf: conf,
|
||||
user: user,
|
||||
jwt: jwt,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *userControllerImpl) Login(ctx *gin.Context, req dto.LoginRequestForm) (*dto.LoginResponse, error) {
|
||||
func (c *UserController) Login(ctx *gin.Context, req dto.LoginRequestForm) (*dto.LoginResponse, error) {
|
||||
user, err := c.user.AuthMatchPassword(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -8,25 +8,15 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type RoleDao interface {
|
||||
GetByFilter(context.Context, dto.RoleRequestFilter, request.PageFilter) ([]*models.SysRole, uint64, error)
|
||||
FindByID(context.Context, uint64) (*models.SysRole, error)
|
||||
Create(context.Context, *models.SysRole) (*models.SysRole, error)
|
||||
UpdateByID(context.Context, *models.SysRole) (*models.SysRole, error)
|
||||
DeleteByID(context.Context, uint64) error
|
||||
DeletePermanentlyByID(context.Context, uint64) error
|
||||
All(context.Context) ([]*models.SysRole, error)
|
||||
}
|
||||
|
||||
type roleDaoImpl struct {
|
||||
type RoleDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewRoleDao(query *query.Query) RoleDao {
|
||||
return &roleDaoImpl{query: query}
|
||||
func NewRoleDao(query *query.Query) *RoleDao {
|
||||
return &RoleDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) GetByFilter(ctx context.Context, filter dto.RoleRequestFilter, page request.PageFilter) ([]*models.SysRole, uint64, error) {
|
||||
func (dao *RoleDao) GetByFilter(ctx context.Context, filter dto.RoleRequestFilter, page request.PageFilter) ([]*models.SysRole, uint64, error) {
|
||||
role := dao.query.SysRole
|
||||
query := role.WithContext(ctx)
|
||||
|
||||
@@ -55,17 +45,17 @@ func (dao *roleDaoImpl) GetByFilter(ctx context.Context, filter dto.RoleRequestF
|
||||
return items, uint64(total), nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) All(ctx context.Context) ([]*models.SysRole, error) {
|
||||
func (dao *RoleDao) All(ctx context.Context) ([]*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
return role.WithContext(ctx).Find()
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) FindByID(ctx context.Context, id uint64) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) FindByID(ctx context.Context, id uint64) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
return role.WithContext(ctx).Where(role.ID.Eq(id)).First()
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) Create(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) Create(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
if err := role.WithContext(ctx).Create(model); err != nil {
|
||||
return nil, err
|
||||
@@ -73,7 +63,7 @@ func (dao *roleDaoImpl) Create(ctx context.Context, model *models.SysRole) (*mod
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) UpdateByID(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) UpdateByID(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Where(role.ID.Eq(model.ID)).Updates(model)
|
||||
if err != nil {
|
||||
@@ -82,13 +72,13 @@ func (dao *roleDaoImpl) UpdateByID(ctx context.Context, model *models.SysRole) (
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) DeleteByID(ctx context.Context, id uint64) error {
|
||||
func (dao *RoleDao) DeleteByID(ctx context.Context, id uint64) error {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Where(role.ID.Eq(id)).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) DeletePermanentlyByID(ctx context.Context, id uint64) error {
|
||||
func (dao *RoleDao) DeletePermanentlyByID(ctx context.Context, id uint64) error {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Unscoped().Where(role.ID.Eq(id)).Delete()
|
||||
return err
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
type RoleInjectParams struct {
|
||||
dig.In
|
||||
DB *gorm.DB
|
||||
Dao RoleDao
|
||||
Dao *RoleDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
@@ -6,24 +6,20 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserDao interface {
|
||||
Create(context.Context, *models.User) (*models.User, error)
|
||||
}
|
||||
|
||||
type userDaoImpl struct {
|
||||
type UserDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewUserDao(query *query.Query) UserDao {
|
||||
return &userDaoImpl{query: query}
|
||||
func NewUserDao(query *query.Query) *UserDao {
|
||||
return &UserDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *userDaoImpl) FindByID(ctx context.Context, id uint64) (*models.User, error) {
|
||||
func (dao *UserDao) FindByID(ctx context.Context, id uint64) (*models.User, error) {
|
||||
user := dao.query.User
|
||||
return user.WithContext(ctx).Where(user.ID.Eq(id)).First()
|
||||
}
|
||||
|
||||
func (dao *userDaoImpl) Create(ctx context.Context, model *models.User) (*models.User, error) {
|
||||
func (dao *UserDao) Create(ctx context.Context, model *models.User) (*models.User, error) {
|
||||
user := dao.query.User
|
||||
if err := user.WithContext(ctx).Create(model); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -6,28 +6,21 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserRoleDao interface {
|
||||
Exists(context.Context, int) bool
|
||||
Create(context.Context, int, int) error
|
||||
Update(context.Context, int, int) error
|
||||
Delete(context.Context, int, int) error
|
||||
}
|
||||
|
||||
type userRoleDaoImpl struct {
|
||||
type UserRoleDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewUserRoleDao(query *query.Query) UserRoleDao {
|
||||
return &userRoleDaoImpl{query: query}
|
||||
func NewUserRoleDao(query *query.Query) *UserRoleDao {
|
||||
return &UserRoleDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Exists(ctx context.Context, userID int) bool {
|
||||
func (dao *UserRoleDao) Exists(ctx context.Context, userID int) bool {
|
||||
userRole := dao.query.UserRole
|
||||
count, _ := userRole.WithContext(ctx).Where(userRole.UserID.Eq(uint64(userID))).Count()
|
||||
return count > 0
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Create(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Create(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
return userRole.WithContext(ctx).Create(&models.UserRole{
|
||||
UserID: uint64(userID),
|
||||
@@ -35,13 +28,13 @@ func (dao *userRoleDaoImpl) Create(ctx context.Context, userID, roleID int) erro
|
||||
})
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Update(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Update(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
_, err := userRole.WithContext(ctx).Where(userRole.UserID.Eq(uint64(userID))).Update(userRole.RoleID, roleID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Delete(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Delete(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
_, err := userRole.WithContext(ctx).
|
||||
Where(userRole.UserID.Eq(uint64(userID))).
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserRoleInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *gorm.DB
|
||||
Dao UserRoleDao
|
||||
Dao *UserRoleDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *gorm.DB
|
||||
Dao UserDao
|
||||
Dao *UserDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
@@ -10,15 +10,7 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type RoleService interface {
|
||||
GetByFilter(context.Context, dto.RoleRequestFilter, request.PageFilter) (*response.PageResponse[*models.SysRole], error)
|
||||
Create(context.Context, dto.RoleRequestForm) (*models.SysRole, error)
|
||||
Tree(context.Context) ([]*dto.RoleTree, error)
|
||||
UpdateByID(context.Context, uint64, dto.RoleRequestForm) (*models.SysRole, error)
|
||||
DeleteByID(context.Context, uint64) error
|
||||
}
|
||||
|
||||
type roleService struct {
|
||||
type RoleService struct {
|
||||
dao dao.RoleDao
|
||||
uuid *uuid.Generator
|
||||
}
|
||||
@@ -26,14 +18,14 @@ type roleService struct {
|
||||
func NewRoleService(
|
||||
dao dao.RoleDao,
|
||||
uuid *uuid.Generator,
|
||||
) RoleService {
|
||||
return &roleService{
|
||||
) *RoleService {
|
||||
return &RoleService{
|
||||
dao: dao,
|
||||
uuid: uuid,
|
||||
}
|
||||
}
|
||||
|
||||
func (svc *roleService) GetByFilter(
|
||||
func (svc *RoleService) GetByFilter(
|
||||
ctx context.Context,
|
||||
filter dto.RoleRequestFilter,
|
||||
page request.PageFilter,
|
||||
@@ -49,7 +41,7 @@ func (svc *roleService) GetByFilter(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (svc *roleService) treeMaker(ctx context.Context, models []*models.SysRole, pid uint64) []*dto.RoleTree {
|
||||
func (svc *RoleService) treeMaker(ctx context.Context, models []*models.SysRole, pid uint64) []*dto.RoleTree {
|
||||
items := []*dto.RoleTree{}
|
||||
for _, model := range models {
|
||||
if model.ParentID == pid {
|
||||
@@ -66,7 +58,7 @@ func (svc *roleService) treeMaker(ctx context.Context, models []*models.SysRole,
|
||||
return items
|
||||
}
|
||||
|
||||
func (svc *roleService) Tree(ctx context.Context) ([]*dto.RoleTree, error) {
|
||||
func (svc *RoleService) Tree(ctx context.Context) ([]*dto.RoleTree, error) {
|
||||
models, err := svc.dao.All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -75,7 +67,7 @@ func (svc *roleService) Tree(ctx context.Context) ([]*dto.RoleTree, error) {
|
||||
return svc.treeMaker(ctx, models, 0), nil
|
||||
}
|
||||
|
||||
func (svc *roleService) Create(ctx context.Context, req dto.RoleRequestForm) (*models.SysRole, error) {
|
||||
func (svc *RoleService) Create(ctx context.Context, req dto.RoleRequestForm) (*models.SysRole, error) {
|
||||
model := models.SysRole{
|
||||
UUID: svc.uuid.MustGenerate(),
|
||||
Name: req.Name,
|
||||
@@ -84,7 +76,7 @@ func (svc *roleService) Create(ctx context.Context, req dto.RoleRequestForm) (*m
|
||||
}
|
||||
return svc.dao.Create(ctx, &model)
|
||||
}
|
||||
func (svc *roleService) UpdateByID(ctx context.Context, id uint64, req dto.RoleRequestForm) (*models.SysRole, error) {
|
||||
func (svc *RoleService) UpdateByID(ctx context.Context, id uint64, req dto.RoleRequestForm) (*models.SysRole, error) {
|
||||
model, err := svc.dao.FindByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,6 +89,6 @@ func (svc *roleService) UpdateByID(ctx context.Context, id uint64, req dto.RoleR
|
||||
return svc.dao.UpdateByID(ctx, model)
|
||||
}
|
||||
|
||||
func (svc *roleService) DeleteByID(ctx context.Context, id uint64) error {
|
||||
func (svc *RoleService) DeleteByID(ctx context.Context, id uint64) error {
|
||||
return svc.dao.DeleteByID(ctx, id)
|
||||
}
|
||||
|
||||
@@ -8,13 +8,7 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserService interface {
|
||||
AttachRole(context.Context, int, int) error
|
||||
AuthMatchPassword(context.Context, *dto.LoginRequestForm) (*models.User, error)
|
||||
GenerateJWTTokenFromUser(context.Context, *models.User) (string, error)
|
||||
}
|
||||
|
||||
type userService struct {
|
||||
type UserService struct {
|
||||
userRoleDao dao.UserRoleDao
|
||||
userDao dao.UserDao
|
||||
jwt *jwt.JWT
|
||||
@@ -24,28 +18,28 @@ func NewUserService(
|
||||
userRoleDao dao.UserRoleDao,
|
||||
userDao dao.UserDao,
|
||||
jwt *jwt.JWT,
|
||||
) UserService {
|
||||
return &userService{
|
||||
) *UserService {
|
||||
return &UserService{
|
||||
userRoleDao: userRoleDao,
|
||||
userDao: userDao,
|
||||
jwt: jwt,
|
||||
}
|
||||
}
|
||||
|
||||
func (svc *userService) AttachRole(ctx context.Context, userID, roleID int) error {
|
||||
func (svc *UserService) AttachRole(ctx context.Context, userID, roleID int) error {
|
||||
if svc.userRoleDao.Exists(ctx, userID) {
|
||||
return svc.userRoleDao.Update(ctx, userID, roleID)
|
||||
}
|
||||
return svc.userRoleDao.Create(ctx, userID, roleID)
|
||||
}
|
||||
|
||||
func (svc *userService) DetachRole(ctx context.Context, userID, roleID int) error {
|
||||
func (svc *UserService) DetachRole(ctx context.Context, userID, roleID int) error {
|
||||
if !svc.userRoleDao.Exists(ctx, userID) {
|
||||
return nil
|
||||
}
|
||||
return svc.userRoleDao.Delete(ctx, userID, roleID)
|
||||
}
|
||||
func (svc *userService) AuthMatchPassword(ctx context.Context, req *dto.LoginRequestForm) (*models.User, error) {
|
||||
func (svc *UserService) AuthMatchPassword(ctx context.Context, req *dto.LoginRequestForm) (*models.User, error) {
|
||||
return &models.User{
|
||||
ID: 10,
|
||||
UUID: "1",
|
||||
@@ -57,7 +51,7 @@ func (svc *userService) AuthMatchPassword(ctx context.Context, req *dto.LoginReq
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (svc *userService) GenerateJWTTokenFromUser(ctx context.Context, user *models.User) (string, error) {
|
||||
func (svc *UserService) GenerateJWTTokenFromUser(ctx context.Context, user *models.User) (string, error) {
|
||||
return svc.jwt.CreateToken(svc.jwt.CreateClaims(jwt.BaseClaims{
|
||||
UID: user.ID,
|
||||
Role: user.RoleID,
|
||||
|
||||
@@ -7,11 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type CaptchaController interface {
|
||||
Show(*gin.Context) (*captcha.CaptchaResponse, error)
|
||||
}
|
||||
|
||||
type captchaControllerImpl struct {
|
||||
type CaptchaController struct {
|
||||
conf *config.Config
|
||||
captcha *captcha.Captcha
|
||||
}
|
||||
@@ -19,13 +15,13 @@ type captchaControllerImpl struct {
|
||||
func NewCaptchaController(
|
||||
conf *config.Config,
|
||||
captcha *captcha.Captcha,
|
||||
) CaptchaController {
|
||||
return &captchaControllerImpl{
|
||||
) *CaptchaController {
|
||||
return &CaptchaController{
|
||||
conf: conf,
|
||||
captcha: captcha,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *captchaControllerImpl) Show(ctx *gin.Context) (*captcha.CaptchaResponse, error) {
|
||||
func (c *CaptchaController) Show(ctx *gin.Context) (*captcha.CaptchaResponse, error) {
|
||||
return c.captcha.Generate()
|
||||
}
|
||||
|
||||
@@ -8,20 +8,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Dao interface {
|
||||
Release(context.Context, int, string) error
|
||||
}
|
||||
|
||||
type DaoImpl struct {
|
||||
type Dao struct {
|
||||
Conf *config.Config
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewDao(DB *gorm.DB) Dao {
|
||||
return &DaoImpl{DB: DB}
|
||||
func NewDao(DB *gorm.DB) *Dao {
|
||||
return &Dao{DB: DB}
|
||||
}
|
||||
|
||||
func (c *DaoImpl) Release(ctx context.Context, a int, b string) error {
|
||||
func (c *Dao) Release(ctx context.Context, a int, b string) error {
|
||||
if a == 20 {
|
||||
return errors.New("A cant't be 20 ")
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestDaoImpl_Release(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := &DaoImpl{
|
||||
c := &Dao{
|
||||
Conf: tt.fields.Conf,
|
||||
DB: tt.fields.DB,
|
||||
}
|
||||
|
||||
@@ -4,13 +4,10 @@ import (
|
||||
"atom/modules/system/dao"
|
||||
)
|
||||
|
||||
type SystemService interface {
|
||||
}
|
||||
|
||||
type systemService struct {
|
||||
type SystemService struct {
|
||||
dao dao.Dao
|
||||
}
|
||||
|
||||
func NewSystemService(dao dao.Dao) SystemService {
|
||||
return &systemService{dao: dao}
|
||||
func NewSystemService(dao dao.Dao) *SystemService {
|
||||
return &SystemService{dao: dao}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user