forked from skycoin/skywire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
262 lines (225 loc) · 6.62 KB
/
static.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Code generated by "esc -o static.go -prefix static static"; DO NOT EDIT.
package main
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{
"/index.html": {
name: "index.html",
local: "static/index.html",
size: 5825,
modtime: 1589625972,
compressed: `
H4sIAAAAAAAC/7xYbW/juBH+nl8xqyxONi6WnWyS3smSi2u7xbW4vSuaA/phEVxoaWwRS5EqSSVxDf/3
gtS7LDm+LlDngyW+DJ955uHMOMG7WER6lyEkOmWri4vAfAMjfBs6yJ3VBUCQIInNA0CQoiYQJUQq1KGT
683sO2d1Ucxpqhmu/pwQDT9kWTAv3stJpXfmxTzbo2BfPJvPRnA925CUsp0PinA1UyjpZtlboeh/0Ifr
D9lrayYSTEgfLu/v78vRQ3EirEW8a58SU5UxsvNhw7BtIaV8liDdJtqH68XiOWnPEbml3IdFa2xNoi9b
KXIe+3B5e3d3fX/bO5m0j9X4qmcxRkISTQX3gQuOxw5QnqCkumcp7/DEqNIzS+SRlYzEMeXbLtI++sqq
p2iMayLPYce8zmIqMSrQR4LlKW8teKGxTny4uVl04lIDusZ0IFzff09u1n3ePIkRzShyPTOudiTC8NWH
6yPnZlpk7TPGTDHatlbuXQutRdqHKJ5Rbph48SGhcYwdXxOqcaYyEtkIvEiSLXuRbnYjYzRTVL2BjHgk
0vQZYV+RY09ZNhuihOi1eD1Nx/8cv1ok3ocODW2ZF4hac0LGKGeSxDRXPtzUka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IZjbkUJCIwrqXtdhASmRy8ioh+MLfHxGrh/syMSdK4Vun69iuSd46RqEUKgzXA1FojgjJppACH9/+OVn
LyNSWUF7ZrRvvtnT2N+DVr6F9xei8QoMK761WXa9V7ajLoeqfYflCV3U96r4no6trfNP67THImGNbD2M
3OZ+z4BsJB7tVI/s8+LRsyVpeU4Ord6Hk3c3LQ+tbQPuZ7IBwEelCZnV5liW/neOcvdg7Qr5A2MTt/qN
7E7rkmR/a4QrMN+evRI/UaU9ial4xkmVfI/qE7LWYhLHzcrl11zwEFz3ZGHqcvBYu5Gqbae2tjP5OOVN
6zOqD2v4hDI2qKOk9sa9gj2kqBMR++D+45eHX92r4j9ofnEdlU3TdLOb7Bvp+b3QXlW30bfHH6ZwmB7f
GE8nyCfSdCCDuaBK9RKVJ75Mx5acnwJMmajuvsW1HLf4e67+eZE+lQW6yqxDNSSnWgiATOEpUgxvxllT
Xg3T5tlQTRhKPXn6K6EMY9DC6qiJ2Pu9rRdP0zGQh+PhwfBGxCgLmyOxIqen6I6wXyiPxYtHsqysMaZB
nkyrn2x1Ax3Mi19qwbz4h/V/AwAA//9G17pUwRYAAA==
`,
},
"/": {
name: "/",
local: `static`,
isDir: true,
},
}
var _escDirs = map[string][]os.FileInfo{
"static": {
_escData["/index.html"],
},
}