templates.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package main
  2. import (
  3. "bytes"
  4. "compress/gzip"
  5. "encoding/base64"
  6. "io/ioutil"
  7. "net/http"
  8. "os"
  9. "path"
  10. "sync"
  11. "time"
  12. )
  13. type _escLocalFS struct{}
  14. var _escLocal _escLocalFS
  15. type _escStaticFS struct{}
  16. var _escStatic _escStaticFS
  17. type _escDirectory struct {
  18. fs http.FileSystem
  19. name string
  20. }
  21. type _escFile struct {
  22. compressed string
  23. size int64
  24. modtime int64
  25. local string
  26. isDir bool
  27. once sync.Once
  28. data []byte
  29. name string
  30. }
  31. func (_escLocalFS) Open(name string) (http.File, error) {
  32. f, present := _escData[path.Clean(name)]
  33. if !present {
  34. return nil, os.ErrNotExist
  35. }
  36. return os.Open(f.local)
  37. }
  38. func (_escStaticFS) prepare(name string) (*_escFile, error) {
  39. f, present := _escData[path.Clean(name)]
  40. if !present {
  41. return nil, os.ErrNotExist
  42. }
  43. var err error
  44. f.once.Do(func() {
  45. f.name = path.Base(name)
  46. if f.size == 0 {
  47. return
  48. }
  49. var gr *gzip.Reader
  50. b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed))
  51. gr, err = gzip.NewReader(b64)
  52. if err != nil {
  53. return
  54. }
  55. f.data, err = ioutil.ReadAll(gr)
  56. })
  57. if err != nil {
  58. return nil, err
  59. }
  60. return f, nil
  61. }
  62. func (fs _escStaticFS) Open(name string) (http.File, error) {
  63. f, err := fs.prepare(name)
  64. if err != nil {
  65. return nil, err
  66. }
  67. return f.File()
  68. }
  69. func (dir _escDirectory) Open(name string) (http.File, error) {
  70. return dir.fs.Open(dir.name + name)
  71. }
  72. func (f *_escFile) File() (http.File, error) {
  73. type httpFile struct {
  74. *bytes.Reader
  75. *_escFile
  76. }
  77. return &httpFile{
  78. Reader: bytes.NewReader(f.data),
  79. _escFile: f,
  80. }, nil
  81. }
  82. func (f *_escFile) Close() error {
  83. return nil
  84. }
  85. func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) {
  86. return nil, nil
  87. }
  88. func (f *_escFile) Stat() (os.FileInfo, error) {
  89. return f, nil
  90. }
  91. func (f *_escFile) Name() string {
  92. return f.name
  93. }
  94. func (f *_escFile) Size() int64 {
  95. return f.size
  96. }
  97. func (f *_escFile) Mode() os.FileMode {
  98. return 0
  99. }
  100. func (f *_escFile) ModTime() time.Time {
  101. return time.Unix(f.modtime, 0)
  102. }
  103. func (f *_escFile) IsDir() bool {
  104. return f.isDir
  105. }
  106. func (f *_escFile) Sys() interface{} {
  107. return f
  108. }
  109. // FS returns a http.Filesystem for the embedded assets. If useLocal is true,
  110. // the filesystem's contents are instead used.
  111. func FS(useLocal bool) http.FileSystem {
  112. if useLocal {
  113. return _escLocal
  114. }
  115. return _escStatic
  116. }
  117. // Dir returns a http.Filesystem for the embedded assets on a given prefix dir.
  118. // If useLocal is true, the filesystem's contents are instead used.
  119. func Dir(useLocal bool, name string) http.FileSystem {
  120. if useLocal {
  121. return _escDirectory{fs: _escLocal, name: name}
  122. }
  123. return _escDirectory{fs: _escStatic, name: name}
  124. }
  125. // FSByte returns the named file from the embedded assets. If useLocal is
  126. // true, the filesystem's contents are instead used.
  127. func FSByte(useLocal bool, name string) ([]byte, error) {
  128. if useLocal {
  129. f, err := _escLocal.Open(name)
  130. if err != nil {
  131. return nil, err
  132. }
  133. b, err := ioutil.ReadAll(f)
  134. f.Close()
  135. return b, err
  136. }
  137. f, err := _escStatic.prepare(name)
  138. if err != nil {
  139. return nil, err
  140. }
  141. return f.data, nil
  142. }
  143. // FSMustByte is the same as FSByte, but panics if name is not present.
  144. func FSMustByte(useLocal bool, name string) []byte {
  145. b, err := FSByte(useLocal, name)
  146. if err != nil {
  147. panic(err)
  148. }
  149. return b
  150. }
  151. // FSString is the string version of FSByte.
  152. func FSString(useLocal bool, name string) (string, error) {
  153. b, err := FSByte(useLocal, name)
  154. return string(b), err
  155. }
  156. // FSMustString is the string version of FSMustByte.
  157. func FSMustString(useLocal bool, name string) string {
  158. return string(FSMustByte(useLocal, name))
  159. }
  160. var _escData = map[string]*_escFile{
  161. "/templates/status.html": {
  162. local: "templates/status.html",
  163. size: 3181,
  164. modtime: 1442049075,
  165. compressed: `
  166. H4sIAAAJbogA/7RXTY/bNhA9W7+CEJpbl4rSGKhTWpdskB7qdFO3PfRGiWOLqES65HidreD/XpD6sCxr
  167. Ha+KXCzpkW/IN/M0lFmOZZGwHLhIGEosIPkI+v7TmlQVoX+CsVIrcjyyqB4MWCHV3yQ3sFmGUaQAheI0
  168. 1RotGr7LhKKZLiM8SEQwd91A9Ib+QOMoszbqsLtMl6lUIGgpFc2sDYmBYhlafCrA5gAY3rqeBw4cs7xd
  169. CMy+AK5Oq11dxD8lwQwF/VcrULyE71FQlxYwpCIbrfDuAHKb4zuS6kL8RI4BixoaS7V4SoKACflIsoJb
  170. uwwzrZBLBSZ0A3mcfCx0ygsW5fFgptEHN2fWx+yOqx89OmPI0wLagfrB/96l2ggwIJrHTCsByoIIk2Dm
  171. eMZfZwxFy5Zqo0ktKmw2RCxytCxC0c1OYlJKdQ7NL6F4BFsBPyEsclsY7iX5vAcjYbBkVe2MVLgh4Sv6
  172. ZhMSWu+ONpPpbxwh9jZ8IWk+hRRPYjnxPV4t319dfb5tMX+WFvXW8HKQ19XVCnlk8frVAFhcAHQIrfiX
  173. c2CN4h4ev1b7xnP/fMUCIiSkS3Enja6kurUuPdJ5VW5kPWS4eE2m8RZTeVeJz+WEf3n5anWxyIVZz93K
  174. IiEfxzrT2//VmVpD9KzcuviPHcoSTpvyYmiN0nv+tEYj1fa07e4Vez7kQ8Fxo005DNriI8EuM9Bd8zj5
  175. SyvnXNfGJyXA75VhnrAI8/rO99s9wgmZN4jtTRrBnLfJ54d1g9Q1rCryHerdrzt0R/e7JaG/t0/Hoxs2
  176. XG2BEOqVEIe5BPbbSlMnQTJduIIv5+1oezqGLoefeAld/loHsbYkF51+1JsrQCMz+1yjv5kzn8CJp5DO
  177. +smI6A/u4+klyj8IZaeoH/JuFXOx3lTiaCac+zK9V2i99VruLzyFYu0+NZwb39cTejb1LqwqIjcd/Xis
  178. 3+wLY547M/Gh7fAtbm1+Fm1wjjYh3jov+yiNmqZF+F2OHOhVBUq4eO1No7qQMJT93mO36m4C3Cq8Dn5F
  179. eT/et5IedHenvnlqm/WHMYv8v4zgvwAAAP//sJ1SyW0MAAA=
  180. `,
  181. },
  182. "/": {
  183. isDir: true,
  184. local: "/",
  185. },
  186. "/templates": {
  187. isDir: true,
  188. local: "/templates",
  189. },
  190. }