Skip to content

Commit 5d4cadc

Browse files
committed
Inline if statements and update README order
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent a5324bf commit 5d4cadc

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,31 +155,32 @@ Environmental variables:
155155

156156
> Note: timeouts should be specified as Golang durations i.e. `1m` or `20s`.
157157
158-
| Option |Usage|
159-
| ---------------------- |-----|
160-
| `fprocess` / `function_process` | Process to execute a server in `http` mode or to be executed for each request in the other modes. For non `http` mode the process must accept input via STDIN and print output via STDOUT. Also known as "function process". |
161-
| `mode` | The mode which of-watchdog operates in, Default `streaming` [see doc](#3-streaming-fork-modestreaming---default). Options are [http](#1-http-modehttp), [serialising fork](#2-serializing-fork-modeserializing), [streaming fork](#3-streaming-fork-modestreaming---default), [static](#4-static-modestatic) |
162-
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds) |
163-
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds) |
164-
| `exec_timeout` | Exec timeout for process exec'd for each incoming request (in seconds). Disabled if set to 0. |
165-
| `max_inflight` | Limit the maximum number of requests in flight, and return a HTTP status 429 when exceeded |
166-
| `prefix_logs` | When set to `true` the watchdog will add a prefix of "Date Time" + "stderr/stdout" to every line read from the function process. Default `true` |
167-
| `log_buffer_size` | The amount of bytes to read from stderr/stdout for log lines. When exceeded, the user will see an "bufio.Scanner: token too long" error. The default value is `bufio.MaxScanTokenSize` |
168-
| `healthcheck_interval` | Interval (in seconds) for HTTP healthcheck by container orchestrator i.e. kubelet. Used for graceful shutdowns. |
169-
| `port` | Specify an alternative TCP port for testing. Default: `8080` |
170-
| `content_type` | Force a specific Content-Type response for all responses - only in forking/serializing modes. |
171-
| `suppress_lock` | When set to `false` the watchdog will attempt to write a lockfile to `/tmp/.lock` for healthchecks. Default `false` |
172-
| `http_upstream_url` | `http` mode only - where to forward requests i.e. `127.0.0.1:5000` |
173-
| `upstream_url` | alias for `http_upstream_url` |
174-
| `http_buffer_req_body` | `http` mode only - buffers request body in memory before forwarding upstream to your template's `upstream_url`. Use if your upstream HTTP server does not accept `Transfer-Encoding: chunked`, for example WSGI tends to require this setting. Default: `false` |
175-
| `buffer_http` | deprecated alias for `http_buffer_req_body`, will be removed in future version |
176-
| `static_path` | Absolute or relative path to the directory that will be served if `mode="static"` |
177-
| `ready_path` | When non-empty, requests to `/_/ready` will invoke the function handler with this path. This can be used to provide custom readiness logic. When `max_inflight` is set, the concurrency limit is checked first before proxying the request to the function. |
158+
| Option | Usage|
159+
| -------------------------------- |---------------------------------------------------------------------|
160+
| `buffer_http` | (Deprecated) Alias for `http_buffer_req_body`, will be removed in future version |
161+
| `content_type` | Force a specific Content-Type response for all responses - only in forking/serializing modes. |
162+
| `exec_timeout` | Exec timeout for process exec'd for each incoming request (in seconds). Disabled if set to 0. |
163+
| `fprocess` / `function_process` | Process to execute a server in `http` mode or to be executed for each request in the other modes. For non `http` mode the process must accept input via STDIN and print output via STDOUT. Also known as "function process". |
164+
| `healthcheck_interval` | Interval (in seconds) for HTTP healthcheck by container orchestrator i.e. kubelet. Used for graceful shutdowns. |
165+
| `http_buffer_req_body` | `http` mode only - buffers request body in memory before forwarding upstream to your template's `upstream_url`. Use if your upstream HTTP server does not accept `Transfer-Encoding: chunked`, for example WSGI tends to require this setting. Default: `false` |
166+
| `http_upstream_url` | `http` mode only - where to forward requests i.e. `http://127.0.0.1:5000` |
167+
| `log_buffer_size` | The amount of bytes to read from stderr/stdout for log lines. When exceeded, the user will see an "bufio.Scanner: token too long" error. The default value is `bufio.MaxScanTokenSize` |
168+
| `max_inflight` | Limit the maximum number of requests in flight, and return a HTTP status 429 when exceeded |
169+
| `mode` | The mode which of-watchdog operates in, Default `streaming` [see doc](#3-streaming-fork-modestreaming---default). Options are [http](#1-http-modehttp), [serialising fork](#2-serializing-fork-modeserializing), [streaming fork](#3-streaming-fork-modestreaming---default), [static](#4-static-modestatic) |
170+
| `port` | Specify an alternative TCP port for testing. Default: `8080` |
171+
| `prefix_logs` | When set to `true` the watchdog will add a prefix of "Date Time" + "stderr/stdout" to every line read from the function process. Default `true` |
172+
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds) |
173+
| `ready_path` | When non-empty, requests to `/_/ready` will invoke the function handler with this path. This can be used to provide custom readiness logic. When `max_inflight` is set, the concurrency limit is checked first before proxying the request to the function. |
174+
| `static_path` | Absolute or relative path to the directory that will be served if `mode="static"` |
175+
| `suppress_lock` | When set to `false` the watchdog will attempt to write a lockfile to `/tmp/.lock` for healthchecks. Default `false` |
176+
| `upstream_url` | Alias for `http_upstream_url` |
177+
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds) |
178178

