• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang appengine.BlobKey函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中google/golang.org/appengine.BlobKey函数的典型用法代码示例。如果您正苦于以下问题:Golang BlobKey函数的具体用法?Golang BlobKey怎么用?Golang BlobKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: init

func init() {
	gob.Register(time.Time{})
	gob.Register(datastore.ByteString{})
	gob.Register(&datastore.Key{})
	gob.Register(appengine.BlobKey(""))
	gob.Register(appengine.GeoPoint{})
}
开发者ID:jongillham,项目名称:nds,代码行数:7,代码来源:nds.go


示例2: Save

func (tf *typeFilter) Save() ([]datastore.Property, error) {
	props := []datastore.Property{}
	for name, propList := range tf.pm {
		if len(name) != 0 && name[0] == '$' {
			continue
		}
		multiple := len(propList) > 1
		for _, prop := range propList {
			toAdd := datastore.Property{
				Name:     name,
				Multiple: multiple,
				NoIndex:  prop.IndexSetting() == ds.NoIndex,
			}
			switch prop.Type() {
			case ds.PTBytes:
				v := prop.Value().([]byte)
				if prop.IndexSetting() == ds.ShouldIndex {
					toAdd.Value = datastore.ByteString(v)
				} else {
					toAdd.Value = v
				}
			case ds.PTKey:
				toAdd.Value = dsF2R(prop.Value().(ds.Key))
			case ds.PTBlobKey:
				toAdd.Value = appengine.BlobKey(prop.Value().(bs.Key))
			case ds.PTGeoPoint:
				toAdd.Value = appengine.GeoPoint(prop.Value().(ds.GeoPoint))
			default:
				toAdd.Value = prop.Value()
			}
			props = append(props, toAdd)
		}
	}
	return props, nil
}
开发者ID:martiniss,项目名称:gae,代码行数:35,代码来源:raw_datastore_type_converter.go


示例3: propValue

// propValue returns a Go value that combines the raw PropertyValue with a
// meaning. For example, an Int64Value with GD_WHEN becomes a time.Time.
func propValue(v *pb.PropertyValue, m pb.Property_Meaning) (interface{}, error) {
	switch {
	case v.Int64Value != nil:
		if m == pb.Property_GD_WHEN {
			return fromUnixMicro(*v.Int64Value), nil
		} else {
			return *v.Int64Value, nil
		}
	case v.BooleanValue != nil:
		return *v.BooleanValue, nil
	case v.StringValue != nil:
		if m == pb.Property_BLOB {
			return []byte(*v.StringValue), nil
		} else if m == pb.Property_BLOBKEY {
			return appengine.BlobKey(*v.StringValue), nil
		} else if m == pb.Property_BYTESTRING {
			return ByteString(*v.StringValue), nil
		} else {
			return *v.StringValue, nil
		}
	case v.DoubleValue != nil:
		return *v.DoubleValue, nil
	case v.Referencevalue != nil:
		key, err := referenceValueToKey(v.Referencevalue)
		if err != nil {
			return nil, err
		}
		return key, nil
	case v.Pointvalue != nil:
		// NOTE: Strangely, latitude maps to X, longitude to Y.
		return appengine.GeoPoint{Lat: v.Pointvalue.GetX(), Lng: v.Pointvalue.GetY()}, nil
	}
	return nil, nil
}
开发者ID:sromku,项目名称:datastore-to-sql,代码行数:36,代码来源:load.go


示例4: propValue

// propValue returns a Go value that combines the raw PropertyValue with a
// meaning. For example, an Int64Value with GD_WHEN becomes a time.Time.
func propValue(v *pb.PropertyValue, m pb.Property_Meaning) (interface{}, error) {
	switch {
	case v.Int64Value != nil:
		if m == pb.Property_GD_WHEN {
			return fromUnixMicro(*v.Int64Value), nil
		} else {
			return *v.Int64Value, nil
		}
	case v.BooleanValue != nil:
		return *v.BooleanValue, nil
	case v.StringValue != nil:
		if m == pb.Property_BLOB {
			return []byte(*v.StringValue), nil
		} else if m == pb.Property_BLOBKEY {
			return appengine.BlobKey(*v.StringValue), nil
		} else {
			return *v.StringValue, nil
		}
	case v.DoubleValue != nil:
		return *v.DoubleValue, nil
	case v.Referencevalue != nil:
		key, err := referenceValueToKey(v.Referencevalue)
		if err != nil {
			return nil, err
		}
		return key, nil
	}
	return nil, nil
}
开发者ID:proppy,项目名称:appengine,代码行数:31,代码来源:load.go


