puper / servicecaller

Call your local service method by string or json.RawMessage, based on net/rpc and net/rpc/jsonrpc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

servicecaller

Call your local service method by string or json.RawMessage, based on net/rpc and net/rpc/jsonrpc

type HelloService struct{}

func (p *HelloService) Hello(request string, reply *string) error {
	*reply = "hello:" + request
	return nil
}

func main() {
	s, _ :=servicecaller.New()
	s.RegisterService("hello", new(HelloService))
	reply := json.RawMessage{}
	err := s.Call("hello.Hello", "world", &reply)
	if err != nil {
		log.Println("callby", err)
	}
	log.Println("callWithString: ", string(reply))
	{
		reply := ""
		s.GetService("hello").(*HelloService).Hello("world", &reply)
		log.Println("callDirectly: ", reply)
	}

}

About

Call your local service method by string or json.RawMessage, based on net/rpc and net/rpc/jsonrpc

License:Apache License 2.0


Languages

Language:Go 100.0%