179179
Unsupported options from the [Classic Watchdog](https://github.com/openfaas/classic-watchdog):
180180

181-
| Option | Usage |
182-
| ------------- | --------------------------------------------------------------------------------------------- |
183-
| `write_debug` | In the classic watchdog, this prints the response body out to the console |
184-
| `read_debug` | In the classic watchdog, this prints the request body out to the console |
185-
| `combined_output` | In the classic watchdog, this returns STDOUT and STDERR in the function's HTTP response, when off it only returns STDOUT and prints STDERR to the logs of the watchdog |
181+
| Option | Usage |
182+
| -------------------- | --------------------------------------------------------------------------------------------- |
183+
| `write_debug` | In the classic watchdog, this prints the response body out to the console |
184+
| `read_debug` | In the classic watchdog, this prints the request body out to the console |
185+
| `combined_output` | In the classic watchdog, this returns STDOUT and STDERR in the function's HTTP response, when off it only returns STDOUT and prints STDERR to the logs of the watchdog |
186+

executor/http_runner.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211

1312
units "github.com/docker/go-units"
1413

@@ -98,7 +97,7 @@ func (f *HTTPFunctionRunner) Run(req FunctionRequest, contentLength int64, r *ht
9897

9998
var body io.Reader
10099
if f.BufferHTTPBody {
101-
reqBody, _ := ioutil.ReadAll(r.Body)
100+
reqBody, _ := io.ReadAll(r.Body)
102101
body = bytes.NewReader(reqBody)
103102
} else {
104103
body = r.Body
@@ -166,7 +165,7 @@ func (f *HTTPFunctionRunner) Run(req FunctionRequest, contentLength int64, r *ht
166165
if res.Body != nil {
167166
defer res.Body.Close()
168167

169-
bodyBytes, bodyErr := ioutil.ReadAll(res.Body)
168+
bodyBytes, bodyErr := io.ReadAll(res.Body)
170169
if bodyErr != nil {
171170
log.Println("read body err", bodyErr)
172171
}

executor/serializing_fork_runner.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"os"
1211

1312
units "github.com/docker/go-units"
@@ -91,7 +90,7 @@ func serializeFunction(req FunctionRequest, f *SerializingForkFunctionRunner) (*
9190
}
9291

9392
var err error
94-
data, err = ioutil.ReadAll(reader)
93+
data, err = io.ReadAll(reader)
9594

9695
if err != nil {
9796
return nil, err
@@ -148,7 +147,7 @@ func pipeToProcess(stdin io.WriteCloser, stdout io.Reader, data *[]byte) (*[]byt
148147

149148
go func(c chan error) {
150149
var err error
151-
result, err := ioutil.ReadAll(stdout)
150+
result, err := io.ReadAll(stdout)
152151
functionResult = &result
153152
if err != nil {
154153
c <- err

main.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"flag"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"log"
1312
"net/http"
1413
"net/url"
@@ -217,14 +216,12 @@ func createLockFile() (string, error) {
217216
path := filepath.Join(os.TempDir(), ".lock")
218217
log.Printf("Writing lock-file to: %s\n", path)
219218

220-
mkdirErr := os.MkdirAll(os.TempDir(), os.ModePerm)
221-
if mkdirErr != nil {
222-
return path, mkdirErr
219+
if err := os.MkdirAll(os.TempDir(), os.ModePerm); err != nil {
220+
return path, err
223221
}
224222

225-
writeErr := ioutil.WriteFile(path, []byte{}, 0660)
226-
if writeErr != nil {
227-
return path, writeErr
223+
if err := os.WriteFile(path, []byte{}, 0660); err != nil {
224+
return path, err
228225
}
229226

230227
atomic.StoreInt32(&acceptingConnections, 1)

0 commit comments

Comments
 (0)