From aaf0bd96e3201a10704199dc80d132eb05b456e7 Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 9 Mar 2020 21:50:50 +1100 Subject: [PATCH] compilation bug fix --- db.go | 8 +++++--- rpn.go | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/db.go b/db.go index af729a8..515a87c 100644 --- a/db.go +++ b/db.go @@ -58,9 +58,11 @@ func (m *TransactionDB) addRequest(r *http.Request) error { } func (m *TransactionDB) addRpnOut(r RpnReq) error { - + return nil } -func (m *TransactionDB) updateRpnOutNameAndCard(orderid string, signature string, name string, card string) error { - +func (m *TransactionDB) updateRpnOutNameAndCard(orderid string, signature string, name string, card string) (row RpnReq, err error) { + err = nil + row = RpnReq{} + return } diff --git a/rpn.go b/rpn.go index aca72a7..5fe97a2 100644 --- a/rpn.go +++ b/rpn.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "net/http" "net/url" @@ -98,6 +99,18 @@ func (m *RpnReq) encode() string { return s } +func retrieveFormValue(form url.Values, key string) (r string, err error) { + + if _, ok := form[key]; ok { + r = form[key][0] + err = nil + } else { + r = "" + err = errors.New("Key [" + key + "] not found in HTTP request") + } + return r, err +} + //receive RPN user name and card number func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { @@ -105,12 +118,12 @@ func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { return } r.ParseForm() - order_id, ok1 := r.Form["id"][0] - signature, ok2 := r.Form["si"][0] - user_name, ok3 := r.Form["name"][0] - user_card, ok4 := r.Form["card"][0] + order_id, ok1 := retrieveFormValue(r.Form, "id") + signature, ok2 := retrieveFormValue(r.Form, "si") + user_name, ok3 := retrieveFormValue(r.Form, "name") + user_card, ok4 := retrieveFormValue(r.Form, "card") - if !(ok1 && ok2 && ok3 && ok4) { + if !(ok1 == nil && ok2 == nil && ok3 == nil && ok4 == nil) { fmt.Fprintf(w, "missing parameters") return }