aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/shurcooL/vfsgen/README.md
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-05-22 20:53:53 +0200
committerMichael Muré <batolettre@gmail.com>2019-05-22 20:53:53 +0200
commit485ca5900486b7fc3ea71cbcbb39b87272ae09fd (patch)
tree92551be8e01130542f969d06282abfc4a1c43629 /vendor/github.com/shurcooL/vfsgen/README.md
parente781d6c7fe7dba2fc526c2049aa188c9988e1cf4 (diff)
downloadgit-bug-485ca5900486b7fc3ea71cbcbb39b87272ae09fd.tar.gz
vendor: update dependencies
Diffstat (limited to 'vendor/github.com/shurcooL/vfsgen/README.md')
-rw-r--r--vendor/github.com/shurcooL/vfsgen/README.md31
1 files changed, 27 insertions, 4 deletions
diff --git a/vendor/github.com/shurcooL/vfsgen/README.md b/vendor/github.com/shurcooL/vfsgen/README.md
index a7781cb1..659a0a03 100644
--- a/vendor/github.com/shurcooL/vfsgen/README.md
+++ b/vendor/github.com/shurcooL/vfsgen/README.md
@@ -26,22 +26,43 @@ go get -u github.com/shurcooL/vfsgen
Usage
-----
-This code will generate an assets_vfsdata.go file with `var assets http.FileSystem = ...` that statically implements the contents of "assets" directory.
+Package `vfsgen` is a Go code generator library. It has a `Generate` function that takes an input filesystem (as a [`http.FileSystem`](https://godoc.org/net/http#FileSystem) type), and generates a Go code file that statically implements the contents of the input filesystem.
+
+For example, we can use [`http.Dir`](https://godoc.org/net/http#Dir) as a `http.FileSystem` implementation that uses the contents of the `/path/to/assets` directory:
```Go
-var fs http.FileSystem = http.Dir("assets")
+var fs http.FileSystem = http.Dir("/path/to/assets")
+```
+Now, when you execute the following code:
+
+```Go
err := vfsgen.Generate(fs, vfsgen.Options{})
if err != nil {
log.Fatalln(err)
}
```
+An assets_vfsdata.go file will be generated in the current directory:
+
+```Go
+// Code generated by vfsgen; DO NOT EDIT.
+
+package main
+
+import ...
+
+// assets statically implements the virtual filesystem provided to vfsgen.Generate.
+var assets http.FileSystem = ...
+```
+
Then, in your program, you can use `assets` as any other [`http.FileSystem`](https://godoc.org/net/http#FileSystem), for example:
```Go
file, err := assets.Open("/some/file.txt")
-if err != nil { ... }
+if err != nil {
+ return err
+}
defer file.Close()
```
@@ -49,6 +70,8 @@ defer file.Close()
http.Handle("/assets/", http.FileServer(assets))
```
+`vfsgen` can be more useful when combined with build tags and go generate directives. This is described below.
+
### `go generate` Usage
vfsgen is great to use with go generate directives. The code invoking `vfsgen.Generate` can go in an assets_generate.go file, which can then be invoked via "//go:generate go run assets_generate.go". The input virtual filesystem can read directly from disk, or it can be more involved.
@@ -175,4 +198,4 @@ This package was originally based on the excellent work by [@jteeuwen](https://g
License
-------
-- [MIT License](https://opensource.org/licenses/mit-license.php)
+- [MIT License](LICENSE)