コード例 #1
0
// GetProviders returns an array of the first 10 Providers.
// FIXME support different result counts
func GetProviders(db *godis.Client) []Resource {
	var providers []Resource

	// fetch the Providers
	r, err := db.Lrange("idx:Provider", 0, 10)
	if err != nil {
		log.Fatal("Could not get providers.")
	}

	// conver the Reply into a []string of "Id|Label" representations
	s := r.StringArray()

	// loop through all results, creating resources
	for i := 0; i < len(s); i++ {
		// split the "Id|Label"
		vals := strings.SplitN(s[i], "|", 2)
		if len(vals) != 2 {
			log.Fatalf("For some reason, the index was improperly formatted: %s", s[i])
		}

		// build the Provider
		var p Provider
		p.Identifier = vals[0]
		p.Name = vals[1]

		// create a resource from the provider and add it to the array to return
		providers = append(providers, NewResource(&p))
	}

	// return the array of providers
	return providers
}
コード例 #2
0
// NewProvider creates a new Provider.
func NewProvider(db *godis.Client, name string) *Provider {
	var p Provider

	// get the next available provider ID
	i64, err := db.Incr("nxProvId")
	if err != nil {
		log.Fatal("Could not INCR nxProvId!")
	}

	// build the Provider
	p.Identifier = strconv.FormatInt(i64, 10)
	p.Name = name
	p.db = db

	// return a pointer to the Provider
	return &p
}
コード例 #3
0
ファイル: warfield.go プロジェクト: asenchi/warfield
// Match our domain to app_id and token in Redis
func (lr *LogRecord) GetToken(r *godis.Client) interface{} {

	domainkey := strings.Join([]string{cloud, "domain", lr.domain}, ":")

	appid, err := r.Hget(domainkey, "app_id")
	if err != nil {
		return err
	}

	// Save our app_id to our LogRecord
	lr.appid = appid.String()

	appkey := strings.Join([]string{cloud, "app", appid.String()}, ":")

	token, err := r.Hget(appkey, "heroku_log_token")
	if err != nil {
		return err
	}

	// Save our token to our LogRecord
	lr.token = token.String()
	return nil
}