示例5: BlobKeyForFile

// BlobKeyForFile returns a BlobKey for a Google Storage file.
// The filename should be of the form "/gs/bucket_name/object_name".
func BlobKeyForFile(c context.Context, filename string) (appengine.BlobKey, error) {
	req := &blobpb.CreateEncodedGoogleStorageKeyRequest{
		Filename: &filename,
	}
	res := &blobpb.CreateEncodedGoogleStorageKeyResponse{}
	if err := internal.Call(c, "blobstore", "CreateEncodedGoogleStorageKey", req, res); err != nil {
		return "", err
	}
	return appengine.BlobKey(*res.BlobKey), nil
}
开发者ID:curiositycasualty,项目名称:packer,代码行数:12,代码来源:blobstore.go


示例6: GetServingUrl

func GetServingUrl(c *gin.Context) {
	r := c.Request
	ctx := appengine.NewContext(r)
	blobKey := appengine.BlobKey(c.Param("blobKey"))
	var err_msg string
	url, err := image.ServingURL(ctx, blobKey, nil)
	if err != nil {
		err_msg = "failed"
	}
	c.JSON(http.StatusOK, gin.H{"err": err_msg, "url": url, "blobKey": url.String()})
}
开发者ID:sankark,项目名称:kyp,代码行数:11,代码来源:filestore.go


示例7: serveThumb

func serveThumb(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	// c := appengine.NewContext(r)
	k := appengine.BlobKey(r.FormValue("blobkey"))

	var o image.ServingURLOptions = *new(image.ServingURLOptions)
	o.Size = 200
	o.Crop = true
	url, err := image.ServingURL(c, k, &o)

	loghttp.E(w, r, err, false)

	http.Redirect(w, r, url.String(), http.StatusFound)
}
开发者ID:aarzilli,项目名称:tools,代码行数:16,代码来源:upload2.go


示例8: handleFilesItem

func handleFilesItem(w http.ResponseWriter, r *http.Request) {
	id := r.URL.Path
	if id == "" {
		w.WriteHeader(404)
		return
	}
	c := appengine.NewContext(r)
	key := datastore.NewKey(c, "File", id, 0, nil)
	switch r.Method {
	case "GET":
		var file File
		err := datastore.Get(c, key, &file)
		if err == datastore.ErrNoSuchEntity {
			http.NotFound(w, r)
			return
		}
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "query file: %s", err.Error())
			return
		}
		w.Header().Set("Content-Type", "application/json")
		err = json.NewEncoder(w).Encode(&file)
		if err != nil {
			log.Errorf(c, "json encode: %s", err.Error())
		}
	case "DELETE":
		err := datastore.Delete(c, key)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "delete file: %s", err.Error())
			return
		}
		err = blobstore.Delete(c, appengine.BlobKey(id))
		if err != nil {
			log.Warningf(c, "delete file '%s': %s", id, err.Error())
		}
		w.WriteHeader(204)
	default:
		http.Error(w, "Valid methods are GET and DELETE", http.StatusMethodNotAllowed)
		return
	}
}
开发者ID:mastercactapus,项目名称:ae-gallery,代码行数:43,代码来源:admin.go


示例9: handleBlobFile

func handleBlobFile(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	key := datastore.NewKey(c, "File", r.URL.Path, 0, nil)

	var file File
	err := datastore.Get(c, key, &file)

	if err != nil {
		http.NotFound(w, r)
		return
	}

	w.Header().Set("Content-Type", mime.TypeByExtension(path.Ext(file.Name)))

	_, err = io.Copy(w, blobstore.NewReader(c, appengine.BlobKey(r.URL.Path)))
	if err != nil {
		log.Errorf(c, "stream blob: %s", err.Error())
	}
}
开发者ID:mastercactapus,项目名称:ae-gallery,代码行数:19,代码来源:gallery.go


示例10: sampleHandler2

