-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity_dev.go
82 lines (65 loc) · 1.79 KB
/
identity_dev.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package appengine_internal
import (
"log"
"net/http"
"strconv"
"strings"
"github.com/golang/protobuf/proto"
pb "appengine_internal/modules"
)
// These functions are the dev implementations of the wrapper functions
// in ../appengine/identity.go. See that file for commentary.
const (
hRequestLogId = "X-AppEngine-Request-Log-Id"
)
func BackendHostname(c apiContext, name string, index int) string {
req := &pb.GetHostnameRequest{
Module: proto.String(name),
}
if index != -1 {
req.Instance = proto.String(strconv.Itoa(index))
}
res := &pb.GetHostnameResponse{}
if err := c.Call("modules", "GetHostname", req, res, nil); err != nil {
log.Printf("appengine: call to modules.GetHostname (name=%s, index=%d) failed: %s",
name, index, err)
return "" // The API doesn't allow for error returns.
}
return *res.Hostname
}
func DefaultVersionHostname(req interface{}) string {
return req.(*http.Request).Host
}
func ModuleName(req interface{}) string {
// instanceConfig.VersionID is either "module:version.timestamp"
// or "version.timestamp".
if i := strings.Index(instanceConfig.VersionID, ":"); i >= 0 {
return instanceConfig.VersionID[:i]
}
return "default"
}
func BackendInstance() int {
i, err := strconv.Atoi(InstanceID())
if err != nil {
return -1
}
return i
}
func VersionID(req interface{}) string {
return instanceConfig.VersionID
}
func InstanceID() string {
return instanceConfig.InstanceID
}
func Datacenter() string {
return instanceConfig.Datacenter
}
func ServerSoftware() string {
return "Development/2.0"
}
func RequestID(req interface{}) string {
return req.(*http.Request).Header.Get(hRequestLogId)
}