Skip to content

Commit

Permalink
Webhook server
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Aug 30, 2024
1 parent ff2f5a9 commit 14c9696
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/webhooks/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/tonkeeper/tonapi-go/examples/webhooks

go 1.22.0
31 changes: 31 additions & 0 deletions examples/webhooks/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
)

type AccountTxPayload struct {
AccountID string `json:"account_id"`
Lt int64 `json:"lt"`
TxHash string `json:"tx_hash"`
}

func webhook(w http.ResponseWriter, req *http.Request) {
defer req.Body.Close()

var payload AccountTxPayload
if err := json.NewDecoder(req.Body).Decode(&payload); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}

fmt.Printf("%v\n", payload)
w.WriteHeader(http.StatusOK)
}

func main() {
http.HandleFunc("/", webhook)
http.ListenAndServe(":8092", nil)
}

0 comments on commit 14c9696

Please sign in to comment.