本文整理汇总了Golang中net/http.Request.Attach方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Attach方法的具体用法?Golang Request.Attach怎么用?Golang Request.Attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Request
的用法示例。
在下文中一共展示了Request.Attach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
//.........这里部分代码省略.........
ids := make([]string, 0, len(allowed))
for i := range allowed {
ids = append(ids, i)
}
bidders := e.Bidders.Bidders(ids)
bestPrice := ""
bestPriority := ""
best := -1
for i := range bidders {
if bidders[i] == nil {
continue
}
price, priority := bidders[i].Bid(ctx)
if price == "" {
continue
}
if best != -1 {
if len(priority) < len(bestPriority) {
continue
}
if len(priority) == len(bestPriority) && priority < bestPriority {
continue
}
if priority == bestPriority {
if len(price) < len(bestPrice) {
continue
}
if len(price) == len(bestPrice) && price < bestPrice {
continue
}
}
}
bestPrice = price
bestPriority = priority
best = i
}
if best == -1 {
trace.Leave(ctx, "NoAllowedBidders")
w.WriteHeader(http.StatusNoContent)
return
}
text := `{"seatbid":[{"bid":[{"impid":"%s","price":%f,"crid":"%s","ext":{"priority":%s,"external-id":%s}}]}]}`
cpm := 0.0
if money, err := strconv.Atoi(strings.TrimSuffix(bestPrice, "USD/1M")); err != nil {
trace.Error(ctx, "Errors.Price", err)
w.WriteHeader(http.StatusNoContent)
return
} else {
cpm = float64(money) / 1000.0
}
cid := ids[best]
augmenters := bidders[best].Augmenters
if augmenters != nil {
if f := augmenters.Forensiq; e.Client != nil && f != nil {
r := &rtb.Components{}
r.Attach("fields", value)
score := e.forensiqRiskScore(ctx, r)
trace.Record(ctx, "Score", score)
if score > f.Configuration.RiskScore {
trace.Leave(ctx, "ForensiqRiskScore")
w.WriteHeader(http.StatusNoContent)
return
}
}
}
crid := allowed[cid][0]
b := string(body)
if strings.Contains(b, cid) == false {
log.Println(b)
log.Println(allowed, ids, cid, crid, best)
}
w.Header().Set("Content-Type", "application/json")
if _, err := fmt.Fprintf(w, text, impid, cpm, crid, bestPriority, cid); err != nil {
trace.Error(ctx, "Errors.Response", err)
return
}
//jsons.Put(value)
trace.Leave(ctx, "Responded")
}