本文整理汇总了Golang中github.com/soundtrackyourbrand/utils/key.Key类的典型用法代码示例。如果您正苦于以下问题:Golang Key类的具体用法?Golang Key怎么用?Golang Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ToGAE
func ToGAE(c appengine.Context, k key.Key) *datastore.Key {
if len(k) < 1 {
return nil
}
kind, stringID, intID, parent := k.Split()
return datastore.NewKey(c, kind, stringID, intID, ToGAE(c, key.Key(parent)))
}
示例2: cacheKeys
// cacheKeys will append to oldKeys, and also return as newKeys, all cache keys this finder may use to find the provided model.
// the reason there may be multiple keys is that we don't know which ancestor will be used when finding the model.
func (self finder) cacheKeys(c PersistenceContext, model interface{}, oldKeys *[]string) (newKeys []string, err error) {
var id key.Key
if _, id, err = getTypeAndId(model); err != nil {
return
}
values := make([]interface{}, len(self.fields))
val := reflect.ValueOf(model).Elem()
for index, field := range self.fields {
values[index] = val.FieldByName(field.Name).Interface()
}
if oldKeys == nil {
oldKeys = &[]string{}
}
for id != "" {
*oldKeys = append(*oldKeys, self.keyForValues(id.Parent(), values))
id = id.Parent()
}
newKeys = *oldKeys
return
}
示例3: UpdateDoc
func UpdateDoc(c ElasticConnector, index string, id key.Key, groovyCode string, params map[string]interface{}) (err error) {
index = processIndexName(index)
url := fmt.Sprintf("%s/%s/%s/%s/_update?retry_on_conflict=%v",
c.GetElasticService(),
index,
id.Kind(),
id.Encode(),
UpdateConflictRetries)
json, err := json.Marshal(UpdateRequest{
Script: groovyCode,
Params: params,
})
if err != nil {
return
}
request, err := http.NewRequest("POST", url, bytes.NewBuffer(json))
if err != nil {
return
}
if c.GetElasticUsername() != "" {
request.SetBasicAuth(c.GetElasticUsername(), c.GetElasticPassword())
}
response, err := c.Client().Do(request)
if err != nil {
return
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(response.Body)
err = errors.Errorf("Bad status code from elasticsearch %v: %v, %v", url, response.Status, string(body))
return
}
return
}
示例4: GetSpotifyAccount
func GetSpotifyAccount(c ServiceConnector, soundZone key.Key, token AccessToken) (result *RemoteSpotifyAccount, err error) {
request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("sound_zones/%v/spotify_account", soundZone.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteSpotifyAccount{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例5: GetSoundZones
func GetSoundZones(c ServiceConnector, account_id key.Key, token AccessToken) (result RemoteSoundZones, err error) {
request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/sound_zones", account_id.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = RemoteSoundZones{}
err = json.NewDecoder(response.Body).Decode(&result)
return
}
示例6: CreateBusinessAccount
func CreateBusinessAccount(c ServiceConnector, token AccessToken, account RemoteAccount, owner key.Key) (result *RemoteAccount, err error) {
request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("users/%v/accounts/business", owner.Encode()), token, account)
if err != nil {
return
}
if response.StatusCode != 201 {
err = errorFor(request, response)
return
}
result = &RemoteAccount{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例7: UpdateSoundZoneErrors
func UpdateSoundZoneErrors(c ServiceConnector, token AccessToken, soundZoneId key.Key, soundZoneError RemoteSoundZoneError) (err error) {
request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("sound_zones/%v/sound_zone_errors", soundZoneId.Encode()), token, soundZoneError)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
return
}
示例8: GetProductQueue
func GetProductQueue(c ServiceConnector, productQueueId key.Key, token AccessToken) (result *RemoteProductQueue, err error) {
request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("product_queues/%v", productQueueId.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteProductQueue{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例9: SetPassword
func SetPassword(c ServiceConnector, user key.Key, password string, token AccessToken) (result *RemoteUser, err error) {
request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("users/%s/password", user.Encode()), token, map[string]string{
"password": password,
})
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteUser{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例10: GetBillingGroupsByAccountId
func GetBillingGroupsByAccountId(c ServiceConnector, account key.Key, token AccessToken) (result RemoteBillingGroups, err error) {
request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("accounts/%v/billing_groups", account.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = RemoteBillingGroups{}
err = json.NewDecoder(response.Body).Decode(&result)
return
}
示例11: CreateSoundZoneError
func CreateSoundZoneError(c ServiceConnector, token AccessToken, e RemoteSoundZoneError, soundZoneId key.Key) (result *RemoteSoundZoneError, err error) {
request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("sound_zones/%v/sound_zone_errors", soundZoneId.Encode()), token, e)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteSoundZoneError{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例12: GetAccountContact
func GetAccountContact(c ServiceConnector, account key.Key, token AccessToken) (result *RemoteUser, err error) {
request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/contact", account.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteUser{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例13: GetLocation
func GetLocation(c ServiceConnector, location key.Key, token AccessToken) (result *RemoteLocation, err error) {
request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("locations/%v", location.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
result = &RemoteLocation{}
err = json.NewDecoder(response.Body).Decode(result)
return
}
示例14: ReplaceScheduleForSoundZones
func ReplaceScheduleForSoundZones(c ServiceConnector, oldSchedule, newSchedule key.Key, token AccessToken) (err error) {
scheduleRef := &ScheduleRef{
Schedule: newSchedule,
}
request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("schedules/%v/sound_zones", oldSchedule.Encode()), token, scheduleRef)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
return
}
示例15: CountSoundZonesForSchedule
func CountSoundZonesForSchedule(c ServiceConnector, schedule key.Key, token AccessToken) (result int, err error) {
request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("schedules/%v/sound_zone_count", schedule.Encode()), token, nil)
if err != nil {
return
}
if response.StatusCode != 200 {
err = errorFor(request, response)
return
}
container := &CountContainer{}
if err = json.NewDecoder(response.Body).Decode(container); err != nil {
return
}
result = container.Count
return
}