github.com/mweagle/Sparta@v1.15.0/CONSTANTS_AWSBINARY.go (about)

     1  // +build lambdabinary
     2  
     3  //lint:file-ignore U1000,ST1018 Ignore all unused code, it's generated
     4  /* #nosec */
     5  // Code generated by "esc -o ./CONSTANTS_AWSBINARY.go -private -pkg sparta ./resources/awsbinary/README.md"; DO NOT EDIT.
     6  
     7  package sparta
     8  
     9  import (
    10  	"bytes"
    11  	"compress/gzip"
    12  	"encoding/base64"
    13  	"fmt"
    14  	"io"
    15  	"io/ioutil"
    16  	"net/http"
    17  	"os"
    18  	"path"
    19  	"sync"
    20  	"time"
    21  )
    22  
    23  type _escLocalFS struct{}
    24  
    25  var _escLocal _escLocalFS
    26  
    27  type _escStaticFS struct{}
    28  
    29  var _escStatic _escStaticFS
    30  
    31  type _escDirectory struct {
    32  	fs   http.FileSystem
    33  	name string
    34  }
    35  
    36  type _escFile struct {
    37  	compressed string
    38  	size       int64
    39  	modtime    int64
    40  	local      string
    41  	isDir      bool
    42  
    43  	once sync.Once
    44  	data []byte
    45  	name string
    46  }
    47  
    48  func (_escLocalFS) Open(name string) (http.File, error) {
    49  	f, present := _escData[path.Clean(name)]
    50  	if !present {
    51  		return nil, os.ErrNotExist
    52  	}
    53  	return os.Open(f.local)
    54  }
    55  
    56  func (_escStaticFS) prepare(name string) (*_escFile, error) {
    57  	f, present := _escData[path.Clean(name)]
    58  	if !present {
    59  		return nil, os.ErrNotExist
    60  	}
    61  	var err error
    62  	f.once.Do(func() {
    63  		f.name = path.Base(name)
    64  		if f.size == 0 {
    65  			return
    66  		}
    67  		var gr *gzip.Reader
    68  		b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed))
    69  		gr, err = gzip.NewReader(b64)
    70  		if err != nil {
    71  			return
    72  		}
    73  		f.data, err = ioutil.ReadAll(gr)
    74  	})
    75  	if err != nil {
    76  		return nil, err
    77  	}
    78  	return f, nil
    79  }
    80  
    81  func (fs _escStaticFS) Open(name string) (http.File, error) {
    82  	f, err := fs.prepare(name)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  	return f.File()
    87  }
    88  
    89  func (dir _escDirectory) Open(name string) (http.File, error) {
    90  	return dir.fs.Open(dir.name + name)
    91  }
    92  
    93  func (f *_escFile) File() (http.File, error) {
    94  	type httpFile struct {
    95  		*bytes.Reader
    96  		*_escFile
    97  	}
    98  	return &httpFile{
    99  		Reader:   bytes.NewReader(f.data),
   100  		_escFile: f,
   101  	}, nil
   102  }
   103  
   104  func (f *_escFile) Close() error {
   105  	return nil
   106  }
   107  
   108  func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) {
   109  	if !f.isDir {
   110  		return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name)
   111  	}
   112  
   113  	fis, ok := _escDirs[f.local]
   114  	if !ok {
   115  		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)
   116  	}
   117  	limit := count
   118  	if count <= 0 || limit > len(fis) {
   119  		limit = len(fis)
   120  	}
   121  
   122  	if len(fis) == 0 && count > 0 {
   123  		return nil, io.EOF
   124  	}
   125  
   126  	return fis[0:limit], nil
   127  }
   128  
   129  func (f *_escFile) Stat() (os.FileInfo, error) {
   130  	return f, nil
   131  }
   132  
   133  func (f *_escFile) Name() string {
   134  	return f.name
   135  }
   136  
   137  func (f *_escFile) Size() int64 {
   138  	return f.size
   139  }
   140  
   141  func (f *_escFile) Mode() os.FileMode {
   142  	return 0
   143  }
   144  
   145  func (f *_escFile) ModTime() time.Time {
   146  	return time.Unix(f.modtime, 0)
   147  }
   148  
   149  func (f *_escFile) IsDir() bool {
   150  	return f.isDir
   151  }
   152  
   153  func (f *_escFile) Sys() interface{} {
   154  	return f
   155  }
   156  
   157  // _escFS returns a http.Filesystem for the embedded assets. If useLocal is true,
   158  // the filesystem's contents are instead used.
   159  func _escFS(useLocal bool) http.FileSystem {
   160  	if useLocal {
   161  		return _escLocal
   162  	}
   163  	return _escStatic
   164  }
   165  
   166  // _escDir returns a http.Filesystem for the embedded assets on a given prefix dir.
   167  // If useLocal is true, the filesystem's contents are instead used.
   168  func _escDir(useLocal bool, name string) http.FileSystem {
   169  	if useLocal {
   170  		return _escDirectory{fs: _escLocal, name: name}
   171  	}
   172  	return _escDirectory{fs: _escStatic, name: name}
   173  }
   174  
   175  // _escFSByte returns the named file from the embedded assets. If useLocal is
   176  // true, the filesystem's contents are instead used.
   177  func _escFSByte(useLocal bool, name string) ([]byte, error) {
   178  	if useLocal {
   179  		f, err := _escLocal.Open(name)
   180  		if err != nil {
   181  			return nil, err
   182  		}
   183  		b, err := ioutil.ReadAll(f)
   184  		_ = f.Close()
   185  		return b, err
   186  	}
   187  	f, err := _escStatic.prepare(name)
   188  	if err != nil {
   189  		return nil, err
   190  	}
   191  	return f.data, nil
   192  }
   193  
   194  // _escFSMustByte is the same as _escFSByte, but panics if name is not present.
   195  func _escFSMustByte(useLocal bool, name string) []byte {
   196  	b, err := _escFSByte(useLocal, name)
   197  	if err != nil {
   198  		panic(err)
   199  	}
   200  	return b
   201  }
   202  
   203  // _escFSString is the string version of _escFSByte.
   204  func _escFSString(useLocal bool, name string) (string, error) {
   205  	b, err := _escFSByte(useLocal, name)
   206  	return string(b), err
   207  }
   208  
   209  // _escFSMustString is the string version of _escFSMustByte.
   210  func _escFSMustString(useLocal bool, name string) string {
   211  	return string(_escFSMustByte(useLocal, name))
   212  }
   213  
   214  var _escData = map[string]*_escFile{
   215  
   216  	"/resources/awsbinary/README.md": {
   217  		name:    "README.md",
   218  		local:   "./resources/awsbinary/README.md",
   219  		size:    184,
   220  		modtime: 1544981078,
   221  		compressed: `
   222  H4sIAAAAAAAC/yTMQWrDMBAF0L1O8aHr5g6hmwZadyFDl2UifxGBrBGaEcS3L8QHeO8NizpDWB/FkEsl
   223  ikFbPTCNG1yRBsUJAS29J927eLlX4uNniet1WeNf/Lx9xxO/UNaB62/El+z3TbCxVz12Nr/glnHohJEo
   224  HsTQZTg0Q5r6gwN8Mk0v2pC0OZ+OXinGs5eGYjZ5Cf8BAAD//13XMme4AAAA
   225  `,
   226  	},
   227  }
   228  
   229  var _escDirs = map[string][]os.FileInfo{}