You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
953 B

8 years ago
7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. amino "github.com/tendermint/go-amino"
  7. cmn "github.com/tendermint/tendermint/libs/common"
  8. "github.com/tendermint/tendermint/libs/log"
  9. rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
  10. )
  11. var routes = map[string]*rpcserver.RPCFunc{
  12. "hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"),
  13. }
  14. func HelloWorld(name string, num int) (Result, error) {
  15. return Result{fmt.Sprintf("hi %s %d", name, num)}, nil
  16. }
  17. type Result struct {
  18. Result string
  19. }
  20. func main() {
  21. var (
  22. mux = http.NewServeMux()
  23. cdc = amino.NewCodec()
  24. logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  25. )
  26. // Stop upon receiving SIGTERM or CTRL-C.
  27. cmn.TrapSignal(logger, func() {})
  28. rpcserver.RegisterRPCFuncs(mux, routes, cdc, logger)
  29. listener, err := rpcserver.Listen("0.0.0.0:8008", rpcserver.Config{})
  30. if err != nil {
  31. cmn.Exit(err.Error())
  32. }
  33. rpcserver.StartHTTPServer(listener, mux, logger)
  34. }