fabric-samples/asset-transfer-basic/rest-api-go/web/query.go
Basil K Y b2de360e1c
REST api added for asset transfer in Golang (#836)
* REST api added for asset transfer in Golang

Signed-off-by: Basil K Y <techiebasil@gmail.com>

* add go.sum to git

Signed-off-by: Basil K Y <techiebasil@gmail.com>

* fix golint error

Signed-off-by: Basil K Y <techiebasil@gmail.com>

Signed-off-by: Basil K Y <techiebasil@gmail.com>
2022-12-14 09:16:09 +01:00

25 lines
786 B
Go

package web
import (
"fmt"
"net/http"
)
// Query handles chaincode query requests.
func (setup OrgSetup) Query(w http.ResponseWriter, r *http.Request) {
fmt.Println("Received Query request")
queryParams := r.URL.Query()
chainCodeName := queryParams.Get("chaincodeid")
channelID := queryParams.Get("channelid")
function := queryParams.Get("function")
args := r.URL.Query()["args"]
fmt.Printf("channel: %s, chaincode: %s, function: %s, args: %s\n", channelID, chainCodeName, function, args)
network := setup.Gateway.GetNetwork(channelID)
contract := network.GetContract(chainCodeName)
evaluateResponse, err := contract.EvaluateTransaction(function, args...)
if err != nil {
fmt.Fprintf(w, "Error: %s", err)
return
}
fmt.Fprintf(w, "Response: %s", evaluateResponse)
}