rpc.go 633 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package api
  2. import (
  3. "log"
  4. "net"
  5. "net/rpc"
  6. "net/rpc/jsonrpc"
  7. "github.com/710leo/urlooker/modules/web/g"
  8. )
  9. type Web int
  10. func Start() {
  11. addr := g.Config.Rpc.Listen
  12. server := rpc.NewServer()
  13. server.Register(new(Web))
  14. l, e := net.Listen("tcp", addr)
  15. if e != nil {
  16. log.Fatalln("listen occur error", e)
  17. } else {
  18. log.Println("listening on", addr)
  19. }
  20. for {
  21. conn, err := l.Accept()
  22. if err != nil {
  23. log.Println("listener accept occur error", err)
  24. continue
  25. }
  26. go server.ServeCodec(jsonrpc.NewServerCodec(conn))
  27. }
  28. }
  29. func (this *Web) Ping(req interface{}, reply *string) error {
  30. *reply = "ok"
  31. return nil
  32. }