-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathrun.go
More file actions
77 lines (66 loc) · 2.28 KB
/
Copy pathrun.go
File metadata and controls
77 lines (66 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2025 Tetrate
// SPDX-License-Identifier: Apache-2.0
// Package api allows Go projects to use func-e as a library, decoupled from how
// the func-e binary reads environment variables or CLI args.
package api
import (
"context"
"io"
"github.com/tetratelabs/func-e/internal/opts"
)
// HomeDir is an absolute path which most importantly contains "versions"
// installed from EnvoyVersionsURL. Defaults to "${HOME}/.func-e"
func HomeDir(homeDir string) RunOption {
return func(o *opts.RunOpts) {
o.HomeDir = homeDir
}
}
// EnvoyVersionsURL is the path to the envoy-versions.json.
// Defaults to "https://archive.tetratelabs.io/envoy/envoy-versions.json"
func EnvoyVersionsURL(envoyVersionsURL string) RunOption {
return func(o *opts.RunOpts) {
o.EnvoyVersionsURL = envoyVersionsURL
}
}
// EnvoyVersion overrides the version of Envoy to run. Defaults to the
// contents of "$HomeDir/versions/version".
//
// When that file is missing, it is generated from ".latestVersion" from the
// EnvoyVersionsURL. Its value can be in full version major.minor.patch format,
// e.g. 1.18.1 or without patch component, major.minor, e.g. 1.18.
func EnvoyVersion(envoyVersion string) RunOption {
return func(o *opts.RunOpts) {
o.EnvoyVersion = envoyVersion
}
}
// Out is where status messages are written. Defaults to os.Stdout
func Out(out io.Writer) RunOption {
return func(o *opts.RunOpts) {
o.Out = out
}
}
// EnvoyOut sets the writer for Envoy stdout
func EnvoyOut(w io.Writer) RunOption {
return func(o *opts.RunOpts) {
o.EnvoyOut = w
}
}
// EnvoyErr sets the writer for Envoy stderr
func EnvoyErr(w io.Writer) RunOption {
return func(o *opts.RunOpts) {
o.EnvoyErr = w
}
}
// RunOption is a configuration for RunFunc.
//
// Note: None of these default to values read from OS environment variables.
// If you wish to introduce such behavior, populate them in calling code.
type RunOption func(*opts.RunOpts)
// RunFunc downloads Envoy and runs it as a process with the arguments
// passed to it. Use api.RunOption for configuration options.
//
// On success, this blocks and returns nil when either `ctx` is done, or the
// process exits with status zero.
//
// The default implementation of RunFunc is func_e.Run.
type RunFunc func(ctx context.Context, args []string, options ...RunOption) error