当前位置: 首页>>代码示例>>Golang>>正文


Golang appengine.IsDevAppServer函数代码示例

本文整理汇总了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)
}
开发者ID:komasoftware,项目名称:go-appengine-mapper,代码行数:29,代码来源:warmup.go

示例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
}
开发者ID:rojters,项目名称:gopherpods,代码行数:34,代码来源:gopherpods.go

示例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
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:35,代码来源:shard.go

示例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
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:26,代码来源:cookie.go

示例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)
	}
}
开发者ID:flowlo,项目名称:appstats,代码行数:32,代码来源:handler.go

示例6: getTableProceed

func getTableProceed() string {
	if newappengine.IsDevAppServer() {
		return BIGQUERY_TABLE_PROCEED_DEV
	} else {
		return BIGQUERY_TABLE_PROCEED_PROD
	}
}
开发者ID:uve,项目名称:localization.expert,代码行数:7,代码来源:bigquery.go

示例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)
	})
}
开发者ID:tudorgergely,项目名称:api,代码行数:30,代码来源:main.go

示例8: initEnv

func initEnv() {
	if appengine.IsDevAppServer() {
		env = envDev
	} else {
		env = envProd
	}
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:7,代码来源:env.go

示例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
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:33,代码来源:warmup.go

示例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
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:33,代码来源:controllers.go

示例11: init

func init() {
	if appengine.IsDevAppServer() {
		AuthenticatorFactory = tokeninfoAuthenticatorFactory
	} else {
		AuthenticatorFactory = cachingAuthenticatorFactory
	}
}
开发者ID:davars,项目名称:go-endpoints,代码行数:7,代码来源:auth.go

示例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
}
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:10,代码来源:proxy.go

示例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"
	}
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:10,代码来源:main.go

示例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)
		}
	}
}
开发者ID:pbochis,项目名称:api,代码行数:12,代码来源:ws.go

示例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)
	}
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:12,代码来源:runner.go


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