Skip to content

Release v1.5.0#88

Merged
Aliothmoon merged 2 commits into
mainfrom
dev
Jun 8, 2026
Merged

Release v1.5.0#88
Aliothmoon merged 2 commits into
mainfrom
dev

Conversation

@Aliothmoon

@Aliothmoon Aliothmoon commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary by Sourcery

添加只读的管理员资源管理 API 以及配套的数据模型、组装逻辑和仓储/业务层,并进行少量依赖更新。

New Features:

  • 暴露管理员 REST 端点,用于列出资源、获取资源详情,以及带分页和过滤功能的资源版本列表。
  • 引入通用的分页响应封装结构,以及用于 API 响应的管理员专用资源和版本 DTO。
  • 添加请求模型,以支持包含 page、size 和 filter 参数的管理员列表查询。

Enhancements:

  • 实现只读的仓储和业务逻辑方法,用于新管理员控制台端点所需的资源/版本列表和计数功能。
  • 将新的管理员处理器接入应用的处理器集合和 HTTP 路由,使这些端点可供使用。
  • 更新与语义化版本控制、JSON 处理和缓存库相关的第三方依赖到较新的补丁/小版本。
Original summary in English

Summary by Sourcery

Add read-only admin resource management APIs and supporting data models, wiring, and repository/logic layers, along with minor dependency updates.

New Features:

  • Expose admin REST endpoints for listing resources, fetching resource details, and listing resource versions with pagination and filtering.
  • Introduce generic paginated response envelopes and admin-specific resource and version DTOs for API responses.
  • Add request models to support admin list queries with page, size, and filter parameters.

Enhancements:

  • Implement read-only repository and logic methods for resource/version listing and counts used by the new admin console endpoints.
  • Wire the new admin handler into the application’s handler set and HTTP router so the endpoints are available.
  • Update third-party dependencies for semantic versioning, JSON handling, and caching libraries to newer patch/minor versions.

- AdminHandler: GET /admin/resources, /:rid, /:rid/versions
- ResourceLogic: ListResources, GetByID, CountVersions, ListByResource
- Resource/Version repo: ListResources, CountResources, GetResourceByID,
  ListVersionsByResource, CountVersionsByResource
- Wire: inject AdminHandler into HandlerSet
- Model: ListResourcesRequest, ListVersionsRequest, ResourceItem,
  VersionItem, ResourceDetailData, PageData response types

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • 避免在 admin.go 中使用点导入(针对 logic/miscmodel),改为显式导入,以保持符号来源清晰并防止命名冲突。
  • 如果其他 handler 使用(或将会使用)类似的分页和映射逻辑,可以考虑把 normalizePagetoResourceItem 抽取到一个共享的辅助函数中,以避免重复并保持行为一致。
给 AI Agents 的提示
请根据这次代码评审中的评论进行修改:

## 总体评论
- 避免在 `admin.go` 中使用点导入(针对 `logic/misc``model`),改为显式导入,以保持符号来源清晰并防止命名冲突。
- 如果其他 handler 使用(或将会使用)类似的分页和映射逻辑,可以考虑把 `normalizePage``toResourceItem` 抽取到一个共享的辅助函数中,以避免重复并保持行为一致。

## 单独评论

### 评论 1
<location path="internal/interfaces/rest/handler/admin.go" line_range="52-61" />
<code_context>
+	g.Get("/:rid/versions", h.ListVersions)
+}
+
+func normalizePage(page, size int) (int, int) {
+	if page <= 0 {
+		page = defaultPage
+	}
+	if size <= 0 {
+		size = defaultPageSize
+	}
+	if size > maxPageSize {
+		size = maxPageSize
+	}
+	return page, size
+}
+
</code_context>
<issue_to_address>
**建议(性能):** 考虑对 page 进行封顶,避免因极大的偏移量导致非常重的查询。

当前 `normalizePage` 只对 `pageSize` 做了边界限制,所以客户端仍然可以发送数百万级的 `page` 值,在大表上会产生非常大的偏移量(`(page-1)*size`),并且当 `page` 接近 `math.MaxInt/size` 时可能导致整数溢出。建议对 `page`(或最大偏移量)增加上限,以防御异常请求。

建议实现:

```golang
	maxPageSize     = 100
	maxPage         = 1_000_000
)

```

