当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.AppID方法代码示例

本文整理汇总了Golang中appengine.Context.AppID方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.AppID方法的具体用法?Golang Context.AppID怎么用?Golang Context.AppID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appengine.Context的用法示例。


在下文中一共展示了Context.AppID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Get

// Get loads the entity stored for k into dst, which may be either a struct
// pointer or a Map. If there is no such entity for the key, Get returns
// ErrNoSuchEntity.
//
// The values of dst's unmatched struct fields or Map entries are not modified.
// In particular, it is recommended to pass either a pointer to a zero valued
// struct or an empty Map on each Get call.
//
// ErrFieldMismatch is returned when a field is to be loaded into a different
// type than the one it was stored from, or when a field is missing or
// unexported in the destination struct. ErrFieldMismatch is only returned if
// dst is a struct pointer.
func Get(c appengine.Context, k *Key, dst interface{}) os.Error {
	if !k.valid() {
		return ErrInvalidKey
	}
	req := &pb.GetRequest{
		Key: []*pb.Reference{
			keyToProto(c.AppID(), k),
		},
	}
	res := &pb.GetResponse{}
	err := c.Call("datastore_v3", "Get", req, res)
	if err != nil {
		return err
	}
	if len(res.Entity) == 0 || res.Entity[0].Entity == nil {
		return ErrNoSuchEntity
	}
	if m, ok := dst.(Map); ok {
		return loadMap(m, k, res.Entity[0].Entity)
	}
	sv, err := asStructValue(dst)
	if err != nil {
		return err
	}
	return loadStruct(sv, k, res.Entity[0].Entity)
}
开发者ID:nicneo925,项目名称:appscale,代码行数:38,代码来源:datastore.go

示例2: Delete

// Delete deletes the entity for the given key.
func Delete(c appengine.Context, k *Key) os.Error {
	if !k.valid() {
		return ErrInvalidKey
	}
	req := &pb.DeleteRequest{
		Key: []*pb.Reference{
			keyToProto(c.AppID(), k),
		},
	}
	res := &pb.DeleteResponse{}
	return c.Call("datastore_v3", "Delete", req, res)
}
开发者ID:nicneo925,项目名称:appscale,代码行数:13,代码来源:datastore.go

示例3: Put

// Put saves the entity src into the datastore with key k. src may be either a
// struct pointer or a Map; if the former then any unexported fields of that
// struct will be skipped.
// If k is an incomplete key, the returned key will be a unique key
// generated by the datastore.
func Put(c appengine.Context, k *Key, src interface{}) (*Key, os.Error) {
	if !k.valid() {
		return nil, ErrInvalidKey
	}
	var e *pb.EntityProto
	if m, ok := src.(Map); ok {
		var err os.Error
		e, err = saveMap(c.AppID(), k, m)
		if err != nil {
			return nil, err
		}
	} else {
		sv, err := asStructValue(src)
		if err != nil {
			return nil, err
		}
		e, err = saveStruct(c.AppID(), k, sv)
		if err != nil {
			return nil, err
		}
	}
	req := &pb.PutRequest{
		Entity: []*pb.EntityProto{e},
	}
	res := &pb.PutResponse{}
	err := c.Call("datastore_v3", "Put", req, res)
	if err != nil {
		return nil, err
	}
	if len(res.Key) == 0 {
		return nil, os.NewError("datastore: internal error: server did not return a key")
	}
	key, err := protoToKey(res.Key[0])
	if err != nil || key.Incomplete() {
		return nil, os.NewError("datastore: internal error: server returned an invalid key")
	}
	return key, nil
}
开发者ID:nicneo925,项目名称:appscale,代码行数:43,代码来源:datastore.go

示例4: fullAppID

// fullAppID returns the full AppID for c.
func fullAppID(c appengine.Context) string {
	if c, ok := c.(fullAppIDer); ok {
		return c.FullAppID()
	}
	return c.AppID()
}
开发者ID:sarnowski,项目名称:google-go-lang-idea-plugin,代码行数:7,代码来源:datastore.go


注:本文中的appengine.Context.AppID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。