You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes: #33
Go sub-modules do not work with this template, because the of
limitations on how local imports and the "replace" word works
in Go modules. You can only use "replace" in the root-level module
i.e. "main.go"
https://github.com/golang/go/wiki/Modules#gomod
This patch was tested with the following repo:
[email protected]:alexellis/golang-middleware-relative-import.git
* Documentation in the README has been updated
* Tested e2e and with a local "go test" in GOPATH with modules
turned on and Go 1.13
* Updated copy commands in Dockerfile so that they use a faster
mechanism, vs creating a new container step to chown (must be
tested with buildkit before merging, since buildkit did not like
this approach in the past when running as a restricted user at
runtime)
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -299,3 +299,53 @@ func Handle(w http.ResponseWriter, r *http.Request) {
299
299
w.Write([]byte(result))
300
300
}
301
301
```
302
+
303
+
#### Advanced usage - Go sub-modules via `GO_REPLACE.txt`
304
+
305
+
For this example you will need to be using Go 1.13 or newer and Go modules, enable this via `faas-cli build --build-arg GO111MODULE=on`.
306
+
307
+
Imagine you have a package which you want to store outside of the `handler.go` file, it's another middleware which can perform an echo.
308
+
309
+
```Golang
310
+
package handlers
311
+
312
+
import (
313
+
"io/ioutil"
314
+
"net/http"
315
+
)
316
+
317
+
funcEcho(whttp.ResponseWriter, r *http.Request) {
318
+
319
+
if r.Body != nil {
320
+
defer r.Body.Close()
321
+
b, _:= ioutil.ReadAll(r.Body)
322
+
w.Write(b)
323
+
}
324
+
325
+
}
326
+
```
327
+
328
+
To include a relative module such as this new `handlers` package, you should create a `GO_REPLACE.txt` file as follows.
329
+
330
+
Let's say your GOPATH for your GitHub repo is: `github.com/alexellis/vault/` and your function is called `purchase`, this makes a total path of: `github.com/alexellis/vault/purchase/`
0 commit comments