Ejemplo n.º 1
0
func recursiveJson(key *datastore.Key) Response {
	var parentJson Response
	if key.Parent() != nil {
		parentJson = recursiveJson(key.Parent())
	}
	return Response{
		"stringID":  key.StringID(),
		"intID":     key.IntID(),
		"kind":      key.Kind(),
		"appID":     key.AppID(),
		"namespace": key.Namespace(),
		"parent":    parentJson,
	}
}
Ejemplo n.º 2
0
func translate(sourceKey *datastore.Key, translateAppId bool, targetAppId string, translateNamespace bool, targetNamespace string) (*datastore.Key, error) {
	if !translateAppId {
		targetAppId = sourceKey.AppID()
	}
	if !translateNamespace {
		targetNamespace = sourceKey.Namespace()
	}
	var translatedParent *datastore.Key = nil
	if sourceKey.Parent() != nil {
		var err error
		translatedParent, err = translate(sourceKey.Parent(), translateAppId, targetAppId, translateNamespace, targetNamespace)
		if err != nil {
			return nil, err
		}
	}
	return datastorekey.CreateKey(nil, targetAppId, targetNamespace, sourceKey.Kind(), sourceKey.StringID(), sourceKey.IntID(), translatedParent)
}
Ejemplo n.º 3
0
func fillFields(key *datastore.Key, data map[string]interface{}) {
	data["kind"] = key.Kind()
	data["stringid"] = key.StringID()
	data["intid"] = key.IntID()
	data["appid"] = key.AppID()
	data["namespace"] = key.Namespace()
	if key.Parent() != nil {
		data["kind2"] = key.Parent().Kind()
		data["stringid2"] = key.Parent().StringID()
		data["intid2"] = key.Parent().IntID()
		if key.Parent().Parent() != nil {
			data["kind3"] = key.Parent().Parent().Kind()
			data["stringid3"] = key.Parent().Parent().StringID()
			data["intid3"] = key.Parent().Parent().IntID()
		}
	}
}
Ejemplo n.º 4
0
func extract(key *datastore.Key, field string) (string, error) {
	switch strings.ToLower(field) {
	case "kind":
		return key.Kind(), nil
	case "appid":
		return key.AppID(), nil
	case "namespace":
		return key.Namespace(), nil
	case "name":
		return key.StringID(), nil
	case "id":
		return fmt.Sprintf("%v", key.IntID()), nil
	case "parent":
		if key.Parent() == nil {
			return "", nil
		} else {
			return key.Parent().Encode(), nil
		}
	default:
		return "", fmt.Errorf("Unsupported field [%v]. Supported fields are kind, appID, namespace, name, id, parentkey.", field)
	}
}