本文整理匯總了Golang中appengine.VersionID函數的典型用法代碼示例。如果您正苦於以下問題:Golang VersionID函數的具體用法?Golang VersionID怎麽用?Golang VersionID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了VersionID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetApiConfigs
// GetApiConfigs creates APIDescriptor for every registered RPCService and
// responds with a config suitable for generating Discovery doc.
//
// Responds with a list of active APIs and their configuration files.
func (s *BackendService) GetApiConfigs(
r *http.Request, req *GetAPIConfigsRequest, resp *APIConfigsList) error {
c := appengine.NewContext(r)
if req.AppRevision != "" {
revision := strings.Split(appengine.VersionID(c), ".")[1]
if req.AppRevision != revision {
err := fmt.Errorf(
"API backend app revision %s not the same as expected %s",
revision, req.AppRevision)
c.Errorf("%s", err)
return err
}
}
resp.Items = make([]string, 0)
for _, service := range s.server.services.services {
if service.internal {
continue
}
d := &APIDescriptor{}
if err := service.APIDescriptor(d, r.Host); err != nil {
c.Errorf("%s", err)
return err
}
bytes, err := json.Marshal(d)
if err != nil {
c.Errorf("%s", err)
return err
}
resp.Items = append(resp.Items, string(bytes))
}
return nil
}
示例2: 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)
}
示例3: root
func root(rw http.ResponseWriter, r *http.Request) {
context := appengine.NewContext(r)
version, _ := strconv.ParseInt(strings.Split(appengine.VersionID(context), ".")[1], 10, 64)
ctime := time.Unix(version/(1<<28)+8*3600, 0).Format(time.RFC3339)
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(rw, "GoProxy server %s works, deployed at %s\n", Version, ctime)
}
示例4: Run
// Run starts a query for log records, which contain request and application
// level log information.
func (params *Query) Run(c appengine.Context) *Result {
req := &log_proto.LogReadRequest{}
appId := c.FullyQualifiedAppID()
req.AppId = &appId
if params.StartTime != 0 {
req.StartTime = ¶ms.StartTime
}
if params.EndTime != 0 {
req.EndTime = ¶ms.EndTime
}
if params.Incomplete {
req.IncludeIncomplete = ¶ms.Incomplete
}
if params.AppLogs {
req.IncludeAppLogs = ¶ms.AppLogs
}
if params.ApplyMinLevel {
req.MinimumLogLevel = proto.Int32(int32(params.MinLevel))
}
if params.Versions == nil {
// If no versions were specified, default to the major version
// used by this app.
versionID := appengine.VersionID(c)
if i := strings.Index(versionID, "."); i >= 0 {
versionID = versionID[:i]
}
req.VersionId = []string{versionID}
} else {
req.VersionId = params.Versions
}
return &Result{context: c, request: req}
}
示例5: feedHandler
// HTTP handler for /feed
func feedHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-control", config.Require("cache_control_header"))
c := appengine.NewContext(r)
key := r.URL.Path + "@" + appengine.VersionID(c)
if item, err := memcache.Get(c, key); err == memcache.ErrCacheMiss {
c.Infof("Page %s not in the cache", key)
} else if err != nil {
c.Errorf("error getting page: %v", err)
} else {
c.Infof("Page %s found in the cache", key)
w.Write(item.Value)
return
}
entry_count, _ := config.GetInt("entries_per_page")
entries, _ := GetEntries(c, EntryQuery{IsPage: false, Count: int(entry_count)})
links := make([]SavedLink, 0)
context, _ := GetTemplateContext(entries, links, "Atom Feed", "feed", r)
var contentBuffer bytes.Buffer
feedTpl.ExecuteTemplate(&contentBuffer, "feed.html", context)
content, _ := ioutil.ReadAll(&contentBuffer)
w.Write(content)
// Feeds get cached infinitely, until an edit flushes it.
storeInCache(c, key, content, 0)
}
示例6: Run
// Run starts a query for log records, which contain request and application
// level log information.
func (params *Query) Run(c appengine.Context) *Result {
req, err := makeRequest(params, c.FullyQualifiedAppID(), appengine.VersionID(c))
return &Result{
context: c,
request: req,
err: err,
}
}
示例7: get
func (h Handler) get() {
version, _ := strconv.ParseInt(strings.Split(appengine.VersionID(h.context), ".")[1], 10, 64)
ctime := time.Unix(version/(1<<28)+8*3600, 0).Format(time.RFC3339)
h.response.WriteHeader(http.StatusOK)
h.response.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(h.response, "GoAgent Go Server %s \xe5\xb7\xb2\xe7\xbb\x8f\xe5\x9c\xa8\xe5\xb7\xa5\xe4\xbd\x9c\xe4\xba\x86\xef\xbc\x8c\xe9\x83\xa8\xe7\xbd\xb2\xe6\x97\xb6\xe9\x97\xb4 %s\n", Version, ctime)
}
示例8: handler
// handler is the main demo entry point that calls the GCS operations.
func handler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
c := appengine.NewContext(r)
if bucket == "" {
var err error
if bucket, err = file.DefaultBucketName(c); err != nil {
c.Errorf("failed to get default GCS bucket name: %v", err)
return
}
}
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.NewContext(appengine.AppID(c), hc)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(w, "Demo GCS Application running from Version: %v\n", appengine.VersionID(c))
fmt.Fprintf(w, "Using bucket name: %v\n\n", bucket)
d := &demo{
c: c,
w: w,
ctx: ctx,
}
n := "demo-testfile-go"
d.createFile(n)
d.readFile(n)
d.copyFile(n)
d.statFile(n)
d.createListFiles()
d.listBucket()
d.listBucketDirMode()
d.defaultACL()
d.putDefaultACLRule()
d.deleteDefaultACLRule()
d.bucketACL()
d.putBucketACLRule()
d.deleteBucketACLRule()
d.acl(n)
d.putACLRule(n)
d.deleteACLRule(n)
d.deleteFiles()
if d.failed {
io.WriteString(w, "\nDemo failed.\n")
} else {
io.WriteString(w, "\nDemo succeeded.\n")
}
}
示例9: BranchName
func BranchName(c appengine.Context) string {
if appengine.IsDevAppServer() {
return "localhost"
}
branchName := strings.Split(appengine.VersionID(c), ".")[0]
if len(branchName) > 0 {
return branchName
}
return "unkown"
}
示例10: handler
func handler(f func(c common.Context)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
c := common.Context{
Context: appengine.NewContext(r),
Req: r,
Resp: w,
Vars: mux.Vars(r),
}
c.User = user.Current(c)
c.Version = appengine.VersionID(c.Context)
f(c)
}
}
示例11: info
// info generates a page of information useful to the developers
func info(w http.ResponseWriter, r *http.Request) {
// must do all reading before any writing
var data struct {
Req *http.Request
Body []byte
BE error
Dctr string
GoArch string
GoOs string
GoVer string
VID string
Vtime string
MaxCx int
}
data.Req = r
data.Body, data.BE = ioutil.ReadAll(r.Body)
data.Dctr = appengine.Datacenter()
data.GoArch = runtime.GOARCH
data.GoOs = runtime.GOOS
data.GoVer = runtime.Version()
data.VID = appengine.VersionID(appengine.NewContext(r))
data.MaxCx = rx.MaxComplexity
var ver int
var bigtime int64
fmt.Sscanf(data.VID, "%d.%d", &ver, &bigtime)
if strings.HasPrefix(r.Host, "localhost:") {
// don't know how to decode this in SDK environment
data.Vtime = "?!"
} else {
// decode VID to match with appengine admin logs
t := time.Unix(bigtime>>28, 0)
data.Vtime = t.Format("01/02 15:04")
}
putheader(w, r, "Info")
fmt.Fprint(w,
"<P>(Information for use of the website maintainers.)\n<P>")
fmt.Fprintf(w, "<span class=cg>= cg =</span> \n") // .cg
fmt.Fprintf(w, "<span class=cw>= cw =</span> \n") // .cw
for i := 0; i < NCOLORS; i++ {
fmt.Fprintf(w, "<span class=%s>= %s =</span> \n",
colorname(i), colorname(i))
}
fmt.Fprintln(w)
tInfo.Execute(w, data)
putfooter(w, r)
}
示例12: handleID
func handleID(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(w, "appengine.AppID(c) = %q\n", appengine.AppID(c))
fmt.Fprintf(w, "appengine.VersionID(c) = %q\n", appengine.VersionID(c))
name, index := appengine.BackendInstance(c)
fmt.Fprintf(w, "appengine.BackendInstance(c) = %q, %d\n", name, index)
fmt.Fprintf(w, "----------\n")
for _, s := range os.Environ() {
fmt.Fprintln(w, s)
}
}
示例13: Run
// Run starts a query for log records, which contain request and application
// level log information.
func (params *Query) Run(c appengine.Context) *Result {
req := &pb.LogReadRequest{}
appId := c.FullyQualifiedAppID()
req.AppId = &appId
if !params.StartTime.IsZero() {
req.StartTime = proto.Int64(params.StartTime.UnixNano() / 1e3)
}
if !params.EndTime.IsZero() {
req.EndTime = proto.Int64(params.EndTime.UnixNano() / 1e3)
}
if params.Offset != nil {
var offset pb.LogOffset
if err := proto.Unmarshal(params.Offset, &offset); err != nil {
return &Result{context: c, err: fmt.Errorf("bad Offset: %v", err)}
}
req.Offset = &offset
}
if params.Incomplete {
req.IncludeIncomplete = ¶ms.Incomplete
}
if params.AppLogs {
req.IncludeAppLogs = ¶ms.AppLogs
}
if params.ApplyMinLevel {
req.MinimumLogLevel = proto.Int32(int32(params.MinLevel))
}
if params.Versions == nil {
// If no versions were specified, default to the major version
// used by this app.
versionID := appengine.VersionID(c)
if i := strings.Index(versionID, "."); i >= 0 {
versionID = versionID[:i]
}
req.VersionId = []string{versionID}
} else {
req.VersionId = params.Versions
}
if params.RequestIDs != nil {
ids := make([][]byte, len(params.RequestIDs))
for i, v := range params.RequestIDs {
ids[i] = []byte(v)
}
req.RequestId = ids
}
return &Result{context: c, request: req}
}
示例14: handleID
func handleID(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(w, "appengine.AppID(c) = %q\n", appengine.AppID(c))
fmt.Fprintf(w, "appengine.VersionID(c) = %q\n", appengine.VersionID(c))
name := appengine.ModuleName(c)
hostname, err := appengine.ModuleHostname(c, "", "", "")
fmt.Fprintf(w, "appengine.ModuleName(c) = %q\n", name)
fmt.Fprintf(w, `appengine.ModuleHostname(c, "", "", "") = %q (err: %v)`+"\n", hostname, err)
fmt.Fprintf(w, "----------\n")
for _, s := range os.Environ() {
fmt.Fprintln(w, s)
}
}
示例15: AppCache
func AppCache(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
w.Header().Set("Content-Type", "text/cache-manifest")
w.Header().Set("Cache-Control", "private, max-age=0, must-revalidate")
// Data to be sent to the template:
data := Template{Version: appengine.VersionID(c)}
// Parse the template and output HTML:
template, err := template.ParseFiles("support/manifest.appcache.skel")
if err != nil {
c.Criticalf("execution failed: %s", err)
}
err = template.Execute(w, data)
if err != nil {
c.Criticalf("execution failed: %s", err)
}
}