本文整理汇总了Golang中camlistore/org/pkg/httputil.PathSuffix函数的典型用法代码示例。如果您正苦于以下问题:Golang PathSuffix函数的具体用法?Golang PathSuffix怎么用?Golang PathSuffix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PathSuffix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (sh *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
suffix := httputil.PathSuffix(req)
handlers := getHandler
switch {
case httputil.IsGet(req):
// use default from above
case req.Method == "POST":
handlers = postHandler
default:
handlers = nil
}
fn := handlers[strings.TrimPrefix(suffix, "camli/search/")]
if fn != nil {
fn(sh, rw, req)
return
}
// TODO: discovery for the endpoints & better error message with link to discovery info
ret := camtypes.SearchErrorResponse{
Error: "Unsupported search path or method",
ErrorType: "input",
}
httputil.ReturnJSON(rw, &ret)
}
示例2: wantsClosure
func wantsClosure(req *http.Request) bool {
if req.Method == "GET" {
suffix := httputil.PathSuffix(req)
return closurePattern.MatchString(suffix)
}
return false
}
示例3: getSuffixMatches
func getSuffixMatches(req *http.Request, pattern *regexp.Regexp) bool {
if httputil.IsGet(req) {
suffix := httputil.PathSuffix(req)
return pattern.MatchString(suffix)
}
return false
}
示例4: ServeHTTP
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
base := httputil.PathBase(req)
subPath := httputil.PathSuffix(req)
switch req.Method {
case "GET", "HEAD":
switch subPath {
case "":
http.Redirect(rw, req, base+"camli/sig/discovery", http.StatusFound)
return
case h.pubKeyBlobRefServeSuffix:
h.pubKeyHandler.ServeHTTP(rw, req)
return
case "camli/sig/sign":
fallthrough
case "camli/sig/verify":
http.Error(rw, "POST required", 400)
return
case "camli/sig/discovery":
httputil.ReturnJSON(rw, h.DiscoveryMap(base))
return
}
case "POST":
switch subPath {
case "camli/sig/sign":
h.handleSign(rw, req)
return
case "camli/sig/verify":
h.handleVerify(rw, req)
return
}
}
http.Error(rw, "Unsupported path or method.", http.StatusBadRequest)
}
示例5: 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)
}
示例6: wantsClosure
func wantsClosure(req *http.Request) bool {
if httputil.IsGet(req) {
suffix := httputil.PathSuffix(req)
return closurePattern.MatchString(suffix)
}
return false
}
示例7: 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)
}
示例8: ServeHTTP
// ServeHTTP serves:
// http://host/importer/
// http://host/importer/twitter/
// http://host/importer/twitter/callback
// http://host/importer/twitter/sha1-abcabcabcabcabc (single account)
func (h *Host) ServeHTTP(w http.ResponseWriter, r *http.Request) {
suffix := httputil.PathSuffix(r)
seg := strings.Split(suffix, "/")
if suffix == "" || len(seg) == 0 {
h.serveImportersRoot(w, r)
return
}
impName := seg[0]
imp, ok := h.imp[impName]
if !ok {
http.NotFound(w, r)
return
}
if len(seg) == 1 || seg[1] == "" {
h.serveImporter(w, r, imp)
return
}
if seg[1] == "callback" {
h.serveImporterAcctCallback(w, r, imp)
return
}
acctRef, ok := blob.Parse(seg[1])
if !ok {
http.NotFound(w, r)
return
}
h.serveImporterAccount(w, r, imp, acctRef)
}
示例9: serveHTTP
func (h *shareHandler) serveHTTP(rw http.ResponseWriter, req *http.Request) error {
var err error
pathSuffix := httputil.PathSuffix(req)
if len(pathSuffix) == 0 {
// This happens during testing because we don't go through PrefixHandler
pathSuffix = strings.TrimLeft(req.URL.Path, "/")
}
pathParts := strings.SplitN(pathSuffix, "/", 2)
blobRef, ok := blob.Parse(pathParts[0])
if !ok {
err = &shareError{code: invalidURL, response: badRequest,
message: fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix)}
} else {
err = handleGetViaSharing(rw, req, blobRef, h.fetcher)
}
if se, ok := err.(*shareError); ok {
switch se.response {
case badRequest:
httputil.BadRequestError(rw, err.Error())
case unauthorizedRequest:
log.Print(err)
auth.SendUnauthorized(rw, req)
}
}
return err
}
示例10: ServeHTTP
func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
blobRef, ok := blob.Parse(httputil.PathSuffix(req))
if !ok {
http.Error(rw, "Malformed share URL.", 400)
return
}
handleGetViaSharing(rw, req, blobRef, h.fetcher)
}
示例11: ServeHTTP
func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
pathSuffix := httputil.PathSuffix(req)
pathParts := strings.SplitN(pathSuffix, "/", 2)
blobRef, ok := blob.Parse(pathParts[0])
if !ok {
http.Error(rw, fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix), 400)
return
}
handleGetViaSharing(rw, req, blobRef, h.fetcher)
}
示例12: ServeHTTP
func (ui *UIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
suffix := httputil.PathSuffix(req)
rw.Header().Set("Vary", "Accept")
switch {
case wantsDiscovery(req):
ui.root.serveDiscovery(rw, req)
case wantsUploadHelper(req):
ui.serveUploadHelper(rw, req)
case strings.HasPrefix(suffix, "download/"):
ui.serveDownload(rw, req)
case strings.HasPrefix(suffix, "thumbnail/"):
ui.serveThumbnail(rw, req)
case strings.HasPrefix(suffix, "tree/"):
ui.serveFileTree(rw, req)
case strings.HasPrefix(suffix, "qr/"):
ui.serveQR(rw, req)
case getSuffixMatches(req, closurePattern):
ui.serveClosure(rw, req)
case getSuffixMatches(req, lessPattern):
ui.serveFromDiskOrStatic(rw, req, lessPattern, ui.fileLessHandler, lessstatic.Files)
case getSuffixMatches(req, reactPattern):
ui.serveFromDiskOrStatic(rw, req, reactPattern, ui.fileReactHandler, reactstatic.Files)
case getSuffixMatches(req, glitchPattern):
ui.serveFromDiskOrStatic(rw, req, glitchPattern, ui.fileGlitchHandler, glitchstatic.Files)
case getSuffixMatches(req, fontawesomePattern):
ui.serveFromDiskOrStatic(rw, req, fontawesomePattern, ui.fileFontawesomeHandler, fontawesomestatic.Files)
default:
file := ""
if m := staticFilePattern.FindStringSubmatch(suffix); m != nil {
file = m[1]
} else {
switch {
case wantsBlobRef(req):
file = "index.html"
case wantsPermanode(req):
file = "permanode.html"
case wantsBlobInfo(req):
file = "blobinfo.html"
case wantsFileTreePage(req):
file = "filetree.html"
case req.URL.Path == httputil.PathBase(req):
file = "index.html"
default:
http.Error(rw, "Illegal URL.", http.StatusNotFound)
return
}
}
if file == "deps.js" {
serveDepsJS(rw, req, ui.uiDir)
return
}
ServeStaticFile(rw, req, uistatic.Files, file)
}
}
示例13: ServeHTTP
func (sh *StatusHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
suffix := httputil.PathSuffix(req)
if req.Method != "GET" {
http.Error(rw, "Illegal URL.", http.StatusMethodNotAllowed)
return
}
if suffix == "status.json" {
sh.serveStatus(rw, req)
return
}
http.Error(rw, "Illegal URL.", 404)
}
示例14: ServeHTTP
func (hh *HelpHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
suffix := httputil.PathSuffix(req)
if !httputil.IsGet(req) {
http.Error(rw, "Illegal help method.", http.StatusMethodNotAllowed)
return
}
switch suffix {
case "":
hh.serveHelpHTML(rw, req)
default:
http.Error(rw, "Illegal help path.", http.StatusNotFound)
}
}
示例15: ServeHTTP
func (a *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if camhttputil.PathSuffix(req) == "config.json" {
if a.auth.AllowedAccess(req)&auth.OpGet == auth.OpGet {
camhttputil.ReturnJSON(rw, a.appConfig)
} else {
auth.SendUnauthorized(rw, req)
}
return
}
if a.proxy == nil {
http.Error(rw, "no proxy for the app", 500)
return
}
a.proxy.ServeHTTP(rw, req)
}