Example #1
0
// Initialize is exported
func (s *Discovery) Initialize(uris string, heartbeat uint64) error {
	var (
		parts = strings.SplitN(uris, "/", 2)
		ips   = strings.Split(parts[0], ",")
		addrs []string
		err   error
	)

	if len(parts) != 2 {
		return fmt.Errorf("invalid format %q, missing <path>", uris)
	}

	for _, ip := range ips {
		addrs = append(addrs, ip)
	}

	s.heartbeat = time.Duration(heartbeat) * time.Second
	s.prefix = parts[1]

	// Creates a new store, will ignore options given
	// if not supported by the chosen store
	s.store, err = store.CreateStore(
		s.name, // name of the store
		addrs,
		store.Config{
			Timeout: s.heartbeat,
		},
	)
	if err != nil {
		return err
	}

	return nil
}
Example #2
0
// newClient used to connect to KV Store
func newClient(kv string, addrs string) (DataStore, error) {
	store, err := store.CreateStore(kv, []string{addrs}, store.Config{})
	if err != nil {
		return nil, err
	}
	ds := &datastore{store: store}
	return ds, nil
}