From 3b188ebfb7f98d3d4ecb19e925f07bfc0c117967 Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Wed, 6 May 2020 14:07:06 +0200 Subject: [PATCH] commit static.go for use by libraries --- resources/static.go | 276 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 resources/static.go diff --git a/resources/static.go b/resources/static.go new file mode 100644 index 0000000..7e3693a --- /dev/null +++ b/resources/static.go @@ -0,0 +1,276 @@ +// Code generated by "esc --prefix resources/ --ignore static.go -o resources/static.go --pkg resources resources"; DO NOT EDIT. + +package resources + +import ( + "bytes" + "compress/gzip" + "encoding/base64" + "fmt" + "io" + "io/ioutil" + "net/http" + "os" + "path" + "sync" + "time" +) + +type _escLocalFS struct{} + +var _escLocal _escLocalFS + +type _escStaticFS struct{} + +var _escStatic _escStaticFS + +type _escDirectory struct { + fs http.FileSystem + name string +} + +type _escFile struct { + compressed string + size int64 + modtime int64 + local string + isDir bool + + once sync.Once + data []byte + name string +} + +func (_escLocalFS) Open(name string) (http.File, error) { + f, present := _escData[path.Clean(name)] + if !present { + return nil, os.ErrNotExist + } + return os.Open(f.local) +} + +func (_escStaticFS) prepare(name string) (*_escFile, error) { + f, present := _escData[path.Clean(name)] + if !present { + return nil, os.ErrNotExist + } + var err error + f.once.Do(func() { + f.name = path.Base(name) + if f.size == 0 { + return + } + var gr *gzip.Reader + b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed)) + gr, err = gzip.NewReader(b64) + if err != nil { + return + } + f.data, err = ioutil.ReadAll(gr) + }) + if err != nil { + return nil, err + } + return f, nil +} + +func (fs _escStaticFS) Open(name string) (http.File, error) { + f, err := fs.prepare(name) + if err != nil { + return nil, err + } + return f.File() +} + +func (dir _escDirectory) Open(name string) (http.File, error) { + return dir.fs.Open(dir.name + name) +} + +func (f *_escFile) File() (http.File, error) { + type httpFile struct { + *bytes.Reader + *_escFile + } + return &httpFile{ + Reader: bytes.NewReader(f.data), + _escFile: f, + }, nil +} + +func (f *_escFile) Close() error { + return nil +} + +func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) { + if !f.isDir { + return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name) + } + + fis, ok := _escDirs[f.local] + if !ok { + return nil, fmt.Errorf(" escFile.Readdir: '%s' is directory, but we have no info about content of this dir, local=%s", f.name, f.local) + } + limit := count + if count <= 0 || limit > len(fis) { + limit = len(fis) + } + + if len(fis) == 0 && count > 0 { + return nil, io.EOF + } + + return fis[0:limit], nil +} + +func (f *_escFile) Stat() (os.FileInfo, error) { + return f, nil +} + +func (f *_escFile) Name() string { + return f.name +} + +func (f *_escFile) Size() int64 { + return f.size +} + +func (f *_escFile) Mode() os.FileMode { + return 0 +} + +func (f *_escFile) ModTime() time.Time { + return time.Unix(f.modtime, 0) +} + +func (f *_escFile) IsDir() bool { + return f.isDir +} + +func (f *_escFile) Sys() interface{} { + return f +} + +// FS returns a http.Filesystem for the embedded assets. If useLocal is true, +// the filesystem's contents are instead used. +func FS(useLocal bool) http.FileSystem { + if useLocal { + return _escLocal + } + return _escStatic +} + +// Dir returns a http.Filesystem for the embedded assets on a given prefix dir. +// If useLocal is true, the filesystem's contents are instead used. +func Dir(useLocal bool, name string) http.FileSystem { + if useLocal { + return _escDirectory{fs: _escLocal, name: name} + } + return _escDirectory{fs: _escStatic, name: name} +} + +// FSByte returns the named file from the embedded assets. If useLocal is +// true, the filesystem's contents are instead used. +func FSByte(useLocal bool, name string) ([]byte, error) { + if useLocal { + f, err := _escLocal.Open(name) + if err != nil { + return nil, err + } + b, err := ioutil.ReadAll(f) + _ = f.Close() + return b, err + } + f, err := _escStatic.prepare(name) + if err != nil { + return nil, err + } + return f.data, nil +} + +// FSMustByte is the same as FSByte, but panics if name is not present. +func FSMustByte(useLocal bool, name string) []byte { + b, err := FSByte(useLocal, name) + if err != nil { + panic(err) + } + return b +} + +// FSString is the string version of FSByte. +func FSString(useLocal bool, name string) (string, error) { + b, err := FSByte(useLocal, name) + return string(b), err +} + +// FSMustString is the string version of FSMustByte. +func FSMustString(useLocal bool, name string) string { + return string(FSMustByte(useLocal, name)) +} + +var _escData = map[string]*_escFile{ + + "/const.go": { + name: "const.go", + local: "resources/const.go", + size: 144, + modtime: 1588452571, + compressed: ` +H4sIAAAAAAAC/ypITM5OTE9VKEotzi8tSk4t5uIqSyxScM7PK0nMzEstSglOLSrLTE5VsFVwC/YtLS4J +LinKzEvXSEvMKU7VUVDST4ar1CuGKFXSBBvhXZqUmpNa4pyfl4ZTc3ZpUmpiSi6STkAAAAD//31F8UGQ +AAAA +`, + }, + + "/containerd.service": { + name: "containerd.service", + local: "resources/containerd.service", + size: 1421, + modtime: 1588452571, + compressed: ` +H4sIAAAAAAAC/7xUwW7cNhC98ysG0aFA0ZVaoGnrADoksYsGjbuGnSIHwweKHK2mpjgCZ2h7+/UFufau +UPhY9CSJmnnz5r0Hmts/I+mdaeBGbVJwHNVSxOTBCgSrWJ4Li9AQEB5JJ0goCzoFZXCBs99QJP1GTAMD +s4Ko3aG08GUiAYySEwroZHVVDTP7HFBAspvAlt7HRIqbkcrpbPcwIGRBX6dwHGmXE67pLYk4lb+kpilD +k1LctaYxDVwFtIIgiKATwsgh8CPFHQSK9zBygpkTAsWR02yVOIIdOGupNs2a52kjmG20O/Qw7CvooehA +rRVMD+TwnWlgUl3kXdfV/wWjTWi9TujZSUvcYeyKrqKd8kJOujKjnXQOzQHNmAYuqm7rfUkOSxYGOBb6 +Jxb/omqag974hC5rVR8h5ehm/yz8szuHjwJdPOVYTTZNVSjlGItkb+7zgNbPUIa8+Q5s9KBTljW3OYvC +gC8+rClSKZzn0kUCS2KHIuj/b59Gijb8VzZVMPN+VEz9icMLuvlQd+9fC4j5aqPKa03nKC7RUnbsV8oe +X4sfSjOac3Z5xqhVjv64xrGlJTbm9lMUtSHc1YHoP+xfp2Nubw5vd6a5eEJXL4GrhH0nA8VuZr8kHhD4 +AVOwe3Os6bssqQvsbOhK5Wm+ucYagt6GR7uXl88bdP1bc44Bd1ax36OY3ymES/bYP6fCbLeXN44Tvvd/ +ZdF+c3Z2Zj7TTPrH9tdPny/6H77/8Ze3P/9kGvjNPpSYRI6bvzEx1KpvBZzNggILppqY6LBEbgg4C/iM +5bqwznGRMu7qVhNabxqgWMNyjyliaOErQsKSW4wespRit0ucFykQnk++bKoGK9T2mfLV9fZjT3EsLu8P +Zx+31xenoy9W7uXSPp1O/gkAAP//LPoJ6o0FAAA= +`, + }, + + "/kubeadm.service": { + name: "kubeadm.service", + local: "resources/kubeadm.service", + size: 900, + modtime: 1588452571, + compressed: ` +H4sIAAAAAAAC/3xSUW+bQAx+51dYtG8roLxOykO20Wrqlk1JJk2apsqAIW6Pu8hnaPn300FpEzXdE8b3 ++fPnz76AtVP6CLs9e6jEHdiCs2aARycPHh5Z9/DQFYRVC2irMTak0C/SxeJD9GdL0nNJf6Pc9izOtmR1 +Gd/++pR/y3d34fv5x/r6683danOzXSZJ4Zx6FTwkgal0tuZmmZGWWfgXS0o+OwUZ0jQAIflfzTEyPq/m +VMnM06NkhouZIJvy6YCtiaOLyRj2gFCzIdA9KsSzI2xZ49GXl9S9YxtDQ5YElTyggnRWuaUrOLhDZ1DZ +NqB7gmOXVl++j8KgR2EsDEE1WGy5RGOG43Gu2dAyeaP6uX1SG2x8SrZ/R3ro23kSKNGGAGon4HoS4Yo8 +uHpEzFtGaTxgYDDoFYS8E03hp1BNgoUZrl4J/d51pgpxdDFm07WraEMNh1UqO5veTrT5kwquArUr7qlU +YDsWTM53E3jU7IGtV8IqfTEr/73brCarnjsWBN51UlIFtbgWNIwdqtMzvoWr8YOfWs3uRfkTlVtF0eVR +mHVesoLtjILLd8769eFs8mS9l2/niP4FAAD//8ugzaeEAwAA +`, + }, + + "/resources": { + name: "resources", + local: `resources`, + isDir: true, + }, +} + +var _escDirs = map[string][]os.FileInfo{ + + "resources": { + _escData["/const.go"], + _escData["/containerd.service"], + _escData["/kubeadm.service"], + }, +}