當前位置: 首頁>>代碼示例>>Golang>>正文


Golang appengine.BlobKey函數代碼示例

本文整理匯總了Golang中google/golang.org/appengine.BlobKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang BlobKey函數的具體用法?Golang BlobKey怎麽用?Golang BlobKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BlobKey函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的google/golang.org/appengine.BlobKey函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。