初始化第一版
This commit is contained in:
commit
8a6c31c14d
83 files changed
+14302
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// Package handler implements inbound HTTP contracts.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type healthResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// RouterOptions contains optional handlers wired by the application layer.
|
||||
type RouterOptions struct {
|
||||
Chat http.Handler
|
||||
DashScopeChat http.Handler
|
||||
MCP http.Handler
|
||||
}
|
||||
|
||||
// NewRouter returns the HTTP handler for the application.
|
||||
func NewRouter(options ...RouterOptions) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /health", health)
|
||||
if len(options) > 0 {
|
||||
if options[0].Chat != nil {
|
||||
mux.Handle("/api/chat", options[0].Chat)
|
||||
}
|
||||
if options[0].DashScopeChat != nil {
|
||||
mux.Handle("/api/v1/apps/{app_id}/completion", options[0].DashScopeChat)
|
||||
}
|
||||
if options[0].MCP != nil {
|
||||
mux.Handle("/mcp", options[0].MCP)
|
||||
}
|
||||
}
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
func health(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(w).Encode(healthResponse{Status: "ok"})
|
||||
}
|
||||
Reference in new issue
Block a user