Exemplo n.º 1
0
func handleRequest(app types.Application, req types.Request, responses chan<- types.Response) {
	switch req := req.(type) {
	case types.RequestEcho:
		responses <- types.ResponseEcho{req.Message}
	case types.RequestFlush:
		responses <- types.ResponseFlush{}
	case types.RequestInfo:
		data := app.Info()
		responses <- types.ResponseInfo{data}
	case types.RequestSetOption:
		logStr := app.SetOption(req.Key, req.Value)
		responses <- types.ResponseSetOption{logStr}
	case types.RequestAppendTx:
		code, result, logStr := app.AppendTx(req.TxBytes)
		responses <- types.ResponseAppendTx{code, result, logStr}
	case types.RequestCheckTx:
		code, result, logStr := app.CheckTx(req.TxBytes)
		responses <- types.ResponseCheckTx{code, result, logStr}
	case types.RequestGetHash:
		hash, logStr := app.GetHash()
		responses <- types.ResponseGetHash{hash, logStr}
	case types.RequestQuery:
		result, logStr := app.Query(req.QueryBytes)
		responses <- types.ResponseQuery{result, logStr}
	default:
		responses <- types.ResponseException{"Unknown request"}
	}
}
Exemplo n.º 2
0
func handleRequest(app types.Application, req *types.Request, responses chan<- *types.Response) {
	switch req.Type {
	case types.MessageType_Echo:
		responses <- types.ResponseEcho(string(req.Data))
	case types.MessageType_Flush:
		responses <- types.ResponseFlush()
	case types.MessageType_Info:
		data := app.Info()
		responses <- types.ResponseInfo(data)
	case types.MessageType_SetOption:
		logStr := app.SetOption(req.Key, req.Value)
		responses <- types.ResponseSetOption(logStr)
	case types.MessageType_AppendTx:
		code, result, logStr := app.AppendTx(req.Data)
		responses <- types.ResponseAppendTx(code, result, logStr)
	case types.MessageType_CheckTx:
		code, result, logStr := app.CheckTx(req.Data)
		responses <- types.ResponseCheckTx(code, result, logStr)
	case types.MessageType_Commit:
		hash, logStr := app.Commit()
		responses <- types.ResponseCommit(hash, logStr)
	case types.MessageType_Query:
		code, result, logStr := app.Query(req.Data)
		responses <- types.ResponseQuery(code, result, logStr)
	default:
		responses <- types.ResponseException("Unknown request")
	}
}