forked from chainHero/heroes-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
37 lines (35 loc) · 834 Bytes
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package controllers
import (
"net/http"
)
func (app *Application) RequestHandler(w http.ResponseWriter, r *http.Request) {
key := "hello"
value, err := app.Fabric.Query(key)
if err != nil {
http.Error(w, "Unable to query the blockchain", 500)
}
data := &struct {
Key string
Value string
TransactionId string
Success bool
Response bool
}{
Key: key,
Value: value,
TransactionId: "",
Success: false,
Response: false,
}
if r.FormValue("submitted") == "true" {
value := r.FormValue(key)
txid, err := app.Fabric.InvokeString(key, value)
if err != nil {
http.Error(w, "Unable to invoke in the blockchain", 500)
}
data.TransactionId = txid
data.Success = true
data.Response = true
}
app.renderTemplate(w, r, "request.html", data)
}