fileserver
import "github.com/tangoui/tango/service/fileserver"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package fileserver serves a local directory over HTTP, for showing user files (downloads, generated images, a documents folder) in a page. Mount it under a prefix of the app's asset handler with Mount.
Requests cannot leave the directory: paths containing ".." are refused, and files are opened through an os.Root, so symlinks pointing outside the directory are not followed either. Directory listings and dotfiles are not served unless enabled.
函数
func Mount
func Mount(prefix string, srv http.Handler, next http.Handler) http.HandlerMount returns a handler that serves srv under prefix (e.g. "/files/") and passes every other request to next (nil: 404). The prefix is stripped before srv sees the path.
类型
Options
type Options struct {
// List enables directory listings. Without it a directory is served
// only through its index.html.
List bool
// Dotfiles allows serving entries whose name starts with ".".
Dotfiles bool
// contains filtered or unexported fields
}Options configures New.
Server
type Server struct {
// contains filtered or unexported fields
}Server is an http.Handler serving one directory. Close releases it.
func New
func New(dir string, opts Options) (*Server, error)New returns a Server for dir, which must exist.
func (*Server) Close
func (s *Server) Close() errorClose closes the directory. Later requests fail.
func (*Server) ServeHTTP
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)ServeHTTP serves the file at r.URL.Path relative to the directory.