本文整理汇总了Golang中net/http.Request.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Name方法的具体用法?Golang Request.Name怎么用?Golang Request.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Request
的用法示例。
在下文中一共展示了Request.Name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ApiHandler
func ApiHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
vars := mux.Vars(r)
neighbors_lock.RLock()
defer neighbors_lock.RUnlock()
type ipasnResult struct {
ASN ASN
ASPath ASPath `json:",omitempty"`
Name string `json:",omitempty"`
Prefix string `json:",omitempty"`
}
switch vars["method"] {
case "ipasn":
_ = r.ParseForm()
ip := net.ParseIP(r.Form.Get("ip"))
if ip == nil {
w.WriteHeader(400)
fmt.Fprintln(w, "Bad IP address")
return
}
result := make(map[string]*ipasnResult)
for neighbor, data := range neighbors {
data.lock.RLock()
defer data.lock.RUnlock()
node := data.FindNode(&ip)
if node.Bits() > 0 {
result[neighbor] = new(ipasnResult)
route := node.Value.(*Route)
r := result[neighbor]
r.ASN = ASN(route.PrimaryASN)
r.ASPath = route.ASPath
r.Name = ""
r.Prefix = nodeToIPNet(node).String()
}
}
json, err := json.Marshal(map[string]interface{}{"result": result})
if err != nil {
w.WriteHeader(500)
log.Println("Error generating json", err)
fmt.Fprintln(w, "Could not generate JSON")
}
fmt.Fprint(w, string(json), "\n")
default:
w.WriteHeader(404)
return
}
}
示例2: serveTop
// serveTop prints a list of the top repository for each language.
func (h *Handler) serveTop(w http.ResponseWriter, r *http.Request) {
// Retrieve the top repositories.
m, err := h.Store.TopRepositories()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Sort keys.
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
w.Header().Set("content-type", "text/plain")
// Print results.
for _, k := range keys {
r := m[k]
fmt.Fprintf(w, "%s: %s - %s\n", k, r.Name(), r.Description)
}
}
示例3: CreateLoc
func (loc Locntrl) CreateLoc(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var re Request
var r Response
json.NewDecoder(r.Body).Decode(&re)
coord := getLoc(re.Address + "+" + re.City + "+" + re.State + "+" + re.Zip)
fmt.Println("Lat:", coord.Coordinate.Lat, "Long:", coord.Coordinate.Lang)
r.Id = bson.NewObjectId()
r.Add = re.Add
r.City = re.City
r.Name = re.Name
r.Zip = re.Zip
r.State = re.State
r.Coordinate.Lang = coord.Coordinate.Lang
r.Coordinate.Lat = coord.Coordinate.Lat
loc.se.DB("jaspalgill").C("location").Insert(r)
result, _ := json.Marshal(r)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(201)
fmt.Fprintf(w, "%s", result)
}
示例4: Index
func Index(w http.ResponseWriter, r *http.Request) {
keys := make([]string, modulus)
for i := range keys {
keys[i] = fmt.Sprintf(keyPart, i*distance)
}
c := context(r)
items, err := memcache.GetMulti(c, keys)
if err != nil {
return
}
ars := AllRequestStats{}
for _, v := range items {
t := stats_part{}
err := gob.NewDecoder(bytes.NewBuffer(v.Value)).Decode(&t)
if err != nil {
continue
}
r := RequestStats(t)
ars = append(ars, &r)
}
sort.Sort(reverse{ars})
requestById := make(map[int]*RequestStats, len(ars))
idByRequest := make(map[*RequestStats]int, len(ars))
requests := make(map[int]*StatByName)
byRequest := make(map[int]map[string]cVal)
for i, v := range ars {
idx := i + 1
requestById[idx] = v
idByRequest[v] = idx
requests[idx] = &StatByName{
RequestStats: v,
}
byRequest[idx] = make(map[string]cVal)
}
requestByPath := make(map[string][]int)
byCount := make(map[string]cVal)
byRPC := make(map[SKey]cVal)
for _, t := range ars {
id := idByRequest[t]
requestByPath[t.Path] = append(requestByPath[t.Path], id)
for _, r := range t.RPCStats {
rpc := r.Name()
v := byRequest[id][rpc]
v.count++
v.cost += r.Cost
byRequest[id][rpc] = v
v = byCount[rpc]
v.count++
v.cost += r.Cost
byCount[rpc] = v
v = byRPC[SKey{rpc, t.Path}]
v.count++
v.cost += r.Cost
byRPC[SKey{rpc, t.Path}] = v
}
}
for k, v := range byRequest {
stats := StatsByName{}
for rpc, s := range v {
stats = append(stats, &StatByName{
Name: rpc,
Count: s.count,
Cost: s.cost,
})
}
sort.Sort(reverse{stats})
requests[k].SubStats = stats
}
statsByRPC := make(map[string]StatsByName)
pathStats := make(map[string]StatsByName)
for k, v := range byRPC {
statsByRPC[k.a] = append(statsByRPC[k.a], &StatByName{
Name: k.b,
Count: v.count,
Cost: v.cost,
})
pathStats[k.b] = append(pathStats[k.b], &StatByName{
Name: k.a,
Count: v.count,
Cost: v.cost,
})
}
for k, v := range statsByRPC {
sort.Sort(reverse{v})
statsByRPC[k] = v
}
pathStatsByCount := StatsByName{}
for k, v := range pathStats {
//.........这里部分代码省略.........
示例5: Details
func Details(w http.ResponseWriter, r *http.Request) {
i, _ := strconv.Atoi(r.FormValue("time"))
qtime := roundTime(i)
key := fmt.Sprintf(keyFull, qtime)
c := context(r)
v := struct {
Env map[string]string
Record *RequestStats
Header http.Header
AllStatsByCount StatsByName
Real time.Duration
}{
Env: map[string]string{
"APPLICATION_ID": appengine.AppID(c),
},
}
item, err := memcache.Get(c, key)
if err != nil {
templates.ExecuteTemplate(w, "details", v)
return
}
full := stats_full{}
err = gob.NewDecoder(bytes.NewBuffer(item.Value)).Decode(&full)
if err != nil {
templates.ExecuteTemplate(w, "details", v)
return
}
byCount := make(map[string]cVal)
durationCount := make(map[string]time.Duration)
var _real time.Duration
for _, r := range full.Stats.RPCStats {
rpc := r.Name()
// byCount
if _, present := byCount[rpc]; !present {
durationCount[rpc] = 0
}
v := byCount[rpc]
v.count++
v.cost += r.Cost
byCount[rpc] = v
durationCount[rpc] += r.Duration
_real += r.Duration
}
allStatsByCount := StatsByName{}
for k, v := range byCount {
allStatsByCount = append(allStatsByCount, &StatByName{
Name: k,
Count: v.count,
Cost: v.cost,
Duration: durationCount[k],
})
}
sort.Sort(allStatsByCount)
v.Record = full.Stats
v.Header = full.Header
v.AllStatsByCount = allStatsByCount
v.Real = _real
_ = templates.ExecuteTemplate(w, "details", v)
}