package main import ( "encoding/json" "fmt" "io" "net/http" ) // webhook HandleFunc read the request body and then print out the contents func webhook(w http.ResponseWriter, req *http.Request) { // read the body content sentBody, err := io.ReadAll(req.Body) if err != nil { // if there was an error while reading the body return an error http.Error(w, "error", http.StatusInternalServerError) return } defer req.Body.Close() // Pretty print the received JSON fmt.Println("=== RECEIVED REQUEST ===") var prettyJSON map[string]interface{} if err := json.Unmarshal(sentBody, &prettyJSON); err != nil { fmt.Println("Raw body:", string(sentBody)) } else { prettyBytes, _ := json.MarshalIndent(prettyJSON, "", " ") fmt.Println(string(prettyBytes)) } fmt.Println("========================") // Set response headers w.Header().Set("Content-Type", "application/json") // test response with claims response := `{ "set_user_metadata":[], "append_claims":[ { "key":"user_type", "value":"machine" } ], "append_log_claims":[] }` fmt.Println("=== SENDING RESPONSE ===") var responseJSON map[string]interface{} json.Unmarshal([]byte(response), &responseJSON) prettyResponse, _ := json.MarshalIndent(responseJSON, "", " ") fmt.Println(string(prettyResponse)) fmt.Println("========================") w.Write([]byte(response)) } func main() { http.HandleFunc("/webhook", webhook) http.ListenAndServe(":8090", nil) }