83b90e4199
* use vfsgen instead of go-bindata * fix templates * fix fmt * vendor vsfgen
39 lines
916 B
Go
39 lines
916 B
Go
// Package vfsutil implements some I/O utility functions for http.FileSystem.
|
|
package vfsutil
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// ReadDir reads the contents of the directory associated with file and
|
|
// returns a slice of FileInfo values in directory order.
|
|
func ReadDir(fs http.FileSystem, name string) ([]os.FileInfo, error) {
|
|
f, err := fs.Open(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
return f.Readdir(0)
|
|
}
|
|
|
|
// Stat returns the FileInfo structure describing file.
|
|
func Stat(fs http.FileSystem, name string) (os.FileInfo, error) {
|
|
f, err := fs.Open(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
return f.Stat()
|
|
}
|
|
|
|
// ReadFile reads the file named by path from fs and returns the contents.
|
|
func ReadFile(fs http.FileSystem, path string) ([]byte, error) {
|
|
rc, err := fs.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rc.Close()
|
|
return ioutil.ReadAll(rc)
|
|
}
|