httpface

package
v0.0.1-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httpface 管理面/用户面 HTTP 边界:响应书写(WriteJSON/WriteErr/ WriteServiceErr,service 错误→HTTP 状态映射表唯一一份)+ 请求参数边界 (ClampLimit——两面包共享的分页上限钳制)。

依赖仅 internal/service/errors 叶子包(零内部依赖),不反向依赖 handler/service/auth/server 任何上层包——依赖图无环。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampLimit

func ClampLimit(l int) int

ClampLimit 分页 limit 统一钳制(上限 200,与 /usage_logs 同语义):超限 裁剪到 200;≤0 原样透传(repo 归一下限 ≤0→20)。管理面误操作 limit=2147483647 不再全表物化(spec 2026-08-17 边界收敛,6 端点共享)。

func WriteErr

func WriteErr(w http.ResponseWriter, status int, msg string)

WriteErr 写 {"error": msg} JSON 信封。

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON 写 JSON 响应(Content-Type application/json + encoder 编码, 含尾换行——与各包历史副本逐字节一致)。

func WriteServiceErr

func WriteServiceErr(w http.ResponseWriter, err error)

WriteServiceErr 统一把 service 错误映射为 HTTP 状态(映射表唯一一份)。 404 输出 err.Error()(service 层已把缺失 id 详情包装进 ErrNotFound,与 批量 404 同语义);未命中哨兵 → 500 "internal error"(不泄露内部细节)。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL