本文整理匯總了Golang中net/http.Request.Scan方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Scan方法的具體用法?Golang Request.Scan怎麽用?Golang Request.Scan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net/http.Request
的用法示例。
在下文中一共展示了Request.Scan方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: findPageToRender
// Given a request, follow the segments through sitetree to find the page that is being requested. Doesn't
// understand actions, so just finds the page. Returns ID of SiteTree_Live record or 0 if it can't find a
// matching page.
// @todo Understand BaseController actions, or break on the furthest it gets up the tree
// @todo cache site tree
func findPageToRender(r *http.Request) (int, error) {
siteCache := getSiteCache()
if siteCache != nil {
id, found := siteCache.findPageToRender(r)
if found {
// fmt.Printf("page cache hit %d\n", id)
return id, nil
}
}
s := strings.Trim(r.URL.Path, "/")
path := strings.Split(s, "/")
if len(path) == 0 || path[0] == "" {
// find a home page ID
r, e := orm.Query("select \"ID\" from \"SiteTree_Live\" where \"URLSegment\"='home' and \"ParentID\"=0")
defer r.Close()
if e != nil {
return 0, e
}
if !r.Next() {
return 0, nil
}
var ID int
e = r.Scan(&ID)
return ID, e
}
currParentID := 0
for _, p := range path {
r, e := orm.Query("select \"ID\",\"ParentID\" from \"SiteTree_Live\" where \"URLSegment\"='" + p + "' and \"ParentID\"=" + strconv.Itoa(currParentID))
defer r.Close()
if e != nil {
return 0, e
}
if !r.Next() {
return 0, nil
}
var ID, ParentID int
e = r.Scan(&ID, &ParentID)
currParentID = ID
}
// if we get to the end, we've found a matching ID in SiteTree_Live
return currParentID, nil
}
示例2: findPageToRender
// Given a request, follow the segments through sitetree to find the page that is being requested. Doesn't
// understand actions, so just finds the page. Returns ID of SiteTree_Live record or 0 if it can't find a
// matching page.
// @todo Understand BaseController actions, or break on the furthest it gets up the tree
// @todo cache site tree
func (ctx *DBContext) findPageToRender(r *http.Request) (int, error) {
s := strings.Trim(r.URL.Path, "/")
path := strings.Split(s, "/")
if len(path) == 0 || path[0] == "" {
// find a home page ID
r, e := ctx.Query("select \"ID\" from \"SiteTree_Live\" where \"URLSegment\"='home' and \"ParentID\"=0")
if e != nil {
return 0, e
}
if !r.Next() {
return 0, nil
}
var ID int
e = r.Scan(&ID)
return ID, e
}
currParentID := 0
for _, p := range path {
r, e := ctx.Query("select \"ID\",\"ParentID\" from \"SiteTree_Live\" where \"URLSegment\"='" + p + "' and \"ParentID\"=" + strconv.Itoa(currParentID))
if e != nil {
return 0, e
}
if !r.Next() {
return 0, nil
}
var ID, ParentID int
e = r.Scan(&ID, &ParentID)
currParentID = ID
}
// if we get to the end, we've found a matching ID in SiteTree_Live
return currParentID, nil
}