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


Golang appengine.DefaultVersionHostname函數代碼示例

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


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

示例1: realhostname

func realhostname(req *http.Request, c appengine.Context) (string, error) {
	if req.RequestURI == "" {
		return appengine.DefaultVersionHostname(c), nil
	}
	myurl, err := url.Parse(req.RequestURI)
	if err != nil {
		return "", err
	}
	if !myurl.IsAbs() {
		return appengine.DefaultVersionHostname(c), nil
	}
	return myurl.Host, nil
}
開發者ID:wickedchicken,項目名稱:blarg,代碼行數:13,代碼來源:layout.go

示例2: realInit

func realInit(w http.ResponseWriter, r *http.Request) bool {
	ctx := appengine.NewContext(r)

	errf := func(format string, args ...interface{}) bool {
		ctx.Errorf("In init: "+format, args...)
		http.Error(w, fmt.Sprintf(format, args...), 500)
		return false
	}

	config, err := serverconfig.Load("./config.json")
	if err != nil {
		return errf("Could not load server config: %v", err)
	}

	// Update the config to use the URL path derived from the first App Engine request.
	// TODO(bslatkin): Support hostnames that aren't x.appspot.com
	scheme := "http"
	if r.TLS != nil {
		scheme = "https"
	}

	baseURL := fmt.Sprintf("%s://%s/", scheme, appengine.DefaultVersionHostname(ctx))
	ctx.Infof("baseurl = %q", baseURL)

	root.mux = http.NewServeMux()
	_, err = config.InstallHandlers(root.mux, baseURL, r)
	if err != nil {
		return errf("Error installing handlers: %v", err)
	}

	return true
}
開發者ID:newobject,項目名稱:camlistore,代碼行數:32,代碼來源:main.go

示例3: aboutPage

func aboutPage(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	fmt.Fprintf(w, "<h1>%v</h1>", appengine.DefaultVersionHostname(c))

	token, expire, _ := appengine.AccessToken(c, "test")
	fmt.Fprintf(w, "<p>AccessToken: %v %v", token, expire)

	fmt.Fprintf(w, "<p>AppID: %v", appengine.AppID(c))
	fmt.Fprintf(w, "<p>FQAppID: %v", c.FullyQualifiedAppID())
	fmt.Fprintf(w, "<p>Go version: %v", runtime.Version())
	fmt.Fprintf(w, "<p>Datacenter: %v", appengine.Datacenter())
	fmt.Fprintf(w, "<p>InstanceID: %v", appengine.InstanceID())
	fmt.Fprintf(w, "<p>IsDevAppServer: %v", appengine.IsDevAppServer())
	fmt.Fprintf(w, "<p>RequestID: %v", appengine.RequestID(c))
	fmt.Fprintf(w, "<p>ServerSoftware: %v", appengine.ServerSoftware())

	sa, _ := appengine.ServiceAccount(c)
	fmt.Fprintf(w, "<p>ServiceAccount: %v", sa)

	keyname, signed, _ := appengine.SignBytes(c, []byte("test"))
	fmt.Fprintf(w, "<p>SignBytes: %v %v", keyname, signed)
	fmt.Fprintf(w, "<p>VersionID: %v", appengine.VersionID(c))

	fmt.Fprintf(w, "<p>Request: %v", r)
	r2 := c.Request()
	fmt.Fprintf(w, "<p>Context Request type/value: %T %v", r2, r2)
}
開發者ID:jmptrader,項目名稱:jra-go,代碼行數:27,代碼來源:appengine.go

示例4: Presentation

//Presentation handles showing page with details about a presentation.
func Presentation(c util.Context) (err error) {
	pk, err := datastore.DecodeKey(c.Vars["id"])
	if err != nil {
		return
	}

	p, err := presentation.GetByKey(pk, c)
	if err != nil {
		return
	}
	as, err := action.GetFor(p, c)
	if err != nil {
		return
	}

	a := prepareActions(as)

	desc := blackfriday.MarkdownCommon(p.Description)

	acts, err := activation.GetForPresentation(pk, c)
	if err != nil {
		return
	}

	util.RenderLayout("presentation.html", "Info o prezentácií", struct {
		P           *presentation.Presentation
		A           map[string][]time.Time
		Desc        template.HTML
		ZeroTime    time.Time
		Domain      string
		Activations []*activation.Activation
		Tz          *time.Location
	}{p, a, template.HTML(desc), time.Date(0001, 01, 01, 00, 00, 00, 00, utc), appengine.DefaultVersionHostname(c), acts, util.Tz}, c, "/static/js/underscore-min.js", "/static/js/presentation.js")
	return
}
開發者ID:sellweek,項目名稱:TOGY-server,代碼行數:36,代碼來源:broadcast.go

示例5: send