```golang
func (h *AdminHandler) Register(r fiber.Router) {
	g := r.Group("/admin/resources")
	g.Get("/", h.ListResources)
	g.Get("/:rid", h.GetResource)
	g.Get("/:rid/versions", h.ListVersions)
}

func normalizePage(page, size int) (int, int) {
	if page <= 0 {
		page = defaultPage
	}
	if page > maxPage {
		page = maxPage
	}
	if size <= 0 {
		size = defaultPageSize
	}
	if size > maxPageSize {
		size = maxPageSize
	}
	return page, size
}

```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑分享 ✨
帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Avoid using dot-imports in admin.go (for logic/misc and model) and instead import explicitly to keep symbol origins clear and prevent name collisions.
  • Consider extracting normalizePage and toResourceItem into a shared helper if other handlers use (or will use) similar pagination and mapping logic, to avoid duplication and keep behavior consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Avoid using dot-imports in `admin.go` (for `logic/misc` and `model`) and instead import explicitly to keep symbol origins clear and prevent name collisions.
- Consider extracting `normalizePage` and `toResourceItem` into a shared helper if other handlers use (or will use) similar pagination and mapping logic, to avoid duplication and keep behavior consistent.

## Individual Comments

### Comment 1
<location path="internal/interfaces/rest/handler/admin.go" line_range="52-61" />
<code_context>
+	g.Get("/:rid/versions", h.ListVersions)
+}
+
+func normalizePage(page, size int) (int, int) {
+	if page <= 0 {
+		page = defaultPage
+	}
+	if size <= 0 {
+		size = defaultPageSize
+	}
+	if size > maxPageSize {
+		size = maxPageSize
+	}
+	return page, size
+}
+
</code_context>
<issue_to_address>
**suggestion (performance):** Consider capping page to avoid extremely large offsets causing heavy queries.

`normalizePage` currently only bounds `pageSize`, so a client can still send `page` values in the millions, resulting in huge offsets (`(page-1)*size`) on large tables and potential integer overflow when `page` approaches `math.MaxInt/size`. Consider adding an upper limit on `page` (or a maximum offset) to guard against pathological requests.

Suggested implementation:

```golang
	maxPageSize     = 100
	maxPage         = 1_000_000
)

```

```golang
func (h *AdminHandler) Register(r fiber.Router) {
	g := r.Group("/admin/resources")
	g.Get("/", h.ListResources)
	g.Get("/:rid", h.GetResource)
	g.Get("/:rid/versions", h.ListVersions)
}

func normalizePage(page, size int) (int, int) {
	if page <= 0 {
		page = defaultPage
	}
	if page > maxPage {
		page = maxPage
	}
	if size <= 0 {
		size = defaultPageSize
	}
	if size > maxPageSize {
		size = maxPageSize
	}
	return page, size
}

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +52 to +61
func normalizePage(page, size int) (int, int) {
if page <= 0 {
page = defaultPage
}
if size <= 0 {
size = defaultPageSize
}
if size > maxPageSize {
size = maxPageSize
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议(性能): 考虑对 page 进行封顶,避免因极大的偏移量导致非常重的查询。

当前 normalizePage 只对 pageSize 做了边界限制,所以客户端仍然可以发送数百万级的 page 值,在大表上会产生非常大的偏移量((page-1)*size),并且当 page 接近 math.MaxInt/size 时可能导致整数溢出。建议对 page(或最大偏移量)增加上限,以防御异常请求。

建议实现:

	maxPageSize     = 100
	maxPage         = 1_000_000
)
func (h *AdminHandler) Register(r fiber.Router) {
	g := r.Group("/admin/resources")
	g.Get("/", h.ListResources)
	g.Get("/:rid", h.GetResource)
	g.Get("/:rid/versions", h.ListVersions)
}

func normalizePage(page, size int) (int, int) {
	if page <= 0 {
		page = defaultPage
	}
	if page > maxPage {
		page = maxPage
	}
	if size <= 0 {
		size = defaultPageSize
	}
	if size > maxPageSize {
		size = maxPageSize
	}
	return page, size
}
Original comment in English

suggestion (performance): Consider capping page to avoid extremely large offsets causing heavy queries.

normalizePage currently only bounds pageSize, so a client can still send page values in the millions, resulting in huge offsets ((page-1)*size) on large tables and potential integer overflow when page approaches math.MaxInt/size. Consider adding an upper limit on page (or a maximum offset) to guard against pathological requests.

Suggested implementation:

	maxPageSize     = 100
	maxPage         = 1_000_000
)
func (h *AdminHandler) Register(r fiber.Router) {
	g := r.Group("/admin/resources")
	g.Get("/", h.ListResources)
	g.Get("/:rid", h.GetResource)
	g.Get("/:rid/versions", h.ListVersions)
}

func normalizePage(page, size int) (int, int) {
	if page <= 0 {
		page = defaultPage
	}
	if page > maxPage {
		page = maxPage
	}
	if size <= 0 {
		size = defaultPageSize
	}
	if size > maxPageSize {
		size = maxPageSize
	}
	return page, size
}

@Aliothmoon Aliothmoon merged commit eacfb98 into main Jun 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant