github.com/noirx94/tendermintmp@v0.0.1/rpc/jsonrpc/test/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "net/http" 6 "os" 7 8 "github.com/tendermint/tendermint/libs/log" 9 tmos "github.com/tendermint/tendermint/libs/os" 10 rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server" 11 rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" 12 ) 13 14 var routes = map[string]*rpcserver.RPCFunc{ 15 "hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"), 16 } 17 18 func HelloWorld(ctx *rpctypes.Context, name string, num int) (Result, error) { 19 return Result{fmt.Sprintf("hi %s %d", name, num)}, nil 20 } 21 22 type Result struct { 23 Result string 24 } 25 26 func main() { 27 var ( 28 mux = http.NewServeMux() 29 logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) 30 ) 31 32 // Stop upon receiving SIGTERM or CTRL-C. 33 tmos.TrapSignal(logger, func() {}) 34 35 rpcserver.RegisterRPCFuncs(mux, routes, logger) 36 config := rpcserver.DefaultConfig() 37 listener, err := rpcserver.Listen("tcp://127.0.0.1:8008", config) 38 if err != nil { 39 tmos.Exit(err.Error()) 40 } 41 42 if err = rpcserver.Serve(listener, mux, logger, config); err != nil { 43 tmos.Exit(err.Error()) 44 } 45 }