// send uses the Channel API to send the provided message in JSON-encoded form
// to the client identified by clientID.
//
// Channels created with one version of an app (eg, the default frontend)
// cannot be sent on from another version (eg, a backend). This is a limitation
// of the Channel API that should be fixed at some point.
// The send function creates a task that runs on the frontend (where the
// channel was created). The task handler makes the channel.Send API call.
func send(c appengine.Context, clientID string, m Message) {
	if clientID == "" {
		c.Debugf("no channel; skipping message send")
		return
	}
	switch {
	case m.TilesDone:
		c.Debugf("tiles done")
	case m.ZipDone:
		c.Debugf("zip done")
	default:
		c.Debugf("%d tiles", len(m.IDs))
	}
	b, err := json.Marshal(m)
	if err != nil {
		panic(err)
	}
	task := taskqueue.NewPOSTTask("/send", url.Values{
		"clientID": {clientID},
		"msg":      {string(b)},
	})
	host := appengine.DefaultVersionHostname(c)
	task.Header.Set("Host", host)
	if _, err := taskqueue.Add(c, task, sendQueue); err != nil {
		c.Errorf("add send task failed: %v", err)
	}
}
開發者ID:TheAustrianPro,項目名稱:overlay-tiler,代碼行數:35,代碼來源:task.go

示例6: handler

func handler(w http.ResponseWriter, r *http.Request) {
	img_url := r.FormValue("me")

	if len(img_url) == 0 {
		http.Redirect(w, r, "/index.html", 307)
		return
	}

	c := appengine.NewContext(r)

	c.Infof("Host: %v", appengine.DefaultVersionHostname(c))

	item, err := getCached(c, img_url, do)

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "image/jpeg")
	w.Header().Set("Content-Length", strconv.Itoa(len(item.Value)))
	if _, err := w.Write(item.Value); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
開發者ID:coel,項目名稱:greenyfy,代碼行數:25,代碼來源:greenyfy.go

示例7: CreateUrls

func (fi *FileInfo) CreateUrls(r *http.Request, c appengine.Context) {
	u := &url.URL{
		Scheme: r.URL.Scheme,
		Host:   appengine.DefaultVersionHostname(c),
		Path:   "/",
	}
	uString := u.String()
	fi.Url = uString + escape(string(fi.Key)) + "/" +
		escape(string(fi.Name))
	fi.DeleteUrl = fi.Url + "?delete=true"
	fi.DeleteType = "DELETE"
	if imageTypes.MatchString(fi.Type) {
		servingUrl, err := image.ServingURL(
			c,
			fi.Key,
			&image.ServingURLOptions{
				Secure: strings.HasSuffix(u.Scheme, "s"),
				Size:   0,
				Crop:   false,
			},
		)
		check(err)
		fi.ThumbnailUrl = servingUrl.String() + THUMBNAIL_PARAM
	}
}
開發者ID:omairrazam,項目名稱:bapp,代碼行數:25,代碼來源:main.go

示例8: cron

func cron(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	q := datastore.NewQuery("asin")

	for t := q.Run(c); ; {
		var x Asin
		_, err := t.Next(&x)
		if err == datastore.Done {
			break
		}
		if err != nil {
			return
		}

		task := taskqueue.NewPOSTTask("/task/fetching", url.Values{
			"asin": {x.Name},
		})

		if !appengine.IsDevAppServer() {
			host := backendName + "." + appengine.DefaultVersionHostname(c)
			task.Header.Set("Host", host)
		}

		if _, err := taskqueue.Add(c, task, ""); err != nil {
			c.Errorf("add fetching task: %v", err)
			http.Error(w, "Error: couldn't schedule fetching task", 500)
			return
		}

		fmt.Fprintf(w, "OK")
	}
}
開發者ID:moonpala,項目名稱:snapshot,代碼行數:32,代碼來源:frontend.go

示例9: handler

func handler(w http.ResponseWriter, r *http.Request) {
	context := appengine.NewContext(r)

	err := parse_chunk_map(context)

	if err != nil {
		log.Fatal("error:", err)
	} else {
		// Determine which file is being requested then construct cached version
		// by collecting the chunks together into one big download.

		w.Header().Set("Content-Type", "application/json")

		var chunkMapWithUrls map[string][]ChunkEntry = make(map[string][]ChunkEntry)

		bigFilename := r.URL.Path

		if len(bigFilename) == 0 {
			log.Fatal(fmt.Sprintf("path \"%s\"", bigFilename))
		} else if bigFilename[0] != '/' {
			log.Fatal(fmt.Sprintf("path \"%s\"", bigFilename))
		} else if strings.Count(bigFilename, "/") != 1 {
			log.Fatal(fmt.Sprintf("path \"%s\"", bigFilename))
		}

		bigFilename = bigFilename[1:]
		chunkArr := chunkMap[bigFilename]

		{
			var chunks []ChunkEntry = make([]ChunkEntry, len(chunkArr))

			for i, chunkEntry := range chunkArr {
				chunks[i] = chunkEntry
				chunks[i].ChunkName = fmt.Sprintf("%s%s/chunk/%s", "http://", appengine.DefaultVersionHostname(context), chunkEntry.ChunkName)
			}

			chunkMapWithUrls[bigFilename] = chunks
		}

		bytes, err := json.MarshalIndent(chunkMapWithUrls, "", "  ")
		if err != nil {
			log.Fatal("error:", err)
		}

		bytes = append(bytes, '\n')

		_, err = w.Write(bytes)
		if err != nil {
			log.Fatal("error:", err)
		}
	}
}
開發者ID:carriercomm,項目名稱:GoFreeCDN,代碼行數:52,代碼來源:servefile.go

