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.

35 lines
631 B

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. cmn "github.com/tendermint/go-common"
  6. rpcserver "github.com/tendermint/go-rpc/server"
  7. )
  8. var routes = map[string]*rpcserver.RPCFunc{
  9. "hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"),
  10. }
  11. func HelloWorld(name string, num int) (Result, error) {
  12. return Result{fmt.Sprintf("hi %s %d", name, num)}, nil
  13. }
  14. type Result struct {
  15. Result string
  16. }
  17. func main() {
  18. mux := http.NewServeMux()
  19. rpcserver.RegisterRPCFuncs(mux, routes)
  20. _, err := rpcserver.StartHTTPServer("0.0.0.0:8008", mux)
  21. if err != nil {
  22. cmn.Exit(err.Error())
  23. }
  24. // Wait forever
  25. cmn.TrapSignal(func() {
  26. })
  27. }