aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorTeddy Wing2015-06-07 12:03:34 -0400
committerTeddy Wing2015-06-07 12:03:34 -0400
commit1b4c3530aee05547fd6341ac206223dfaf1c2a7b (patch)
tree27875ae7066f067a4e852c0807a2a429e85ea6b1 /main.go
parent01186c52c83bccffad17dde5a24712b86dc3e68e (diff)
downloadNew-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.
Diffstat (limited to 'main.go')
-rw-r--r--main.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/main.go b/main.go
index 41f09cc..a75b8b4 100644
--- a/main.go
+++ b/main.go
@@ -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)
}