示例10: CreateUrls

func (fi *FileInfo) CreateUrls(r *http.Request, c appengine.Context) {
	u := &url.URL{
		Scheme: r.URL.Scheme,
		Host:   appengine.DefaultVersionHostname(c),
		Path:   "/",
	}
	uString := u.String()
	fi.Url = uString + fi.Key
	fi.DeleteUrl = fi.Url
	fi.DeleteType = "DELETE"
	if fi.ThumbnailKey != "" {
		fi.ThumbnailUrl = uString + fi.ThumbnailKey
	}
}
開發者ID:devCPXL,項目名稱:gestion_stock_old,代碼行數:14,代碼來源:main.go

示例11: Presentations

//Presentations shows listing of presentations in paginated form.
func Presentations(c util.Context) (err error) {
	page, err := strconv.Atoi(c.R.FormValue("p"))
	if err != nil {
		return
	}
	ps, err := presentation.GetListing(page, perPage, c)
	if err != nil {
		return
	}

	type templateData struct {
		P presentation.Presentation
		D template.HTML
	}

	data := make([]templateData, len(ps), len(ps))

	for _, p := range ps {
		data = append(data, templateData{P: *p, D: template.HTML(blackfriday.MarkdownCommon(p.Description))})
	}

	maxPages, err := presentation.PageCount(perPage, c)
	if err != nil {
		return
	}

	c.Infof("Hostname: %v", appengine.DefaultVersionHostname(c))

	util.RenderLayout("index.html", "Zoznam vysielaní", struct {
		Page     int
		MaxPages int
		Data     []templateData
		Domain   string
	}{Page: page, MaxPages: maxPages, Data: data, Domain: appengine.DefaultVersionHostname(c)}, c, "/static/js/index.js")
	return
}
開發者ID:sellweek,項目名稱:TOGY-server,代碼行數:37,代碼來源:public.go

示例12: getBeardFromUrl

func getBeardFromUrl(c appengine.Context, key string) (*bytes.Buffer, error) {
	client := urlfetch.Client(c)
	resp, err := client.Get("http://" + appengine.DefaultVersionHostname(c) + "/images/beard.png")

	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	buff := new(bytes.Buffer)
	buff.ReadFrom(resp.Body)

	return buff, nil
}
開發者ID:coel,項目名稱:greenyfy,代碼行數:15,代碼來源:beard.go

示例13: CreateUrls

func (fi *FileInfo) CreateUrls(r *http.Request, c appengine.Context) {
	u := &url.URL{
		Scheme: r.URL.Scheme,
		Host:   appengine.DefaultVersionHostname(c),
	}
	u.Path = "/" + url.QueryEscape(string(fi.Key)) + "/" +
		url.QueryEscape(string(fi.Name))
	fi.Url = u.String()
	fi.DeleteUrl = fi.Url
	fi.DeleteType = "DELETE"
	if fi.ThumbnailUrl != "" && -1 == strings.Index(
		r.Header.Get("Accept"),
		"application/json",
	) {
		u.Path = "/thumbnails/" + url.QueryEscape(string(fi.Key))
		fi.ThumbnailUrl = u.String()
	}
}
開發者ID:steliomo,項目名稱:jQuery-File-Upload,代碼行數:18,代碼來源:main.go

示例14: handler

func handler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	fmt.Fprintf(w, "<!DOCTYPE html>")
	fmt.Fprintf(w, "<html><head><title>appengineパッケージ</title></head><body>")

	if appengine.IsDevAppServer() {
		// 開発環境
		fmt.Fprintf(w, "開発環境で動作しています。。<br>")
	} else {
		fmt.Fprintf(w, "本番環境で動作しています。<br>")
	}

	c := appengine.NewContext(r)

	fmt.Fprintf(w, "AppID(): %s<br>", appengine.AppID(c))
	fmt.Fprintf(w, "DefaultVersionHostname(): %s<br>", appengine.DefaultVersionHostname(c))

	fmt.Fprintf(w, "VersionID(): %s<br>", appengine.VersionID(c))
	fmt.Fprintf(w, "</body></html>")
}
開發者ID:ghostnotes,項目名稱:HelloGo,代碼行數:20,代碼來源:appenginesample.go

示例15: homeHandler

func homeHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	data := map[string]string{
		"isDevelopment":   appEngineEnvironment("isDevelopment"),
		"isProduction":    appEngineEnvironment("isProduction"),
		"currentHostname": appengine.DefaultVersionHostname(c),
	}

	tpl, err := ace.Load("base", "inner", &ace.Options{
		BaseDir:       "views",
		DynamicReload: true})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := tpl.Execute(w, data); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
開發者ID:aficiomaquinas,項目名稱:i18n-cd-mx,代碼行數:22,代碼來源:server.go


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