Go 实现 /api/v1/analysis 契约、Demo/Live Worker、DeerFlow SSE;含设计文档与冒烟脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
888 B
Go
32 lines
888 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// ApiResponse 与 Java 一致:{ code, message, data };成功 code=0。
|
|
type ApiResponse struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data"`
|
|
}
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, body interface{}) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(body)
|
|
}
|
|
|
|
func OK(w http.ResponseWriter, data interface{}) {
|
|
writeJSON(w, http.StatusOK, ApiResponse{Code: 0, Message: "ok", Data: data})
|
|
}
|
|
|
|
func Created(w http.ResponseWriter, data interface{}) {
|
|
writeJSON(w, http.StatusCreated, ApiResponse{Code: 0, Message: "ok", Data: data})
|
|
}
|
|
|
|
func Fail(w http.ResponseWriter, httpStatus, code int, msg string) {
|
|
writeJSON(w, httpStatus, ApiResponse{Code: code, Message: msg, Data: nil})
|
|
}
|