Skip to content

Commit d1aa33f

Browse files
committed
Add example to README
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent c6c867d commit d1aa33f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ You can manage dependencies in one of the following ways:
3030
- You can also Go modules with vendoring, run `go mod vendor` in your function folder and add `--build-arg GO111MODULE=off --build-arg GOFLAGS='-mod=vendor'` to `faas-cli up`
3131
- If you have a private module dependency, we recommend using the vendoring technique from above.
3232

33+
## Adding static files to your image
34+
35+
Any folder named `static` will be copied into the final image published for your function.
36+
37+
To read this back at runtime, you can do the following:
38+
39+
```go
40+
package function
41+
42+
import (
43+
"io/ioutil"
44+
"net/http"
45+
)
46+
47+
func Handle(w http.ResponseWriter, r *http.Request) {
48+
49+
data, err := ioutil.ReadFile("./static/file.txt")
50+
51+
if err != nil {
52+
http.Error(w, err.Error(), http.StatusInternalServerError)
53+
}
54+
55+
w.Write(data)
56+
}
57+
```
58+
3359
## 1.0 golang-http
3460

3561
This template provides additional context and control over the HTTP response from your function.

0 commit comments

Comments
 (0)