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.

40 lines
870 B

8 years ago
7 years ago
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. rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
  8. cmn "github.com/tendermint/tendermint/libs/common"
  9. "github.com/tendermint/tendermint/libs/log"
  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. mux := http.NewServeMux()
  22. cdc := amino.NewCodec()
  23. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  24. rpcserver.RegisterRPCFuncs(mux, routes, cdc, logger)
  25. _, err := rpcserver.StartHTTPServer("0.0.0.0:8008", mux, logger, rpcserver.Config{})
  26. if err != nil {
  27. cmn.Exit(err.Error())
  28. }
  29. // Wait forever
  30. cmn.TrapSignal(func() {
  31. })
  32. }