本文整理匯總了Golang中github.com/flynn/flynn/blobstore/data.FileRepo.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileRepo.List方法的具體用法?Golang FileRepo.List怎麽用?Golang FileRepo.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/blobstore/data.FileRepo
的用法示例。
在下文中一共展示了FileRepo.List方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handler
func handler(r *data.FileRepo) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
path := path.Clean(req.URL.Path)
if path == "/" {
if req.Method == "HEAD" {
return
} else if req.Method != "GET" {
w.WriteHeader(404)
return
}
paths, err := r.List(req.URL.Query().Get("dir"))
if err != nil && err != backend.ErrNotFound {
errorResponse(w, err)
return
}
if paths == nil {
paths = []string{}
}
sort.Strings(paths)
w.WriteHeader(200)
json.NewEncoder(w).Encode(paths)
return
}
switch req.Method {
case "HEAD", "GET":
file, err := r.Get(path, req.Method == "GET")
if err != nil {
errorResponse(w, err)
return
}
if file.FileStream != nil {
defer file.Close()
}
if r, ok := file.FileStream.(backend.Redirector); ok && req.Method == "GET" {
http.Redirect(w, req, r.RedirectURL(), http.StatusFound)
return
}
w.Header().Set("Content-Length", strconv.FormatInt(file.Size, 10))
w.Header().Set("Content-Type", file.Type)
w.Header().Set("Etag", file.ETag)
http.ServeContent(w, req, path, file.ModTime, file)
case "PUT":
var err error
if src := req.Header.Get("Blobstore-Copy-From"); src != "" {
err = r.Copy(path, src)
} else {
var offset int64
if s := req.Header.Get("Blobstore-Offset"); s != "" {
offset, err = strconv.ParseInt(s, 10, 64)
if err != nil {
errorResponse(w, err)
return
}
}
err = r.Put(path, req.Body, offset, req.Header.Get("Content-Type"))
}
if err != nil {
errorResponse(w, err)
return
}
w.WriteHeader(200)
case "DELETE":
err := r.Delete(path)
if err != nil {
errorResponse(w, err)
return
}
w.WriteHeader(200)
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
})
}