mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
32 lines
733 B
Go
32 lines
733 B
Go
package api
|
|
|
|
import "net/rpc"
|
|
|
|
const HelloServiceName = "path/to/pkg.HelloService"
|
|
|
|
type HelloServiceInterface = interface {
|
|
Hello(request string, reply *string) error
|
|
}
|
|
|
|
func RegisterHelloService(svc HelloServiceInterface) error {
|
|
return rpc.RegisterName(HelloServiceName, svc)
|
|
}
|
|
|
|
type HelloServiceClient struct {
|
|
*rpc.Client
|
|
}
|
|
|
|
var _ HelloServiceInterface = (*HelloServiceClient)(nil)
|
|
|
|
func DialHelloService(network, address string) (*HelloServiceClient, error) {
|
|
c, err := rpc.Dial(network, address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &HelloServiceClient{Client: c}, nil
|
|
}
|
|
|
|
func (p *HelloServiceClient) Hello(request string, reply *string) error {
|
|
return p.Client.Call(HelloServiceName+".Hello", request, reply)
|
|
}
|