diff --git a/internal/services/company/controller/company_controller.go b/internal/services/company/controller/company_controller.go index a6f9068..3ccdd09 100644 --- a/internal/services/company/controller/company_controller.go +++ b/internal/services/company/controller/company_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/company/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type CompanyController struct { - app.Controller[entities.Company, request.CompanyUpsertRequest] + crud.Controller[entities.Company, request.CompanyUpsertRequest] } func (ctr *CompanyController) InitRoutes(r *echo.Group) { diff --git a/internal/services/company/controller/company_department_controller.go b/internal/services/company/controller/company_department_controller.go index c20f7d9..c18836e 100644 --- a/internal/services/company/controller/company_department_controller.go +++ b/internal/services/company/controller/company_department_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/company/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type CompanyDepartmentController struct { - app.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest] + crud.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest] } func (c *CompanyDepartmentController) InitRoutes(r *echo.Group) { diff --git a/internal/services/company/controller/company_staff_controller.go b/internal/services/company/controller/company_staff_controller.go index 8135744..a5b6c55 100644 --- a/internal/services/company/controller/company_staff_controller.go +++ b/internal/services/company/controller/company_staff_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/company/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type CompanyStaffController struct { - app.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest] + crud.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest] } func (c *CompanyStaffController) InitRoutes(r *echo.Group) { diff --git a/internal/services/company/service.go b/internal/services/company/service.go index 5356eaf..e13c0e7 100644 --- a/internal/services/company/service.go +++ b/internal/services/company/service.go @@ -2,7 +2,7 @@ package company import ( "sorbet/internal/services/company/controller" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type Service struct{} @@ -15,7 +15,7 @@ func (*Service) Priority() int { return 1 } -func (*Service) Init(ctx *app.Context) error { +func (*Service) Init(ctx *crud.Context) error { ctx.Routes(&controller.CompanyController{}) ctx.Routes(&controller.CompanyDepartmentController{}) ctx.Routes(&controller.CompanyStaffController{}) diff --git a/internal/services/config/controller/config_controller.go b/internal/services/config/controller/config_controller.go index 8381a72..6e6fe68 100644 --- a/internal/services/config/controller/config_controller.go +++ b/internal/services/config/controller/config_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/config/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type ConfigController struct { - app.Controller[entities.Config, request.ConfigUpsertRequest] + crud.Controller[entities.Config, request.ConfigUpsertRequest] } func (ctr *ConfigController) InitRoutes(r *echo.Group) { diff --git a/internal/services/config/controller/config_group_controller.go b/internal/services/config/controller/config_group_controller.go index 185e911..8832301 100644 --- a/internal/services/config/controller/config_group_controller.go +++ b/internal/services/config/controller/config_group_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/config/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type ConfigGroupController struct { - app.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest] + crud.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest] } // InitRoutes 实现路由注册接口 diff --git a/internal/services/config/service.go b/internal/services/config/service.go index 86e168f..16c26f2 100644 --- a/internal/services/config/service.go +++ b/internal/services/config/service.go @@ -2,7 +2,7 @@ package config import ( "sorbet/internal/services/config/controller" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type Service struct{} @@ -15,7 +15,7 @@ func (*Service) Priority() int { return 0 } -func (*Service) Init(ctx *app.Context) error { +func (*Service) Init(ctx *crud.Context) error { ctx.Routes(&controller.ConfigGroupController{}) ctx.Routes(&controller.ConfigController{}) return nil diff --git a/internal/services/feature/controller/feature_category_controller.go b/internal/services/feature/controller/feature_category_controller.go index 473ed43..086ea71 100644 --- a/internal/services/feature/controller/feature_category_controller.go +++ b/internal/services/feature/controller/feature_category_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureCategoryController struct { - app.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest] + crud.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest] } func (f *FeatureCategoryController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/controller/feature_config_controller.go b/internal/services/feature/controller/feature_config_controller.go index 9006c9c..eb367ff 100644 --- a/internal/services/feature/controller/feature_config_controller.go +++ b/internal/services/feature/controller/feature_config_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureConfigController struct { - app.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest] + crud.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest] } func (f *FeatureConfigController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/controller/feature_content_chapter_controller.go b/internal/services/feature/controller/feature_content_chapter_controller.go index 15db1ca..1565c1d 100644 --- a/internal/services/feature/controller/feature_content_chapter_controller.go +++ b/internal/services/feature/controller/feature_content_chapter_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureContentChapterController struct { - app.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest] + crud.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest] } func (f *FeatureContentChapterController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/controller/feature_content_controller.go b/internal/services/feature/controller/feature_content_controller.go index 1a05c4c..3cf395c 100644 --- a/internal/services/feature/controller/feature_content_controller.go +++ b/internal/services/feature/controller/feature_content_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureContentController struct { - app.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest] + crud.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest] } func (f *FeatureContentController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/controller/feature_content_detail_controller.go b/internal/services/feature/controller/feature_content_detail_controller.go index 0cbfd9c..2aa32e9 100644 --- a/internal/services/feature/controller/feature_content_detail_controller.go +++ b/internal/services/feature/controller/feature_content_detail_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureContentDetailController struct { - app.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest] + crud.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest] } func (f *FeatureContentDetailController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/controller/feature_controller.go b/internal/services/feature/controller/feature_controller.go index eb6c3f5..c8c9ba9 100644 --- a/internal/services/feature/controller/feature_controller.go +++ b/internal/services/feature/controller/feature_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/feature/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type FeatureController struct { - app.Controller[entities.Feature, request.FeatureUpsertRequest] + crud.Controller[entities.Feature, request.FeatureUpsertRequest] } func (f *FeatureController) InitRoutes(r *echo.Group) { diff --git a/internal/services/feature/service.go b/internal/services/feature/service.go index 2462f9c..76dc27c 100644 --- a/internal/services/feature/service.go +++ b/internal/services/feature/service.go @@ -2,7 +2,7 @@ package feature import ( "sorbet/internal/services/feature/controller" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type Service struct{} @@ -15,7 +15,7 @@ func (*Service) Priority() int { return 3 } -func (s *Service) Init(ctx *app.Context) error { +func (s *Service) Init(ctx *crud.Context) error { ctx.Routes(&controller.FeatureCategoryController{}) ctx.Routes(&controller.FeatureConfigController{}) ctx.Routes(&controller.FeatureContentChapterController{}) diff --git a/internal/services/resource/controller/resource_category_controller.go b/internal/services/resource/controller/resource_category_controller.go index 55e0588..42f9503 100644 --- a/internal/services/resource/controller/resource_category_controller.go +++ b/internal/services/resource/controller/resource_category_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/resource/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type ResourceCategoryController struct { - app.Controller[entities.Resource, request.ResourceCategoryUpsertRequest] + crud.Controller[entities.Resource, request.ResourceCategoryUpsertRequest] } func (ctr *ResourceCategoryController) InitRoutes(r *echo.Group) { diff --git a/internal/services/resource/controller/resource_controller.go b/internal/services/resource/controller/resource_controller.go index 0b8bcf0..6cbd262 100644 --- a/internal/services/resource/controller/resource_controller.go +++ b/internal/services/resource/controller/resource_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/resource/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type ResourceController struct { - app.Controller[entities.Resource, request.ResourceUpsertRequest] + crud.Controller[entities.Resource, request.ResourceUpsertRequest] } func (ctr *ResourceController) InitRoutes(r *echo.Group) { diff --git a/internal/services/resource/service.go b/internal/services/resource/service.go index 69192be..2ca7355 100644 --- a/internal/services/resource/service.go +++ b/internal/services/resource/service.go @@ -2,7 +2,7 @@ package resource import ( "sorbet/internal/services/resource/controller" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type Service struct{} @@ -15,7 +15,7 @@ func (*Service) Priority() int { return 2 } -func (*Service) Init(ctx *app.Context) error { +func (*Service) Init(ctx *crud.Context) error { ctx.Routes(&controller.ResourceController{}) ctx.Routes(&controller.ResourceCategoryController{}) return nil diff --git a/internal/services/service.go b/internal/services/service.go index 3b69d36..6b677df 100644 --- a/internal/services/service.go +++ b/internal/services/service.go @@ -10,12 +10,14 @@ import ( "sorbet/internal/services/feature" "sorbet/internal/services/resource" "sorbet/internal/services/system" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) -var services []app.Service +var services []crud.Service -func Register(service app.Service) error { +const ContextEchoKey = "echo_framework" + +func Register(service crud.Service) error { for _, applet := range services { if applet.Name() == service.Name() { return errors.New("service already registered") @@ -25,8 +27,8 @@ func Register(service app.Service) error { return nil } -func Init() { - services = []app.Service{ +func Init(ctx context.Context) error { + services = []crud.Service{ &config.Service{}, &company.Service{}, &resource.Service{}, @@ -35,15 +37,17 @@ func Init() { } // 按优先级排序 - slices.SortFunc(services, func(a, b app.Service) int { + slices.SortFunc(services, func(a, b crud.Service) int { return b.Priority() - a.Priority() }) + + return nil } func Bootstrap(ctx context.Context) error { - e := ctx.Value("echo_framework").(*echo.Echo) + e := ctx.Value(ContextEchoKey).(*echo.Echo) for _, service := range services { - err := service.Init(app.NewContext(ctx, e.Group(""))) + err := service.Init(crud.NewContext(ctx, e.Group(""))) if err != nil { return err } diff --git a/internal/services/system/controller/system_log_controller.go b/internal/services/system/controller/system_log_controller.go index 285397d..1f0d8c2 100644 --- a/internal/services/system/controller/system_log_controller.go +++ b/internal/services/system/controller/system_log_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemLogController struct { - app.Controller[entities.SystemLog, request.SystemLogUpsertRequest] + crud.Controller[entities.SystemLog, request.SystemLogUpsertRequest] } func (s *SystemLogController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/controller/system_menu_controller.go b/internal/services/system/controller/system_menu_controller.go index d0bb9dc..013651f 100644 --- a/internal/services/system/controller/system_menu_controller.go +++ b/internal/services/system/controller/system_menu_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemMenuController struct { - app.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest] + crud.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest] } func (s *SystemMenuController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/controller/system_permission_controller.go b/internal/services/system/controller/system_permission_controller.go index f03f7d7..7d98bdd 100644 --- a/internal/services/system/controller/system_permission_controller.go +++ b/internal/services/system/controller/system_permission_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemPermissionController struct { - app.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest] + crud.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest] } func (s *SystemPermissionController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/controller/system_role_controller.go b/internal/services/system/controller/system_role_controller.go index ff33d2d..ad97e45 100644 --- a/internal/services/system/controller/system_role_controller.go +++ b/internal/services/system/controller/system_role_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemRoleController struct { - app.Controller[entities.SystemRole, request.SystemRoleUpsertRequest] + crud.Controller[entities.SystemRole, request.SystemRoleUpsertRequest] } func (s *SystemRoleController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/controller/system_role_power_controller.go b/internal/services/system/controller/system_role_power_controller.go index 6e51391..10c0739 100644 --- a/internal/services/system/controller/system_role_power_controller.go +++ b/internal/services/system/controller/system_role_power_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemRolePowerController struct { - app.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest] + crud.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest] } func (s *SystemRolePowerController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/controller/system_user_controller.go b/internal/services/system/controller/system_user_controller.go index 962b98d..af432c1 100644 --- a/internal/services/system/controller/system_user_controller.go +++ b/internal/services/system/controller/system_user_controller.go @@ -4,11 +4,11 @@ import ( "github.com/labstack/echo/v4" "sorbet/internal/entities" "sorbet/internal/services/system/request" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type SystemUserController struct { - app.Controller[entities.SystemUser, request.SystemUserUpsertRequest] + crud.Controller[entities.SystemUser, request.SystemUserUpsertRequest] } func (s *SystemUserController) InitRoutes(r *echo.Group) { diff --git a/internal/services/system/service.go b/internal/services/system/service.go index 4b9d620..b55f975 100644 --- a/internal/services/system/service.go +++ b/internal/services/system/service.go @@ -2,7 +2,7 @@ package system import ( "sorbet/internal/services/system/controller" - "sorbet/pkg/app" + "sorbet/pkg/crud" ) type Service struct{} @@ -15,7 +15,7 @@ func (*Service) Priority() int { return 3 } -func (s *Service) Init(ctx *app.Context) error { +func (s *Service) Init(ctx *crud.Context) error { ctx.Routes(&controller.SystemLogController{}) ctx.Routes(&controller.SystemMenuController{}) ctx.Routes(&controller.SystemPermissionController{}) diff --git a/pkg/app/context.go b/pkg/crud/context.go similarity index 98% rename from pkg/app/context.go rename to pkg/crud/context.go index 60a85f8..512932a 100644 --- a/pkg/app/context.go +++ b/pkg/crud/context.go @@ -1,4 +1,4 @@ -package app +package crud import ( "context" diff --git a/pkg/app/controller.go b/pkg/crud/controller.go similarity index 99% rename from pkg/app/controller.go rename to pkg/crud/controller.go index 76f6c1d..849e0e8 100644 --- a/pkg/app/controller.go +++ b/pkg/crud/controller.go @@ -1,4 +1,4 @@ -package app +package crud import ( "github.com/labstack/echo/v4" diff --git a/pkg/app/echo_utils.go b/pkg/crud/echo_utils.go similarity index 99% rename from pkg/app/echo_utils.go rename to pkg/crud/echo_utils.go index 0194ccc..ad2371b 100644 --- a/pkg/app/echo_utils.go +++ b/pkg/crud/echo_utils.go @@ -1,4 +1,4 @@ -package app +package crud import ( "github.com/labstack/echo/v4" diff --git a/pkg/app/service.go b/pkg/crud/service.go similarity index 96% rename from pkg/app/service.go rename to pkg/crud/service.go index 2b63e16..6602f65 100644 --- a/pkg/app/service.go +++ b/pkg/crud/service.go @@ -1,4 +1,4 @@ -package app +package crud import "github.com/labstack/echo/v4"