appengine 包

import "google.golang.org/appengine"

简介

appengine 包可为 Google App Engine 提供基本函数。

如需详细了解如何为 Google App Engine 写入 Go 应用,请参阅:https://cloud.google.com/appengine/docs/standard/go/

索引

func AccessToken(c context.Context, scopes ...string) (token string, expiry time.Time, err error)
func AppID(c context.Context) string
func Datacenter(c context.Context) string
func DefaultVersionHostname(c context.Context) string
func InstanceID() string
func IsDevAppServer() bool
func IsOverQuota(err error) bool
func IsTimeoutError(err error) bool
func ModuleHostname(c context.Context, module, version, instance string) (string, error)
func ModuleName(c context.Context) string
func Namespace(c context.Context, namespace string) (context.Context, error)
func NewContext(req *http.Request) context.Context
func PublicCertificates(c context.Context) ([]Certificate, error)
func RequestID(c context.Context) string
func ServerSoftware() string
func ServiceAccount(c context.Context) (string, error)
func SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error)
func VersionID(c context.Context) string
func WithContext(parent context.Context, req *http.Request) context.Context
type BlobKey
type Certificate
type GeoPoint
    func (g GeoPoint) Valid() bool
type MultiError
    func (m MultiError) Error() string

func AccessToken

func AccessToken(c context.Context, scopes ...string) (token string, expiry time.Time, err error)

AccessToken 可以代表相应应用的服务账号为指定的范围生成 OAuth2 访问令牌。此令牌将在返回的时间后过期。

func AppID

func AppID(c context.Context) string

AppID 返回当前应用的应用 ID。该字符串是普通的应用 ID(例如“appid”),带有自定义域名部署的域名前缀(例如“example.com:appid”)。

func Datacenter

func Datacenter(c context.Context) string

数据中心可以返回运行实例的数据中心的标识符。

func DefaultVersionHostname

func DefaultVersionHostname(c context.Context) string

DefaultVersionHostname 返回当前应用默认版本的标准主机名(例如“my-app.appspot.com”)。该函数适合用于构建网址。

func InstanceID

func InstanceID() string

InstanceID 可以为相应实例返回唯一性最高的标识符。

func IsDevAppServer

func IsDevAppServer() bool

IsDevAppServer 报告 App Engine 应用在开发应用服务器中运行。

func IsOverQuota

func IsOverQuota(err error) bool

IsOverQuota 报告错误是否表示因可用配额不足而导致 API 调用失败。

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError 报告错误是否为超时错误。

func ModuleHostname

func ModuleHostname(c context.Context, module, version, instance string) (string, error)

ModuleHostname 返回模块实例的主机名。如果模块是空字符串,则引用当前实例的模块。如果版本为空,则引用当前实例的版本(如有效)或当前实例模块的默认版本。如果实例为空,ModuleHostname 将返回负载平衡主机名。

func ModuleName

func ModuleName(c context.Context) string

ModuleName 返回当前实例的模块名称。

func Namespace

func Namespace(c context.Context, namespace string) (context.Context, error)

Namespace 返回在给定命名空间内运行的替换上下文。

func NewContext

func NewContext(req *http.Request) context.Context

NewContext 返回动态 HTTP 请求的上下文。该函数的费用很低。

func PublicCertificates

func PublicCertificates(c context.Context) ([]Certificate, error)

PublicCertificates 检索应用的公共证书。该证书可用于验证 SignBytes 返回的签名。

func RequestID

func RequestID(c context.Context) string

RequestID 返回识别相应请求的唯一字符串。

func ServerSoftware

func ServerSoftware() string

ServerSoftware 返回 App Engine 发行版本。在生产环境中,其形式类似“Google App Engine/X.Y.Z”。在开发应用服务器中,其形式类似“Development/X.Y”。

func ServiceAccount

func ServiceAccount(c context.Context) (string, error)

ServiceAccount 通过电子邮件地址的形式返回表示服务账号名称的字符串(通常为 app_id@appspot.gserviceaccount.com)。

func SignBytes

func SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error)

SignBytes 使用您的应用特有的私钥为字节签名。

func VersionID

func VersionID(c context.Context) string

VersionID 返回当前应用的版本 ID。其形式为“X.Y”,其中 X 在 app.yaml 中指定,Y 是应用的各版本上传后生成的数字。它不包含模块名称。

func WithContext

func WithContext(parent context.Context, req *http.Request) context.Context

WithContext 返回父上下文的副本,并将其与动态 HTTP 请求关联。该函数的费用很低。

type BlobKey

type BlobKey string

BlobKey 是 Blobstore 的 Blob 键。

从概念上来说,该类型属于 Bobstore 包,但将它归入 appengine 包是为了避免循环依赖:Blobstore 依赖数据存储区,数据存储区也需要引用 BlobKey 类型。

type Certificate

type Certificate struct {
    KeyName string
    Data    []byte // PEM-encoded X.509 certificate
}

Certificate 表示应用的公共证书。

type GeoPoint

type GeoPoint struct {
    Lat, Lng float64
}

GeoPoint 使用纬度/经度表示位置。

func (GeoPoint) Valid

func (g GeoPoint) Valid() bool

Valid 可以返回 GeoPoint 是否在 [-90, 90] 的纬度和 [-180, 180] 的经度范围之内的结果。

type MultiError

type MultiError []error

特定元素存在错误时,批处理操作返回 MultiError。错误将与输入元素保持一对一的对应关系;成功的元素将拥有 nil 条目。

func (MultiError) Error

func (m MultiError) Error() string