func sampleHandler2(w http.ResponseWriter, r *http.Request) {
	// [START uploading_a_blob_3]
	ctx := appengine.NewContext(r)
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		serveError(ctx, w, err)
		return
	}
	file := blobs["file"]
	if len(file) == 0 {
		log.Errorf(ctx, "no file uploaded")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	http.Redirect(w, r, "/serve/?blobKey="+string(file[0].BlobKey), http.StatusFound)
	// [END uploading_a_blob_3]

	// [START serving_a_blob]
	blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey")))
	// [END serving_a_blob]
}
开发者ID:wuman,项目名称:golang-samples,代码行数:21,代码来源:blobstore.go


示例11: TestReader

func TestReader(t *testing.T) {
	for _, rt := range readerTest {
		c := aetesting.FakeSingleContext(t, "blobstore", "FetchData", fakeFetchData)
		r := NewReader(c, appengine.BlobKey(rt.blobKey))
		for i, step := range rt.step {
			var (
				got    string
				gotErr error
				n      int
				offset int64
			)
			switch step.method {
			case "LargeReadAt":
				p := make([]byte, step.lenp)
				n, gotErr = r.ReadAt(p, step.offset)
				got = strconv.Itoa(n)
			case "Read":
				p := make([]byte, step.lenp)
				n, gotErr = r.Read(p)
				got = string(p[:n])
			case "ReadAt":
				p := make([]byte, step.lenp)
				n, gotErr = r.ReadAt(p, step.offset)
				got = string(p[:n])
			case "Seek":
				offset, gotErr = r.Seek(step.offset, step.whence)
				got = strconv.FormatInt(offset, 10)
			default:
				t.Fatalf("unknown method: %s", step.method)
			}
			if gotErr != step.wantErr {
				t.Fatalf("%s step %d: got error %v want %v", rt.blobKey, i, gotErr, step.wantErr)
			}
			if got != step.want {
				t.Fatalf("%s step %d: got %q want %q", rt.blobKey, i, got, step.want)
			}
		}
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:39,代码来源:blobstore_test.go


示例12: dsF2RProp

func dsF2RProp(ctx context.Context, in ds.Property) (datastore.Property, error) {
	err := error(nil)
	ret := datastore.Property{
		NoIndex: in.IndexSetting() == ds.NoIndex,
	}
	switch in.Type() {
	case ds.PTBytes:
		v := in.Value().([]byte)
		if in.IndexSetting() == ds.ShouldIndex {
			ret.Value = datastore.ByteString(v)
		} else {
			ret.Value = v
		}
	case ds.PTKey:
		ret.Value, err = dsF2R(ctx, in.Value().(*ds.Key))
	case ds.PTBlobKey:
		ret.Value = appengine.BlobKey(in.Value().(bs.Key))
	case ds.PTGeoPoint:
		ret.Value = appengine.GeoPoint(in.Value().(ds.GeoPoint))
	default:
		ret.Value = in.Value()
	}
	return ret, err
}
开发者ID:nishanths,项目名称:gae,代码行数:24,代码来源:raw_datastore_type_converter.go


示例13:

]`)

// icon is a sample white png file 16x16,
// dumped as a byte array.
var icon = []byte{
	137, 80, 78, 71, 13, 10, 26, 10,
	0, 0, 0, 13, 73, 72, 68, 82,
	0, 0, 0, 16, 0, 0, 0, 16,
	8, 2, 0, 0, 0, 144, 145, 104,
	54, 0, 0, 0, 9, 112, 72, 89,
	115, 0, 0, 11, 19, 0, 0, 11,
	19, 1, 0, 154, 156, 24, 0, 0,
	0, 7, 116, 73, 77, 69, 7, 222,
	5, 8, 21, 41, 53, 225, 172, 74,
	51, 0, 0, 0, 25, 116, 69, 88,
	116, 67, 111, 109, 109, 101, 110, 116,
	0, 67, 114, 101, 97, 116, 101, 100,
	32, 119, 105, 116, 104, 32, 71, 73,
	77, 80, 87, 129, 14, 23, 0, 0,
	0, 26, 73, 68, 65, 84, 40, 207,
	99, 252, 255, 255, 63, 3, 41, 128,
	137, 129, 68, 48, 170, 97, 84, 195,
	208, 209, 0, 0, 85, 109, 3, 29,
	159, 46, 21, 162, 0, 0, 0, 0,
	73, 69, 78, 68, 174, 66, 96, 130}

// blobKey is a sample appengine.BlobKey value.
var blobKey = appengine.BlobKey("AMIfv94Ly-gFmdjqsU9IwztyA6jjiChzE8cUSwkP8EE" +
	"fo4paIuXmHiwFkoccnayuqcTmkyXfDo8SS9uetO-6h7AhqlKQFYsY1tyGjrhjqmxOYT19CC" +
	"tH5tZEL2pxtCBLe6MFProzW1fw1du_vMwPsypKMHnnpZau6F_qJNoc6yoqnYIKGDvroNk")
开发者ID:ronoaldo,项目名称:aetools,代码行数:30,代码来源:vars_test.go


示例14: handleServe

func handleServe(w http.ResponseWriter, r *http.Request) {
	blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey")))
}
开发者ID:wuman,项目名称:golang-samples,代码行数:3,代码来源:complete.go


示例15: serveFull

func serveFull(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
	blobstore.Send(w, appengine.BlobKey(r.FormValue("blobkey")))
}
开发者ID:aarzilli,项目名称:tools,代码行数:3,代码来源:upload2.go


示例16: Serve

func Serve(c *gin.Context) {
	r := c.Request
	w := c.Writer
	blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey")))
}
开发者ID:sankark,项目名称:kyp,代码行数:5,代码来源:filestore.go


示例17: handleBucketsItem

func handleBucketsItem(w http.ResponseWriter, r *http.Request) {
	id := r.URL.Path
	if id == "" {
		w.WriteHeader(404)
		return
	}
	c := appengine.NewContext(r)
	key := datastore.NewKey(c, "Bucket", id, 0, nil)
	switch r.Method {
	case "GET":
		var b Bucket
		err := datastore.Get(c, key, &b)
		if err == datastore.ErrNoSuchEntity {
			w.WriteHeader(404)
			return
		}
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "query bucket: %s", err.Error())
			return
		}
		w.Header().Set("Content-Type", "application/json")
		err = json.NewEncoder(w).Encode(&b)
		if err != nil {
			log.Errorf(c, "json encode: %s", err.Error())
		}
	case "PUT":
		var b Bucket
		err := json.NewDecoder(r.Body).Decode(&b)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		if b.ID != id {
			http.Error(w, "Bucket ID must match URL ID", http.StatusBadRequest)
			return
		}
		_, err = datastore.Put(c, key, &b)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "put bucket: %s", err.Error())
			return
		}
		w.WriteHeader(204)
	case "DELETE":
		err := datastore.RunInTransaction(c, func(c context.Context) error {
			metaKey := datastore.NewKey(c, "Meta", "main", 0, nil)
			var m Meta
			err := datastore.Get(c, metaKey, &m)
			if err != nil {
				return err
			}
			b := m.Buckets[:0]
			for _, bucket := range m.Buckets {
				if bucket == id {
					continue
				}
				b = append(b, bucket)
			}
			m.Buckets = b
			_, err = datastore.Put(c, metaKey, &m)
			if err != nil {
				return err
			}
			return err

		}, &datastore.TransactionOptions{XG: true})
		if err != nil {
			log.Warningf(c, "update meta: %s", err.Error())
		}
		var bk Bucket
		err = datastore.Get(c, key, &bk)
		if err == nil && bk.Images != nil { // delete images
			for _, id := range bk.Images {
				err = blobstore.Delete(c, appengine.BlobKey(id))
				if err != nil {
					log.Warningf(c, "delete image blob '%s': %s", id, err.Error())
				}
				err = datastore.Delete(c, datastore.NewKey(c, "Image", id, 0, nil))
				if err != nil {
					log.Warningf(c, "delete image entry '%s': %s", id, err.Error())
				}
			}
		}
		err = datastore.Delete(c, key)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "delete bucket: %s", err.Error())
			return
		}
		w.WriteHeader(204)
	default:
		http.Error(w, "Valid methods are GET, DELETE and PUT", http.StatusMethodNotAllowed)
		return
	}
}
开发者ID:mastercactapus,项目名称:ae-gallery,代码行数:96,代码来源:admin.go


示例18: decodeProperty

func decodeProperty(c context.Context, k string, v interface{}, e *Entity) error {
	var p datastore.Property
	p.Name = k

	var err error

	switch v.(type) {
	// Try to decode property object
	case map[string]interface{}:
		// Decode custom type
		m := v.(map[string]interface{})

		t, ok := m["type"]
		if !ok {
			t = "primitive"
		}

		if index, ok := m["indexed"]; ok {
			if i, ok := index.(bool); ok {
				p.NoIndex = !i
			}
		}

		switch t {
		case "key":
			key, err := decodeKey(c, m["value"])
			if err != nil {
				return err
			}
			p.Value = key
		case "blobkey":
			v, ok := m["value"].(string)
			if !ok {
				return newDecodePropertyError(k, "blobkey", v)
			}
			p.Value = appengine.BlobKey(v)
		case "blob":
			v, ok := m["value"].(string)
			if !ok {
				return newDecodePropertyError(k, "date", v)
			}
			p.Value, err = base64.URLEncoding.DecodeString(v)
			if err != nil {
				return err
			}
		case "date":
			v, ok := m["value"].(string)
			if !ok {
				return newDecodePropertyError(k, "date", v)
			}
			var dt time.Time
			dt, err = time.Parse(DateTimeFormat, v)
			if err != nil {
				return newDecodePropertyError(k, "date", err)
			}
			p.Value = dt.UTC()
		default:
			if v, ok := m["value"]; ok {
				err = decodeJSONPrimitiveValue(v, &p)
			} else {
				err = fmt.Errorf("aetools: complex property %s without 'value' attribute", k)
			}
		}

	default:
		err = decodeJSONPrimitiveValue(v, &p)
	}

	if err == nil {
		e.Properties = append(e.Properties, p)
	}
	return err
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:73,代码来源:marshal.go


示例19: getImage

func getImage(res http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	// requesting an image based on blob key
	blobstore.Send(res, appengine.BlobKey(ps.ByName("blobKey")))
}
开发者ID:mediix,项目名称:CSci_191T_FALL2015,代码行数:4,代码来源:api.go


示例20: TestMarshalUnmarshalPropertyList

func TestMarshalUnmarshalPropertyList(t *testing.T) {
	c, closeFunc := NewContext(t)
	defer closeFunc()

	timeVal := time.Now()
	timeProp := datastore.Property{Name: "Time",
		Value: timeVal, NoIndex: false, Multiple: false}

	byteStringVal := datastore.ByteString{0x23}
	byteStringProp := datastore.Property{Name: "ByteString",
		Value: byteStringVal, NoIndex: false, Multiple: false}

	keyVal := datastore.NewKey(c, "Entity", "stringID", 0, nil)
	keyProp := datastore.Property{Name: "Key",
		Value: keyVal, NoIndex: false, Multiple: false}

	blobKeyVal := appengine.BlobKey("blobkey")
	blobKeyProp := datastore.Property{Name: "BlobKey",
		Value: blobKeyVal, NoIndex: false, Multiple: false}

	geoPointVal := appengine.GeoPoint{1, 2}
	geoPointProp := datastore.Property{Name: "GeoPoint",
		Value: geoPointVal, NoIndex: false, Multiple: false}

	pl := datastore.PropertyList{
		timeProp,
		byteStringProp,
		keyProp,
		blobKeyProp,
		geoPointProp,
	}
	data, err := nds.MarshalPropertyList(pl)
	if err != nil {
		t.Fatal(err)
	}

	testEntity := &struct {
		Time       time.Time
		ByteString datastore.ByteString
		Key        *datastore.Key
		BlobKey    appengine.BlobKey
		GeoPoint   appengine.GeoPoint
	}{}

	pl = datastore.PropertyList{}
	if err := nds.UnmarshalPropertyList(data, &pl); err != nil {
		t.Fatal(err)
	}
	if err := nds.SetValue(reflect.ValueOf(testEntity), pl); err != nil {
		t.Fatal(err)
	}

	if !testEntity.Time.Equal(timeVal) {
		t.Fatal("timeVal not equal")
	}

	if string(testEntity.ByteString) != string(byteStringVal) {
		t.Fatal("byteStringVal not equal")
	}

	if !testEntity.Key.Equal(keyVal) {
		t.Fatal("keyVal not equal")
	}

	if testEntity.BlobKey != blobKeyVal {
		t.Fatal("blobKeyVal not equal")
	}

	if !reflect.DeepEqual(testEntity.GeoPoint, geoPointVal) {
		t.Fatal("geoPointVal not equal")
	}
}
开发者ID:jongillham,项目名称:nds,代码行数:72,代码来源:nds_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang appengine.IsDevAppServer函数代码示例发布时间:2022-05-28
下一篇:
Golang appengine.AppID函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap