automation 重构期间的配套修改: - browser:订单抓取/密码登录/二维码刷新/stealth 等适配新流程,删 search.go - db:cookies/orders_ext/extras/sessions/users/password/repository 等调整 - xianyu:mtop client、protocol(sign/decrypt/msgpack/cookies)、qrlogin、ws、ua - server:admin/analytics/auth/cookie/helpers/item/item_publish_batch handlers - frontend:App/Dashboard/ItemList/Rules/Sidebar/api/types,删 Keywords/TestPage - auth、notify、webui、go.mod 等 本次会话补充: - cmd/server、cmd/init-admin 改为 // Package main 开头的标准包文档 - .gitignore 加 internal/webui/static/assets/(hash 化构建产物不入库) - internal/webui/static/index.html 重新构建 全量 go build/vet/test + race + 前端 test/build 通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
30 lines
686 B
Go
30 lines
686 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// writeJSON 写 JSON 响应。
|
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(v)
|
|
}
|
|
|
|
// errDetail 构造 {"detail": msg} 错误体。
|
|
func errDetail(msg string) map[string]any {
|
|
return map[string]any{"detail": msg}
|
|
}
|
|
|
|
// writeErr 写错误响应。
|
|
func writeErr(w http.ResponseWriter, status int, msg string) {
|
|
writeJSON(w, status, errDetail(msg))
|
|
}
|
|
|
|
// decodeJSON 解析请求体 JSON。
|
|
func decodeJSON(r *http.Request, v any) error {
|
|
dec := json.NewDecoder(r.Body)
|
|
return dec.Decode(v)
|
|
}
|