本文整理汇总了Golang中google/golang.org/appengine.IsDevAppServer函数的典型用法代码示例。如果您正苦于以下问题:Golang IsDevAppServer函数的具体用法?Golang IsDevAppServer怎么用?Golang IsDevAppServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDevAppServer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: warmupHandler
func warmupHandler(c *echo.Context) error {
if appengine.IsDevAppServer() {
photographers := []Photographer{
{1, "Mr Canon"},
{2, "Miss Nikon"},
{3, "Mrs Pentax"},
{4, "Ms Sony"},
}
// create some dummy data
for m := 1; m <= 12; m++ {
for d := 1; d < 28; d++ {
taken := time.Date(2015, time.Month(m), d, 12, 0, 0, 0, time.UTC)
id := rand.Int31n(4)
photographer := photographers[id]
p := Photo{
Photographer: photographer,
Uploaded: time.Now().UTC(),
Width: 8000,
Height: 6000,
Taken: taken,
}
k := datastore.NewIncompleteKey(c, "photo", nil)
nds.Put(c, k, &p)
}
}
}
return c.NoContent(http.StatusOK)
}
示例2: recaptchaCheck
func recaptchaCheck(ctx context.Context, response, ip string) (bool, error) {
if appengine.IsDevAppServer() {
return true, nil
}
form := url.Values{}
form.Add("secret", os.Getenv("SECRET"))
form.Add("response", response)
form.Add("remoteip", ip)
req, err := http.NewRequest("POST", recaptchaURL, strings.NewReader(form.Encode()))
if err != nil {
return false, err
}
cli := urlfetch.Client(ctx)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := cli.Do(req)
if err != nil {
return false, err
}
var recaptcha recaptchaResponse
if err := json.NewDecoder(resp.Body).Decode(&recaptcha); err != nil {
return false, err
}
if !recaptcha.Success {
log.Warningf(ctx, "%+v", recaptcha)
return false, nil
}
return true, nil
}
示例3: createOutputFile
func (s *shard) createOutputFile(c context.Context) (io.WriteCloser, error) {
c, _ = context.WithTimeout(c, time.Duration(10)*time.Minute)
// for development we can't use the appengine default credentials so
// instead need to create our own oauth token source to access storage
// TODO: maybe give job a chance to generate this - it could also
// create the writer (?). The only reason we're doing it is to prevent
// duplication and also handle the file rollup operations
var client *cstorage.Client
if appengine.IsDevAppServer() {
jsonKey, err := ioutil.ReadFile("service-account.json")
if err != nil {
return nil, err
}
conf, err := google.JWTConfigFromJSON(jsonKey, cstorage.ScopeReadWrite)
if err != nil {
return nil, err
}
client, err = cstorage.NewClient(c, option.WithTokenSource(conf.TokenSource(c)))
if err != nil {
return nil, err
}
} else {
var err error
client, err = cstorage.NewClient(c)
if err != nil {
return nil, err
}
}
o := client.Bucket(s.job.Bucket).Object(s.sliceFilename(s.Sequence)).NewWriter(c)
// TODO: wrap writer to count bytes and continue slice if we get close to 10Mb limit (?)
return o, nil
}
示例4: putCookie
func putCookie(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
p, ok := passenger.FromContext(ctx)
if !ok {
return http.StatusUnauthorized, nil
}
token := &model.Token{
Description: "Login from " + r.RemoteAddr,
}
value, err := p.IssueToken(ctx, token)
if err != nil {
return http.StatusInternalServerError, err
}
http.SetCookie(w, &http.Cookie{
Name: "token",
Value: value,
Secure: !appengine.IsDevAppServer(),
HttpOnly: true,
Expires: token.Expiry,
})
w.Write([]byte("OK"))
return http.StatusOK, nil
}
示例5: appstatsHandler
func appstatsHandler(w http.ResponseWriter, r *http.Request) {
ctx := storeContext(appengine.NewContext(r))
if appengine.IsDevAppServer() {
// noop
} else if u := user.Current(ctx); u == nil {
if loginURL, err := user.LoginURL(ctx, r.URL.String()); err == nil {
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
} else {
serveError(w, err)
}
return
} else if !u.Admin {
http.Error(w, "Forbidden", http.StatusForbidden)
return
}
if detailsURL == r.URL.Path {
details(ctx, w, r)
} else if fileURL == r.URL.Path {
file(ctx, w, r)
} else if strings.HasPrefix(r.URL.Path, staticURL) {
name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:]
content, ok := static[name]
if !ok {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
http.ServeContent(w, r, name, initTime, content)
} else {
index(ctx, w, r)
}
}
示例6: getTableProceed
func getTableProceed() string {
if newappengine.IsDevAppServer() {
return BIGQUERY_TABLE_PROCEED_DEV
} else {
return BIGQUERY_TABLE_PROCEED_PROD
}
}
示例7: cors
// Rudimentary CORS checking. See
// https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS
func cors(h http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
origin := r.Header.Get("Origin")
if !appengine.IsDevAppServer() {
if origin == "" {
h(w, r)
return
}
if !strings.HasPrefix(origin, "https://app.cod.uno") {
http.Error(w, "Invalid CORS request", http.StatusUnauthorized)
return
}
}
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Origin", origin)
if r.Method == "OPTIONS" {
w.Write([]byte("OK"))
return
}
h(w, r)
})
}
示例8: initEnv
func initEnv() {
if appengine.IsDevAppServer() {
env = envDev
} else {
env = envProd
}
}
示例9: generateRandom
// this will generate some random data for the given day
// 24 * 12 on appengine (288)
// 24 only on development
func generateRandom(c context.Context, day time.Time) error {
var x int
if appengine.IsDevAppServer() {
x = 1
} else {
x = 12
}
keys := make([]*datastore.Key, 24*x)
photos := make([]*Photo, 24*x)
id := 0
for h := 0; h < 24; h++ {
taken := day.Add(time.Duration(h) * time.Hour)
for i := 0; i < x; i++ {
photographer := photographers[rand.Int31n(4)]
photos[id] = &Photo{
Photographer: photographer,
Uploaded: time.Now().UTC(),
Width: 8000,
Height: 6000,
Taken: taken,
TakenDay: day,
}
keys[id] = datastore.NewIncompleteKey(c, "photo", nil)
id++
}
}
nds.PutMulti(c, keys, photos)
return nil
}
示例10: cors
// Rudimentary CORS checking. See
// https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS
func cors(w http.ResponseWriter, r *http.Request) bool {
origin := r.Header.Get("Origin")
// If the client has not provided it's origin, the
// request will be answered in any case.
if origin == "" {
return true
}
// Only allow our own origin if not on development server.
if !appengine.IsDevAppServer() && origin != "https://app.cod.uno" {
http.Error(w, "Invalid Origin", http.StatusUnauthorized)
return false
}
// We have a nice CORS established, so set appropriate headers.
// TODO(flowlo): Figure out how to send correct methods.
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Origin", origin)
// If this is an OPTIONS request, we answer it
// immediately and do not bother higher level handlers.
if r.Method == "OPTIONS" {
w.Write([]byte("OK"))
return false
}
return true
}
示例11: init
func init() {
if appengine.IsDevAppServer() {
AuthenticatorFactory = tokeninfoAuthenticatorFactory
} else {
AuthenticatorFactory = cachingAuthenticatorFactory
}
}
示例12: allowShare
func allowShare(r *http.Request) bool {
if appengine.IsDevAppServer() {
return true
}
switch r.Header.Get("X-AppEngine-Country") {
case "", "ZZ", "CN":
return false
}
return true
}
示例13: gaeUrl
func gaeUrl() string {
if appengine.IsDevAppServer() {
return "http://localhost:8080"
} else {
// Include your URL on App Engine here.
// I found no way to get AppID without appengine.Context and this always
// based on a http.Request.
return "http://federatedservices.appspot.com"
}
}
示例14: init
func init() {
if appengine.IsDevAppServer() {
upgrader.CheckOrigin = func(r *http.Request) bool {
log.Printf("Allowing origin %s", r.Header["Origin"])
return true
}
upgrader.Error = func(w http.ResponseWriter, r *http.Request, status int, reason error) {
log.Printf("WebSocket HTTP %d because of %s", status, reason)
http.Error(w, reason.Error(), status)
}
}
}
示例15: init
func init() {
var err error
if appengine.IsDevAppServer() {
dc, err = docker.NewClientFromEnv()
} else {
// FIXME(flowlo)
dc, err = docker.NewClient("tcp://10.240.10.141:2375")
}
if err != nil {
panic(err)
}
}