Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A wrapper for *rpc.Client that removes the wrapped *rpc.Client from the cache if it produces errors.
func LookupOne ¶
LookupOne will use mDNS to lookup exactly one service named _name._tcp and return a *Client for it.
If a lookup has already been made earlier, the cached results will be returned and then a new lookup made in the background.
Example ¶
package main import ( "fmt" ) type Calculator struct{} type Numbers []int func (self *Calculator) Add(numbers Numbers, result *int) (err error) { for _, num := range numbers { *result += num } return } func main() { calc := &Calculator{} if _, err := Publish("Calculator", calc); err != nil { panic(err) } cli, err := LookupOne("Calculator") if err != nil { panic(err) } res := 0 if err := cli.Call("Add", Numbers{1, 2, 3}, &res); err != nil { panic(err) } fmt.Println("Sum is", res) }
Output: Sum is 6
func (*Client) Call ¶
Call works just like http://golang.org/pkg/net/rpc/#Client.Call except that it prepends "rpc." to the serviceMethod, and also removes the client from the cache if an error is returned.
func (*Client) Go ¶
func (self *Client) Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) (result *rpc.Call)
Go works just like http://golang.org/pkg/net/rpc/#Client.Go except that it prepends "rpc." to the serviceMethod, and also removes the client from the cache if an error is returned.
type Clients ¶
type Clients []*Client
func LookupAll ¶
LookupAll will use mDNS to lookup all services named _name._tcp and return a slice of *Client for them.
If a lookup has already been made earlier, the cached results will be returned and then a new lookup made in the background.
Example ¶
package main import "fmt" type Generator int func (self Generator) Generate(unused struct{}, result *int) (err error) { *result = int(self) return } func main() { gen1 := Generator(1) if _, err := Publish("Generator", gen1); err != nil { panic(err) } gen2 := Generator(2) if _, err := Publish("Generator", gen2); err != nil { panic(err) } gen3 := Generator(3) if _, err := Publish("Generator", gen3); err != nil { panic(err) } generators, err := LookupAll("Generator") if err != nil { panic(err) } res := 0 for _, client := range generators { n := 0 if err := client.Call("Generate", struct{}{}, &n); err != nil { panic(err) } res += n } fmt.Println("Sum is", res) }
Output: Sum is 6
type NoSuchService ¶
type NoSuchService string
NoSuchService is returned when LookupAll fails to find a single service.
func (NoSuchService) Error ¶
func (self NoSuchService) Error() string
type NotOneService ¶
NotOneService is returned when LookupOne fails to find exactly one service.
func (NotOneService) Error ¶
func (self NotOneService) Error() string