diff options
| author | Teddy Wing | 2015-06-07 12:03:34 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-06-07 12:03:34 -0400 |
| commit | 1b4c3530aee05547fd6341ac206223dfaf1c2a7b (patch) | |
| tree | 27875ae7066f067a4e852c0807a2a429e85ea6b1 | |
| parent | 01186c52c83bccffad17dde5a24712b86dc3e68e (diff) | |
| download | New-House-on-the-Block-1b4c3530aee05547fd6341ac206223dfaf1c2a7b.tar.bz2 | |
main.go: Create an HTTP handler to initiate transactions
Visiting this endpoint will create 2 transactions that sends the money.
Handle errors in the HTTP handler and pass them back from the
transaction functions now.
| -rw-r--r-- | main.go | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -9,27 +9,29 @@ import ( "github.com/teddywing/new-house-on-the-block/purchase" ) -func sendMoneyToSeller() { +func sendMoneyToSeller() error { transaction_id, err := purchase.SendMoney(os.Getenv("COINBASE_KEY"), os.Getenv("COINBASE_SECRET"), "n2Qd6da1jiFgij5SSncFKh7MoFN74GdUxv", "0.0001") if err != nil { - log.Println(err) + return err } else { fmt.Println(transaction_id) + return nil } } -func sendTokenToBuyer() { +func sendTokenToBuyer() error { transaction_id, err := purchase.SendMoney(os.Getenv("SELLER_COINBASE_KEY"), os.Getenv("SELLER_COINBASE_SECRET"), "mqy3kT6aFHymTcvmdwZLKq1Svo2m6sUtzH", "0.0001") if err != nil { - log.Println(err) + return err } else { fmt.Println(transaction_id) + return nil } } @@ -37,6 +39,22 @@ func main() { fs := http.FileServer(http.Dir("static")) http.Handle("/", fs) + http.HandleFunc("/buy/", func(w http.ResponseWriter, r *http.Request) { + var err error + + err = sendMoneyToSeller() + if err != nil { + log.Println(err) + } + + err = sendTokenToBuyer() + if err != nil { + log.Println(err) + } + + http.Redirect(w, r, "", 302) + }) + log.Println("Listening on port 3000") http.ListenAndServe(":3000", nil) } |
