本文整理汇总了Golang中camlistore/org/pkg/httputil.ErrorRouting函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorRouting函数的具体用法?Golang ErrorRouting怎么用?Golang ErrorRouting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorRouting函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serveFileTree
func (ui *UIHandler) serveFileTree(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := httputil.PathSuffix(req)
m := treePattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
blobref, ok := blob.Parse(m[1])
if !ok {
http.Error(rw, "Invalid blobref", 400)
return
}
fth := &FileTreeHandler{
Fetcher: ui.root.Storage,
file: blobref,
}
fth.ServeHTTP(rw, req)
}
示例2: serveDownload
func (ui *UIHandler) serveDownload(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := httputil.PathSuffix(req)
m := downloadPattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
fbr, ok := blob.Parse(m[1])
if !ok {
http.Error(rw, "Invalid blobref", 400)
return
}
dh := &DownloadHandler{
Fetcher: ui.root.Storage,
Cache: ui.Cache,
}
dh.ServeHTTP(rw, req, fbr)
}
示例3: serveClosure
func (ui *UIHandler) serveClosure(rw http.ResponseWriter, req *http.Request) {
suffix := httputil.PathSuffix(req)
if ui.closureHandler == nil {
log.Printf("%v not served: closure handler is nil", suffix)
http.NotFound(rw, req)
return
}
m := closurePattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
req.URL.Path = "/" + m[1]
ui.closureHandler.ServeHTTP(rw, req)
}
示例4: serveThumbnail
func (ui *UIHandler) serveThumbnail(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
m := thumbnailPattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
query := req.URL.Query()
width, err := strconv.Atoi(query.Get("mw"))
if err != nil {
http.Error(rw, "Invalid specified max width 'mw'", 500)
return
}
height, err := strconv.Atoi(query.Get("mh"))
if err != nil {
http.Error(rw, "Invalid specified height 'mh'", 500)
return
}
blobref := blobref.Parse(m[1])
if blobref == nil {
http.Error(rw, "Invalid blobref", 400)
return
}
th := &ImageHandler{
Fetcher: ui.root.Storage,
Cache: ui.Cache,
MaxWidth: width,
MaxHeight: height,
sc: ui.sc,
}
th.ServeHTTP(rw, req, blobref)
}
示例5: serveThumbnail
func (ui *UIHandler) serveThumbnail(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := httputil.PathSuffix(req)
m := thumbnailPattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
query := req.URL.Query()
width, _ := strconv.Atoi(query.Get("mw"))
height, _ := strconv.Atoi(query.Get("mh"))
blobref, ok := blob.Parse(m[1])
if !ok {
http.Error(rw, "Invalid blobref", 400)
return
}
if width == 0 {
width = search.MaxImageSize
}
if height == 0 {
height = search.MaxImageSize
}
th := &ImageHandler{
Fetcher: ui.root.Storage,
Cache: ui.Cache,
MaxWidth: width,
MaxHeight: height,
ThumbMeta: ui.thumbMeta,
ResizeSem: ui.resizeSem,
Search: ui.search,
}
th.ServeHTTP(rw, req, blobref)
}