Skip to content

Commit

Permalink
Update ordering of GO_REPLACE statements
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 24, 2020
1 parent 8bb365f commit 23db8b3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions README.md
Expand Up @@ -304,7 +304,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {

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`.

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.
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 of the user's input.

```Golang
package handlers
Expand All @@ -315,26 +315,25 @@ import (
)

func Echo(w http.ResponseWriter, r *http.Request) {

if r.Body != nil {
defer r.Body.Close()
b, _ := ioutil.ReadAll(r.Body)
w.Write(b)
}

}
```

To include a relative module such as this new `handlers` package, you should create a `GO_REPLACE.txt` file as follows.

Let's say your GOPATH for your GitHub repo is: `github.com/alexellis/vault/` and your OpenFaaS function is `purchase` generated by `faas-cli new purchase --lang golang-middleware`.

Your relative GOPATH is: `github.com/alexellis/vault/purchase`, so add a redirect as per below to redirect the "handlers" package to where it exists in the build container.
To include a relative module such as this new `handlers` package, you should create a `GO_REPLACE.txt` file as follows:

```
replace github.com/alexellis/vault/purchase/handlers => ./function/handlers
```

How did we get to that? Let's say your GOPATH for your GitHub repo is: `github.com/alexellis/vault/` and your OpenFaaS function is `purchase` generated by `faas-cli new purchase --lang golang-middleware`.

Your relative GOPATH is: `github.com/alexellis/vault/purchase`, so add a redirect as per below to redirect the "handlers" package to where it exists in the build container.


Now if you want to reference the handlers package from within your `handler.go` write the following:

```golang
Expand Down

0 comments on commit 23db8b3

Please sign in to comment.