@ -0,0 +1,11 @@ | |||||
.PHONY: all test get_deps | |||||
all: test | |||||
test: | |||||
go test github.com/tendermint/go-rpc/... | |||||
cd ./test && bash test.sh | |||||
get_deps: | |||||
go get -t -d github.com/tendermint/go-rpc/... |
@ -0,0 +1,23 @@ | |||||
machine: | |||||
environment: | |||||
GOPATH: /home/ubuntu/.go_workspace | |||||
REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME | |||||
hosts: | |||||
circlehost: 127.0.0.1 | |||||
localhost: 127.0.0.1 | |||||
checkout: | |||||
post: | |||||
- rm -rf $REPO | |||||
- mkdir -p $HOME/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME | |||||
- mv $HOME/$CIRCLE_PROJECT_REPONAME $REPO | |||||
# - git submodule sync | |||||
# - git submodule update --init # use submodules | |||||
dependencies: | |||||
override: | |||||
- "cd $REPO && make get_deps" | |||||
test: | |||||
override: | |||||
- "cd $REPO && make test" |
@ -0,0 +1,6 @@ | |||||
{ | |||||
"jsonrpc":"2.0", | |||||
"id":"", | |||||
"method":"hello_world", | |||||
"params":["my_world", 5] | |||||
} |
@ -0,0 +1,35 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"net/http" | |||||
. "github.com/tendermint/go-common" | |||||
rpcserver "github.com/tendermint/go-rpc/server" | |||||
) | |||||
var routes = map[string]*rpcserver.RPCFunc{ | |||||
"hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"), | |||||
} | |||||
func HelloWorld(name string, num int) (Result, error) { | |||||
return Result{fmt.Sprintf("hi %s %d", name, num)}, nil | |||||
} | |||||
type Result struct { | |||||
Result string | |||||
} | |||||
func main() { | |||||
mux := http.NewServeMux() | |||||
rpcserver.RegisterRPCFuncs(mux, routes) | |||||
_, err := rpcserver.StartHTTPServer("0.0.0.0:8008", mux) | |||||
if err != nil { | |||||
Exit(err.Error()) | |||||
} | |||||
// Wait forever | |||||
TrapSignal(func() { | |||||
}) | |||||
} |
@ -0,0 +1,23 @@ | |||||
#! /bin/bash | |||||
set -e | |||||
go build -o server main.go | |||||
./server > /dev/null & | |||||
PID=$! | |||||
sleep 2 | |||||
R1=`curl -s 'http://localhost:8008/hello_world?name="my_world"&num=5'` | |||||
R2=`curl -s --data @data.json http://localhost:8008` | |||||
kill -9 $PID | |||||
if [[ "$R1" != "$R2" ]]; then | |||||
echo "responses are not identical:" | |||||
echo "R1: $R1" | |||||
echo "R2: $R2" | |||||
exit 1 | |||||
fi | |||||
echo "Success" |