package main import ( "encoding/json" "fmt" "go-bot/config" "go-bot/utils" "io" "net/http" ) func handlePost(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "Error reading request body", http.StatusBadRequest) return } // fmt.Println(string(body)) // 解码 JSON 数据到 map[string]interface{} 类型的变量 var data map[string]interface{} err = json.Unmarshal(body, &data) if err != nil { fmt.Println("Error decoding JSON:", err) return } utils.Router(data) w.Write([]byte("JSON data received successfully!")) } func main() { config.LoadConfig() config.APIURL = "http://127.0.0.1:5700/" config.PORT = ":5580" http.HandleFunc("/", handlePost) fmt.Println("Server listening on port 5580...") http.ListenAndServe(config.PORT, nil) }