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.

38 lines
762 B

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