mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
953af7d8db
- Relocated generic HTTP response helpers (Response, OK, Err, etc.) from internal/util/ to a dedicated internal/common/response/ package. - Renamed ResponseAny to Any to resolve revive stuttering warnings. - Moved session building options and cookie headers logic from internal/util/ to internal/apps/oauth/. - Removed all direct imports of Gin/Sessions/HTTP frameworks from internal/util/ to keep general utilities 100% pure. - Regenerated Swagger API documentation via make swagger. - All tests and make code-check compile and pass with 0 issues.
35 lines
858 B
Go
35 lines
858 B
Go
// Copyright 2025 linux.do
|
|
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package response provides shared HTTP API response structures.
|
|
package response
|
|
|
|
// Response 通用响应体
|
|
type Response[T any] struct {
|
|
ErrorMsg string `json:"error_msg"`
|
|
Data T `json:"data"`
|
|
}
|
|
|
|
// Any 用于 Swagger 文档的响应类型(非泛型)
|
|
// swag 不支持泛型,使用此类型替代 Response[T]
|
|
type Any struct {
|
|
ErrorMsg string `json:"error_msg" example:""`
|
|
Data interface{} `json:"data"`
|
|
}
|
|
|
|
// OK 构造成功响应
|
|
func OK[T any](data T) Response[T] {
|
|
return Response[T]{Data: data}
|
|
}
|
|
|
|
// OKNil 构造成功响应(data 为 null)
|
|
func OKNil() Response[any] {
|
|
return Response[any]{Data: nil}
|
|
}
|
|
|
|
// Err 构造错误响应
|
|
func Err(msg string) Response[any] {
|
|
return Response[any]{ErrorMsg: msg, Data: nil}
|
|
}
|