Skip to content

Instantly share code, notes, and snippets.

@fred-stripe
Created May 19, 2017 19:30
Show Gist options
  • Save fred-stripe/eb23700ede936c397c15538b35df78c2 to your computer and use it in GitHub Desktop.
Save fred-stripe/eb23700ede936c397c15538b35df78c2 to your computer and use it in GitHub Desktop.
Simple webhook example in Go
package main
import(
"fmt"
"log"
"encoding/json"
"net/http"
"os"
"github.com/stripe/stripe-go/client"
"github.com/stripe/stripe-go"
)
func main() {
client := &client.API{}
client.Init(os.Getenv("turing_secret_key"), nil)
http.HandleFunc("/webhook", func (w http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
var event = stripe.Event{}
err := decoder.Decode(&event)
if err != nil {
fmt.Fprintf(w, "%t", err)
return
}
defer req.Body.Close()
log.Println(event.ID)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment