Repository navigation
assets: add file system layer for zipped embed assets - #343
Conversation
be9b567 to
308b1e8
Compare
|
I'm not sure how I can keep building and testing this for go < 1.16. Any input welcome. |
10bde71 to
308b1e8
Compare
|
I'd create a separate module like we do for sigv4 |
308b1e8 to
0bbedfb
Compare
|
Thanks, I didn't think of that. |
|
@roidelapluie mind taking another look at this? |
|
@juliusv did you review this before merging into prometheus/prometheus? |
|
@roidelapluie Ah I did not. |
roidelapluie
left a comment
There was a problem hiding this comment.
Thanks.
It would be nice if exported function would have the interfaces they implement in comments.
| components and libraries. They are considered internal to Prometheus, without | ||
| any stability guarantees for external usage. | ||
|
|
||
| * **assets**: Embeding of static assets with gzip support |
There was a problem hiding this comment.
| * **assets**: Embeding of static assets with gzip support | |
| * **assets**: Embedding of static assets with gzip support |
| } | ||
|
|
||
| type File struct { | ||
| // the underlying file |
There was a problem hiding this comment.
| // the underlying file | |
| // The underlying file. |
| type File struct { | ||
| // the underlying file | ||
| file fs.File | ||
| // the decrompressed content, needed to return an accurate size |
There was a problem hiding this comment.
| // the decrompressed content, needed to return an accurate size | |
| // The decrompressed content, needed to return an accurate size. |
There was a problem hiding this comment.
It is not needed for this, it is used to read it.
| return FileInfo{stat, int64(len(f.content))}, nil | ||
| } | ||
|
|
||
| func (f *File) Read(buf []byte) (n int, err error) { |
There was a problem hiding this comment.
can we avoid the named return here? thanks
| ) | ||
|
|
||
| const ( | ||
| zipSuffix = ".gz" |
There was a problem hiding this comment.
| zipSuffix = ".gz" | |
| gzipSuffix = ".gz" |
| if err != nil { | ||
| return f, err | ||
| } | ||
| // and wrap everything in our custom File |
There was a problem hiding this comment.
| // and wrap everything in our custom File | |
| // Wrap everything in our custom File. |
| if err != nil { | ||
| return f, err | ||
| } | ||
| // read the (decompressed) content into a buffer |
There was a problem hiding this comment.
| // read the (decompressed) content into a buffer | |
| // Read the decompressed content into a buffer. |
| } | ||
|
|
||
| func (compressed FileSystem) Open(path string) (fs.File, error) { | ||
| // if we have the file in our embed FS, just return that (could be a |
There was a problem hiding this comment.
| // if we have the file in our embed FS, just return that (could be a | |
| // If we have the file in our embed FS, just return that (could be a |
|
|
||
| func (compressed FileSystem) Open(path string) (fs.File, error) { | ||
| // if we have the file in our embed FS, just return that (could be a | ||
| // dir) |
There was a problem hiding this comment.
| // dir) | |
| // dir.) |
let's have that comment in one line.
| if f, err := compressed.embed.Open(path); err == nil { | ||
| return f, nil | ||
| } | ||
| // try opening path with .gz suffix |
There was a problem hiding this comment.
This comment is not really needed
This commits adds an optional decompression layer to a embed.FS instance. If a file can't be found during Open, the filename plus a .gz ending is tried. If this succeeds, the content is decompressed and served. Signed-off-by: Jan Fajerski <[email protected]>
Since assets tests can only run on go1.16 and later the matrix style job list avoinds adding more conditionals to the job spec. Signed-off-by: Jan Fajerski <[email protected]>
0bbedfb to
50a67a2
Compare
|
Thank you @roidelapluie! PTAL. |
|
thanks! |
This commits adds an optional decompression layer to a embed.FS
instance. If a file can't be found during Open, the filename plus a .gz
ending is tried. If this succeeds, the content is decompressed and
served.
Signed-off-by: Jan Fajerski [email protected]
This was originally proposed in prometheus/prometheus#9380.