本文整理汇总了Golang中net/http.Request.Add方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Add方法的具体用法?Golang Request.Add怎么用?Golang Request.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Request
的用法示例。
在下文中一共展示了Request.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: UpdateLoc
func (loc Locntrl) UpdateLoc(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var re Request
var r Response
id := p.ByName("id")
if !bson.IsObjectIdHex(id) {
w.WriteHeader(404)
return
}
id := bson.ObjectIdHex(id)
if err := loc.se.DB("jaspalgill").C("location").FindId(id).One(&r); err != nil {
w.WriteHeader(404)
return
}
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.Add = re.Add
r.City = re.City
r.State = re.State
r.Zip = re.Zip
r.Coordinate.Lat = coord.Coordinate.Lat
r.Coordinate.Lang = coord.Coordinate.Lang
c := loc.se.DB("jaspalgill").C("location")
i := bson.M{"id": id}
err := c.Update(i, response)
if err != nil {
panic(err)
}
result, _ := json.Marshal(r)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(201)
fmt.Fprintf(w, "%s", result)
}