github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/google.golang.org/appengine/appengine.go (about)

     1  // Copyright 2011 Google Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package appengine provides basic functionality for Google App Engine.
     6  //
     7  // For more information on how to write Go apps for Google App Engine, see:
     8  // https://cloud.google.com/appengine/docs/go/
     9  package appengine
    10  
    11  import (
    12  	"net/http"
    13  
    14  	"github.com/golang/protobuf/proto"
    15  	"golang.org/x/net/context"
    16  
    17  	"google.golang.org/appengine/internal"
    18  )
    19  
    20  // IsDevAppServer reports whether the App Engine app is running in the
    21  // development App Server.
    22  func IsDevAppServer() bool {
    23  	return internal.IsDevAppServer()
    24  }
    25  
    26  // NewContext returns a context for an in-flight HTTP request.
    27  // This function is cheap.
    28  func NewContext(req *http.Request) context.Context {
    29  	return WithContext(context.Background(), req)
    30  }
    31  
    32  // WithContext returns a copy of the parent context
    33  // and associates it with an in-flight HTTP request.
    34  // This function is cheap.
    35  func WithContext(parent context.Context, req *http.Request) context.Context {
    36  	return internal.WithContext(parent, req)
    37  }
    38  
    39  // TODO(dsymonds): Add a Call function here? Otherwise other packages can't access internal.Call.
    40  
    41  // BlobKey is a key for a blobstore blob.
    42  //
    43  // Conceptually, this type belongs in the blobstore package, but it lives in
    44  // the appengine package to avoid a circular dependency: blobstore depends on
    45  // datastore, and datastore needs to refer to the BlobKey type.
    46  type BlobKey string
    47  
    48  // GeoPoint represents a location as latitude/longitude in degrees.
    49  type GeoPoint struct {
    50  	Lat, Lng float64
    51  }
    52  
    53  // Valid returns whether a GeoPoint is within [-90, 90] latitude and [-180, 180] longitude.
    54  func (g GeoPoint) Valid() bool {
    55  	return -90 <= g.Lat && g.Lat <= 90 && -180 <= g.Lng && g.Lng <= 180
    56  }
    57  
    58  // APICallFunc defines a function type for handling an API call.
    59  // See WithCallOverride.
    60  type APICallFunc func(ctx context.Context, service, method string, in, out proto.Message) error
    61  
    62  // WithCallOverride returns a copy of the parent context
    63  // that will cause API calls to invoke f instead of their normal operation.
    64  //
    65  // This is intended for advanced users only.
    66  func WithAPICallFunc(ctx context.Context, f APICallFunc) context.Context {
    67  	return internal.WithCallOverride(ctx, internal.CallOverrideFunc(f))
    68  }
    69  
    70  // APICall performs an API call.
    71  //
    72  // This is not intended for general use; it is exported for use in conjunction
    73  // with WithAPICallFunc.
    74  func APICall(ctx context.Context, service, method string, in, out proto.Message) error {
    75  	return internal.Call(ctx, service, method, in, out)
    76  }