Skip to content

Commit 1e91dec

Browse files
LucasRoesleralexellis
authored andcommitted
docs: update the readme to reflect the go1.18 changes
Update the sections that discuss dependencies and sub-packages Signed-off-by: Lucas Roesler <[email protected]>
1 parent 193d979 commit 1e91dec

File tree

1 file changed

+6
-57
lines changed

1 file changed

+6
-57
lines changed

README.md

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
OpenFaaS Golang HTTP templates
2-
=============================================
1+
# OpenFaaS Golang HTTP templates
32

43
This repository contains two Golang templates for OpenFaaS which give additional control over the HTTP request and response. They will both handle higher throughput than the classic watchdog due to the process being kept warm.
54

@@ -27,8 +26,9 @@ The two templates are equivalent with `golang-http` using a structured request/r
2726

2827
You can manage dependencies in one of the following ways:
2928

30-
* To use Go modules without vendoring, the default already is set `GO111MODULE=on` but you also can make that explicit by adding `--build-arg GO111MODULE=on` to `faas-cli up`, you can also use `--build-arg GOPROXY=https://` if you want to use your own mirror for the modules
31-
* You can also Go modules with vendoring, run `go mod vendor` in your function folder and add `--build-arg GO111MODULE=off` to `faas-cli up`
29+
- To use Go modules without vendoring, the default already is set `GO111MODULE=on` but you also can make that explicit by adding `--build-arg GO111MODULE=on` to `faas-cli up`, you can also use `--build-arg GOPROXY=https://` if you want to use your own mirror for the modules
30+
- 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`
31+
- If you have a private module dependency, we recommend using the vendoring technique from above.
3232

3333
## 1.0 golang-http
3434

@@ -182,7 +182,6 @@ func Handle(req handler.Request) (handler.Response, error) {
182182

183183
This context can also be passed to other methods so that they can respond to the cancellation as well, for example [`db.ExecContext(req.Context())`](https://golang.org/pkg/database/sql/#DB.ExecContext)
184184

185-
186185
## 2.0 golang-middleware
187186

188187
This template uses the [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc) as entry point.
@@ -377,64 +376,14 @@ It is often natural to organize your code into sub-packages, for example you may
377376
└── version.go
378377
```
379378

380-
First update your go.mod file to replace `handler/function` with your local folder
381-
382-
```go
383-
go mod edit -replace=handler/function=./
384-
```
385-
386379
Now if you want to reference the`version` sub-package, import it as
387380

388381
```go
389382
import "handler/function/pkg/version"
390383
```
391384

392-
This replacement is handled gracefully by the template at build time and your local development environment will now recognize the sub-package.
385+
This works like any local Go project.
393386

394387
##### Go sub-modules
395388

396-
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.
397-
398-
```Golang
399-
package handlers
400-
401-
import (
402-
"io"
403-
"net/http"
404-
)
405-
406-
func Echo(w http.ResponseWriter, r *http.Request) {
407-
if r.Body != nil {
408-
defer r.Body.Close()
409-
b, _ := io.ReadAll(r.Body)
410-
w.Write(b)
411-
}
412-
}
413-
```
414-
415-
To include a relative module such as this new `handlers` package, you should update your `go.mod` file as follows:
416-
417-
```
418-
go mod edit -replace=github.com/alexellis/vault/purchase/handlers=./handlers
419-
```
420-
421-
At build time, this relative path will be handled correctly inside the template.
422-
423-
Now if you want to reference the handlers package from within your `handler.go` write the following:
424-
425-
```golang
426-
package function
427-
428-
import (
429-
"net/http"
430-
431-
"github.com/alexellis/vault/purchase/handlers"
432-
)
433-
434-
func Handle(w http.ResponseWriter, r *http.Request) {
435-
436-
handlers.Echo(w, r)
437-
}
438-
```
439-
440-
If you have any vendor private dependency, you can disable the Go module via `faas-cli build --build-arg GO111MODULE=off`.
389+
Sub-modules (meaning sub-folders with a `go.mod`) are not supported.

0 commit comments

Comments
 (0)