mirror of
https://github.com/yudai/gotty.git
synced 2026-01-21 00:36:11 +01:00
switched to go-mod, updated codegangsta/cli -> urfave/cli
This commit is contained in:
parent
a080c85cbc
commit
f0fe6d57fd
466 changed files with 248599 additions and 5024 deletions
2
vendor/github.com/elazarl/go-bindata-assetfs/README.md
generated
vendored
2
vendor/github.com/elazarl/go-bindata-assetfs/README.md
generated
vendored
|
|
@ -41,6 +41,6 @@ use
|
|||
...
|
||||
http.Handle("/",
|
||||
http.FileServer(
|
||||
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "data"}))
|
||||
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "data"}))
|
||||
|
||||
to serve files embedded from the `data` directory.
|
||||
|
|
|
|||
34
vendor/github.com/elazarl/go-bindata-assetfs/assetfs.go
generated
vendored
34
vendor/github.com/elazarl/go-bindata-assetfs/assetfs.go
generated
vendored
|
|
@ -9,11 +9,12 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
fileTimestamp = time.Now()
|
||||
defaultFileTimestamp = time.Now()
|
||||
)
|
||||
|
||||
// FakeFile implements os.FileInfo interface for a given path and size
|
||||
|
|
@ -24,6 +25,8 @@ type FakeFile struct {
|
|||
Dir bool
|
||||
// Len is the length of the fake file, zero if it is a directory
|
||||
Len int64
|
||||
// Timestamp is the ModTime of this file
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (f *FakeFile) Name() string {
|
||||
|
|
@ -40,7 +43,7 @@ func (f *FakeFile) Mode() os.FileMode {
|
|||
}
|
||||
|
||||
func (f *FakeFile) ModTime() time.Time {
|
||||
return fileTimestamp
|
||||
return f.Timestamp
|
||||
}
|
||||
|
||||
func (f *FakeFile) Size() int64 {
|
||||
|
|
@ -62,11 +65,14 @@ type AssetFile struct {
|
|||
FakeFile
|
||||
}
|
||||
|
||||
func NewAssetFile(name string, content []byte) *AssetFile {
|
||||
func NewAssetFile(name string, content []byte, timestamp time.Time) *AssetFile {
|
||||
if timestamp.IsZero() {
|
||||
timestamp = defaultFileTimestamp
|
||||
}
|
||||
return &AssetFile{
|
||||
bytes.NewReader(content),
|
||||
ioutil.NopCloser(nil),
|
||||
FakeFile{name, false, int64(len(content))}}
|
||||
FakeFile{name, false, int64(len(content)), timestamp}}
|
||||
}
|
||||
|
||||
func (f *AssetFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
|
|
@ -92,13 +98,13 @@ func NewAssetDirectory(name string, children []string, fs *AssetFS) *AssetDirect
|
|||
fileinfos := make([]os.FileInfo, 0, len(children))
|
||||
for _, child := range children {
|
||||
_, err := fs.AssetDir(filepath.Join(name, child))
|
||||
fileinfos = append(fileinfos, &FakeFile{child, err == nil, 0})
|
||||
fileinfos = append(fileinfos, &FakeFile{child, err == nil, 0, time.Time{}})
|
||||
}
|
||||
return &AssetDirectory{
|
||||
AssetFile{
|
||||
bytes.NewReader(nil),
|
||||
ioutil.NopCloser(nil),
|
||||
FakeFile{name, true, 0},
|
||||
FakeFile{name, true, 0, time.Time{}},
|
||||
},
|
||||
0,
|
||||
fileinfos}
|
||||
|
|
@ -127,6 +133,8 @@ type AssetFS struct {
|
|||
Asset func(path string) ([]byte, error)
|
||||
// AssetDir should return list of files in the path
|
||||
AssetDir func(path string) ([]string, error)
|
||||
// AssetInfo should return the info of file in path if exists
|
||||
AssetInfo func(path string) (os.FileInfo, error)
|
||||
// Prefix would be prepended to http requests
|
||||
Prefix string
|
||||
}
|
||||
|
|
@ -137,11 +145,23 @@ func (fs *AssetFS) Open(name string) (http.File, error) {
|
|||
name = name[1:]
|
||||
}
|
||||
if b, err := fs.Asset(name); err == nil {
|
||||
return NewAssetFile(name, b), nil
|
||||
timestamp := defaultFileTimestamp
|
||||
if fs.AssetInfo != nil {
|
||||
if info, err := fs.AssetInfo(name); err == nil {
|
||||
timestamp = info.ModTime()
|
||||
}
|
||||
}
|
||||
return NewAssetFile(name, b, timestamp), nil
|
||||
}
|
||||
if children, err := fs.AssetDir(name); err == nil {
|
||||
return NewAssetDirectory(name, children, fs), nil
|
||||
} else {
|
||||
// If the error is not found, return an error that will
|
||||
// result in a 404 error. Otherwise the server returns
|
||||
// a 500 error for files not found.
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue