func dial(addr string) *doozer.Conn { c, err := doozer.Dial(addr) if err != nil { panic(err) } return c }
// IsCal checks if addr is a CAL in the cluster named name. // Returns a client if so, nil if not. func isCal(name, addr string) (*doozer.Conn, error) { c, err := doozer.Dial(addr) if err != nil { return nil, err } err = c.Access(rwsk) if err != nil { return nil, err } v, _, _ := c.Get("/ctl/name", nil) if string(v) != name { return nil, nil } rev, err := c.Rev() if err != nil { return nil, err } var cals []string names, err := c.Getdir("/ctl/cal", rev, 0, -1) if err != nil { return nil, err } for _, name := range names { cals = append(cals, name) } for _, cal := range cals { body, _, err := c.Get("/ctl/cal/"+cal, nil) if err != nil || len(body) == 0 { continue } id := string(body) v, _, err := c.Get("/ctl/node/"+id+"/addr", nil) if err != nil { return nil, err } if string(v) == addr { return c, nil } } return nil, nil }
// only call from mux() func (d *DoozerConnection) dialMux(server string, boot string) error { var err error d.connection, err = doozer.Dial(server) if err != nil { return err } d.currentInstance = server //d.Log.Println("Connected to Doozer Instance: " + server) connected := DoozerConnected{Addr: server} // Log connection d.Log.Trace(fmt.Sprintf("%T: %+v", connected, connected)) return nil }
func main() { flag.Parse() serverList := strings.Split(*servers, ",") res := make([]string, 0, 0) sem := make(chan empty, len(serverList)) for ind, server := range serverList { go func(ind int, name string) { address := name + ":" + *port _, err := net.DialTimeout(*protocol, address, time.Duration(*timeout)*time.Millisecond) if err != nil { } else { res = appendIfMissing(res, address) } sem <- empty{} }(ind, server) } for i := 0; i < len(serverList); i++ { <-sem } doozer, derr := doozer.Dial(res[0]) if derr != nil { panic(derr) // HANDLE THIS PROPERLY } // Get latest Revision of DB _, rerr := doozer.Rev() // HANDLE THE ERROR if rerr != nil { panic("Shit, it's an Errrrrrorrrr!") // Do some proper error handling here I suppose... } host, _, _ := net.SplitHostPort(res[0]) resolved, _ := net.LookupIP(host) output := net.JoinHostPort(resolved[0].String(), *port) fmt.Print(output) }
func Dial(addr string) (*Conn, error) { conn, err := doozer.Dial(addr) return &Conn{Conn: conn, Id: "1"}, err }