- 在管理面板中集成网络代理配置显示和平台代理设置 - 添加钱包摘要和交易列表API接口及数据管理 - 实现SSE流式响应中的错误处理机制 - 添加全局HTTP代理环境变量配置支持 - 更新平台表单以支持代理模式选择和自定义代理地址 - 集成钱包交易查询过滤和分页功能 - 优化API错误详情解析和显示格式
34 lines
806 B
Go
34 lines
806 B
Go
package httpapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, value any) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(value)
|
|
}
|
|
|
|
func writeError(w http.ResponseWriter, status int, message string, codes ...string) {
|
|
errorPayload := map[string]any{
|
|
"message": message,
|
|
"status": status,
|
|
}
|
|
if len(codes) > 0 {
|
|
if code := strings.TrimSpace(codes[0]); code != "" {
|
|
errorPayload["code"] = code
|
|
}
|
|
}
|
|
writeJSON(w, status, map[string]any{"error": errorPayload})
|
|
}
|
|
|
|
func sendSSE(w http.ResponseWriter, event string, payload any) {
|
|
bytes, _ := json.Marshal(payload)
|
|
_, _ = fmt.Fprintf(w, "event: %s\n", event)
|
|
_, _ = fmt.Fprintf(w, "data: %s\n\n", bytes)
|
|
}
|