Skip to content

Commit e9fa173

Browse files
authored
Kick off experimental Go SDK (#26)
Contributes to #25 --------- Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
1 parent 0853728 commit e9fa173

16 files changed

Lines changed: 2070 additions & 23 deletions

File tree

.github/workflows/commit.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,42 @@ jobs:
6161
- name: Run tests
6262
run: cargo test --verbose
6363

64+
go:
65+
name: Go Build and Test (${{ matrix.platform.arch }})
66+
runs-on: ${{ matrix.platform.os }}
67+
defaults:
68+
run:
69+
working-directory: ./go
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
platform:
74+
- os: ubuntu-22.04
75+
arch: amd64
76+
- os: ubuntu-22.04-arm
77+
arch: arm64
78+
79+
steps:
80+
- name: Checkout repository
81+
uses: actions/checkout@v4
82+
83+
- uses: actions/setup-go@v5
84+
with:
85+
cache: false
86+
go-version-file: go/go.mod
87+
88+
- uses: actions/cache@v4
89+
with:
90+
path: |
91+
~/.cache/go-build
92+
~/go/pkg/mod
93+
~/go/bin
94+
key: go-test-${{ hashFiles('**/go.mod', '**/go.sum') }}
95+
96+
- run: go test ./... -v
97+
- run: go build -buildmode=c-shared -o main.so
98+
- run: go tool golangci-lint run
99+
64100
docker_build:
65101
name: Build and Push multi-arch Docker image
66102
runs-on: ubuntu-latest

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ target/
44
bazel-out/
55
bazel-*
66

7-
access_logs/
7+
access_logs/
8+
9+
*.so

Dockerfile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# This is the example Dockerfile for building the multi arch Envoy image with the Rust dynamic module.
1+
# This is the example Dockerfile for building the multi arch Envoy image with the Rust and Go dynamic module.
2+
3+
##### Build the Rust library #####
24

35
# Use https://github.com/rust-cross/cargo-zigbuild to cross-compile the Rust library for both x86_64 and aarch64 architectures.
46
# We need it because bindgen relies on the sysroot of the target architecture which makes it
@@ -27,8 +29,25 @@ RUN cargo zigbuild --target x86_64-unknown-linux-gnu
2729
RUN cp /build/target/aarch64-unknown-linux-gnu/debug/librust_module.so /build/arm64_librust_module.so
2830
RUN cp /build/target/x86_64-unknown-linux-gnu/debug/librust_module.so /build/amd64_librust_module.so
2931

30-
# Finally, copy the built library to the final image.
31-
FROM envoyproxy/envoy-dev:a27d2c31627e59f096f7c8cdc84488649158b000 AS envoy
32+
##### Build the Go library #####
33+
34+
# We use zig to cross-compile the Go library for both x86_64 and aarch64 architectures.
35+
FROM --platform=$BUILDPLATFORM golang:1.24.2 AS go_builder
36+
# Install zig.
37+
ARG ZIG_VERSION=0.14.0
38+
RUN apt update && apt install -y curl xz-utils
39+
RUN curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \
40+
ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
41+
# Build the Go library.
42+
RUN mkdir /build
43+
COPY ./go /build
44+
WORKDIR /build
45+
RUN CC="zig cc -target aarch64-linux-gnu" CXX="zig c++ -target aarch64-linux-gnu" CGO_ENABLED=1 GOARCH=arm64 go build -buildmode=c-shared -o /build/arm64_libgo_module.so .
46+
RUN CC="zig cc -target x86_64-linux-gnu" CXX="zig c++ -target x86_64-linux-gnu" CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o /build/amd64_libgo_module.so .
47+
48+
##### Build the final image #####
49+
FROM envoyproxy/envoy-dev:5b88f941da971de57f29286103c20770811ec67f AS envoy
3250
ARG TARGETARCH
3351
ENV ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/usr/local/lib
3452
COPY --from=rust_builder /build/${TARGETARCH}_librust_module.so /usr/local/lib/librust_module.so
53+
COPY --from=go_builder /build/${TARGETARCH}_libgo_module.so /usr/local/lib/libgo_module.so

ENVOY_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a27d2c31627e59f096f7c8cdc84488649158b000
1+
5b88f941da971de57f29286103c20770811ec67f

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dynamic Modules Examples
22

3-
> Envoy Version: [a27d2c31627e59f096f7c8cdc84488649158b000]
3+
> Envoy Version: [5b88f941da971de57f29286103c20770811ec67f] v1.34
44
55
This repository hosts examples of dynamic modules for [Envoy] to extend its functionality.
66
The high level documentation is available [here][High Level Doc]. In short, a dynamic module is a shared library
@@ -9,8 +9,12 @@ that can be loaded into Envoy at runtime to add custom functionality, for exampl
99
It is a new way to extend Envoy without the need to recompile it just like the existing mechanisms
1010
like Lua filters, Wasm filters, or External Processors.
1111

12-
Currently, the only language supported is Rust, so this repository contains examples of dynamic modules written in Rust.
13-
Future examples will be added in other languages once the support is available.
12+
As of writing, the only official language supported by Envoy is Rust. However, the dynamic module's interface is defined in a plain
13+
C header file, so technically you can implement a dynamic module in any language that can build shared libraries, such as C, C++, Go, Zig, etc.
14+
Currently, this repository hosts two language implementations of dynamic modules: Rust and C++.
15+
* [`rust`](rust): using the official Rust dynamic module SDK.
16+
* [`go`](go): using the experimental Go dynamic module SDK implemented here. WARNING: This is not an official SDK and is not
17+
supported by Envoy main respository. See [issue#25](https://github.com/envoyproxy/dynamic-modules-examples/issues/25) for more details.
1418

1519
This repository serves as a reference for developers who want to create their own dynamic modules for Envoy including
1620
how to setup the project, how to build it, and how to test it, etc.
@@ -31,7 +35,18 @@ cargo clippy -- -D warnings
3135
cargo fmt --all -- --check
3236
```
3337

34-
### Build Envoy + Example Rust Dynamic Module Docker Image
38+
### Go Dynamic Module
39+
To build and test the modules locally without Envoy, you can use `go` to build them just like any other Go project:
40+
41+
```
42+
cd go
43+
go test ./... -v
44+
go build -buildmode=c-shared -o libgo_module.so .
45+
go tool golangci-lint run
46+
find . -type f -name '*.go' | xargs go tool gofumpt -l -w
47+
```
48+
49+
### Build Envoy + Example Dynamic Module Docker Image
3550

3651
To build the example modules and bundle them with Envoy, simply run
3752

@@ -41,7 +56,7 @@ docker buildx build . -t envoy-with-dynamic-modules:latest [--platform linux/amd
4156

4257
where `--platform` is optional and can be used to build for multiple platforms.
4358

44-
### Run Envoy + Example Rust Dynamic Module Docker Image
59+
### Run Envoy + Example Dynamic Module Docker Image
4560

4661
The example Envoy configuration yaml is in [`integration/envoy.yaml`](integration/envoy.yaml) which is also used
4762
to run the integration tests. Assuming you built the Docker image with the tag `envoy-with-dynamic-modules:latest`, you can run Envoy with the following command:
@@ -69,16 +84,6 @@ If you want to explicitly specify the docker image, use `ENVOY_IMAGE` environmen
6984
ENVOY_IMAGE=foo-bar-image:latest go test . -v -count=1
7085
```
7186

72-
## Update Envoy Version
73-
74-
To update the Envoy version used in this repository, execute the following command:
75-
76-
```
77-
CURRENT_VERSION="$(cat ENVOY_VERSION)"
78-
NEW_VERSION=4a113b5118003682833ba612202eb68628861ac6 # Whatever the commit in envoyproxy/envoy repo.
79-
grep -rlF "${CURRENT_VERSION}" . | xargs sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
80-
```
81-
82-
[a27d2c31627e59f096f7c8cdc84488649158b000]: https://github.com/envoyproxy/envoy/tree/a27d2c31627e59f096f7c8cdc84488649158b000
87+
[5b88f941da971de57f29286103c20770811ec67f]: https://github.com/envoyproxy/envoy/tree/5b88f941da971de57f29286103c20770811ec67f
8388
[Envoy]: https://github.com/envoyproxy/envoy
8489
[High Level Doc]: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/dynamic_modules

go/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Experimental Go SDK
2+
3+
This directory hosts an experimental Go SDK for the dynamic modules and its example. See [issue#25](https://github.com/envoyproxy/dynamic-modules-examples/issues/25) for more details.

go/go.mod

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
module github.com/envoyproxy/dynamic-modules-examples/go
2+
3+
go 1.24.2
4+
5+
tool (
6+
github.com/golangci/golangci-lint/cmd/golangci-lint
7+
mvdan.cc/gofumpt
8+
)
9+
10+
require (
11+
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
12+
4d63.com/gochecknoglobals v0.2.2 // indirect
13+
github.com/4meepo/tagalign v1.4.2 // indirect
14+
github.com/Abirdcfly/dupword v0.1.3 // indirect
15+
github.com/Antonboom/errname v1.0.0 // indirect
16+
github.com/Antonboom/nilnil v1.0.1 // indirect
17+
github.com/Antonboom/testifylint v1.5.2 // indirect
18+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
19+
github.com/Crocmagnon/fatcontext v0.7.1 // indirect
20+
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
21+
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1 // indirect
22+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
23+
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
24+
github.com/alecthomas/go-check-sumtype v0.3.1 // indirect
25+
github.com/alexkohler/nakedret/v2 v2.0.5 // indirect
26+
github.com/alexkohler/prealloc v1.0.0 // indirect
27+
github.com/alingse/asasalint v0.0.11 // indirect
28+
github.com/alingse/nilnesserr v0.1.2 // indirect
29+
github.com/ashanbrown/forbidigo v1.6.0 // indirect
30+
github.com/ashanbrown/makezero v1.2.0 // indirect
31+
github.com/beorn7/perks v1.0.1 // indirect
32+
github.com/bkielbasa/cyclop v1.2.3 // indirect
33+
github.com/blizzy78/varnamelen v0.8.0 // indirect
34+
github.com/bombsimon/wsl/v4 v4.5.0 // indirect
35+
github.com/breml/bidichk v0.3.2 // indirect
36+
github.com/breml/errchkjson v0.4.0 // indirect
37+
github.com/butuzov/ireturn v0.3.1 // indirect
38+
github.com/butuzov/mirror v1.3.0 // indirect
39+
github.com/catenacyber/perfsprint v0.8.2 // indirect
40+
github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
41+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
42+
github.com/charithe/durationcheck v0.0.10 // indirect
43+
github.com/chavacava/garif v0.1.0 // indirect
44+
github.com/ckaznocha/intrange v0.3.0 // indirect
45+
github.com/curioswitch/go-reassign v0.3.0 // indirect
46+
github.com/daixiang0/gci v0.13.5 // indirect
47+
github.com/davecgh/go-spew v1.1.1 // indirect
48+
github.com/denis-tingaikin/go-header v0.5.0 // indirect
49+
github.com/ettle/strcase v0.2.0 // indirect
50+
github.com/fatih/color v1.18.0 // indirect
51+
github.com/fatih/structtag v1.2.0 // indirect
52+
github.com/firefart/nonamedreturns v1.0.5 // indirect
53+
github.com/fsnotify/fsnotify v1.5.4 // indirect
54+
github.com/fzipp/gocyclo v0.6.0 // indirect
55+
github.com/ghostiam/protogetter v0.3.9 // indirect
56+
github.com/go-critic/go-critic v0.12.0 // indirect
57+
github.com/go-toolsmith/astcast v1.1.0 // indirect
58+
github.com/go-toolsmith/astcopy v1.1.0 // indirect
59+
github.com/go-toolsmith/astequal v1.2.0 // indirect
60+
github.com/go-toolsmith/astfmt v1.1.0 // indirect
61+
github.com/go-toolsmith/astp v1.1.0 // indirect
62+
github.com/go-toolsmith/strparse v1.1.0 // indirect
63+
github.com/go-toolsmith/typep v1.1.0 // indirect
64+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
65+
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
66+
github.com/gobwas/glob v0.2.3 // indirect
67+
github.com/gofrs/flock v0.12.1 // indirect
68+
github.com/golang/protobuf v1.5.3 // indirect
69+
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect
70+
github.com/golangci/go-printf-func-name v0.1.0 // indirect
71+
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
72+
github.com/golangci/golangci-lint v1.64.8 // indirect
73+
github.com/golangci/misspell v0.6.0 // indirect
74+
github.com/golangci/plugin-module-register v0.1.1 // indirect
75+
github.com/golangci/revgrep v0.8.0 // indirect
76+
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
77+
github.com/google/go-cmp v0.7.0 // indirect
78+
github.com/gordonklaus/ineffassign v0.1.0 // indirect
79+
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
80+
github.com/gostaticanalysis/comment v1.5.0 // indirect
81+
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
82+
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
83+
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
84+
github.com/hashicorp/go-version v1.7.0 // indirect
85+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
86+
github.com/hashicorp/hcl v1.0.0 // indirect
87+
github.com/hexops/gotextdiff v1.0.3 // indirect
88+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
89+
github.com/jgautheron/goconst v1.7.1 // indirect
90+
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
91+
github.com/jjti/go-spancheck v0.6.4 // indirect
92+
github.com/julz/importas v0.2.0 // indirect
93+
github.com/karamaru-alpha/copyloopvar v1.2.1 // indirect
94+
github.com/kisielk/errcheck v1.9.0 // indirect
95+
github.com/kkHAIKE/contextcheck v1.1.6 // indirect
96+
github.com/kulti/thelper v0.6.3 // indirect
97+
github.com/kunwardeep/paralleltest v1.0.10 // indirect
98+
github.com/lasiar/canonicalheader v1.1.2 // indirect
99+
github.com/ldez/exptostd v0.4.2 // indirect
100+
github.com/ldez/gomoddirectives v0.6.1 // indirect
101+
github.com/ldez/grignotin v0.9.0 // indirect
102+
github.com/ldez/tagliatelle v0.7.1 // indirect
103+
github.com/ldez/usetesting v0.4.2 // indirect
104+
github.com/leonklingele/grouper v1.1.2 // indirect
105+
github.com/macabu/inamedparam v0.1.3 // indirect
106+
github.com/magiconair/properties v1.8.6 // indirect
107+
github.com/maratori/testableexamples v1.0.0 // indirect
108+
github.com/maratori/testpackage v1.1.1 // indirect
109+
github.com/matoous/godox v1.1.0 // indirect
110+
github.com/mattn/go-colorable v0.1.14 // indirect
111+
github.com/mattn/go-isatty v0.0.20 // indirect
112+
github.com/mattn/go-runewidth v0.0.16 // indirect
113+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
114+
github.com/mgechev/revive v1.7.0 // indirect
115+
github.com/mitchellh/go-homedir v1.1.0 // indirect
116+
github.com/mitchellh/mapstructure v1.5.0 // indirect
117+
github.com/moricho/tparallel v0.3.2 // indirect
118+
github.com/nakabonne/nestif v0.3.1 // indirect
119+
github.com/nishanths/exhaustive v0.12.0 // indirect
120+
github.com/nishanths/predeclared v0.2.2 // indirect
121+
github.com/nunnatsa/ginkgolinter v0.19.1 // indirect
122+
github.com/olekukonko/tablewriter v0.0.5 // indirect
123+
github.com/pelletier/go-toml v1.9.5 // indirect
124+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
125+
github.com/pmezard/go-difflib v1.0.0 // indirect
126+
github.com/polyfloyd/go-errorlint v1.7.1 // indirect
127+
github.com/prometheus/client_golang v1.12.1 // indirect
128+
github.com/prometheus/client_model v0.2.0 // indirect
129+
github.com/prometheus/common v0.32.1 // indirect
130+
github.com/prometheus/procfs v0.7.3 // indirect
131+
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect
132+
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
133+
github.com/quasilyte/gogrep v0.5.0 // indirect
134+
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
135+
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
136+
github.com/raeperd/recvcheck v0.2.0 // indirect
137+
github.com/rivo/uniseg v0.4.7 // indirect
138+
github.com/rogpeppe/go-internal v1.14.1 // indirect
139+
github.com/ryancurrah/gomodguard v1.3.5 // indirect
140+
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
141+
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
142+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
143+
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
144+
github.com/sashamelentyev/usestdlibvars v1.28.0 // indirect
145+
github.com/securego/gosec/v2 v2.22.2 // indirect
146+
github.com/sirupsen/logrus v1.9.3 // indirect
147+
github.com/sivchari/containedctx v1.0.3 // indirect
148+
github.com/sivchari/tenv v1.12.1 // indirect
149+
github.com/sonatard/noctx v0.1.0 // indirect
150+
github.com/sourcegraph/go-diff v0.7.0 // indirect
151+
github.com/spf13/afero v1.12.0 // indirect
152+
github.com/spf13/cast v1.5.0 // indirect
153+
github.com/spf13/cobra v1.9.1 // indirect
154+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
155+
github.com/spf13/pflag v1.0.6 // indirect
156+
github.com/spf13/viper v1.12.0 // indirect
157+
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
158+
github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect
159+
github.com/stretchr/objx v0.5.2 // indirect
160+
github.com/stretchr/testify v1.10.0 // indirect
161+
github.com/subosito/gotenv v1.4.1 // indirect
162+
github.com/tdakkota/asciicheck v0.4.1 // indirect
163+
github.com/tetafro/godot v1.5.0 // indirect
164+
github.com/timakin/bodyclose v0.0.0-20241017074812-ed6a65f985e3 // indirect
165+
github.com/timonwong/loggercheck v0.10.1 // indirect
166+
github.com/tomarrell/wrapcheck/v2 v2.10.0 // indirect
167+
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
168+
github.com/ultraware/funlen v0.2.0 // indirect
169+
github.com/ultraware/whitespace v0.2.0 // indirect
170+
github.com/uudashr/gocognit v1.2.0 // indirect
171+
github.com/uudashr/iface v1.3.1 // indirect
172+
github.com/xen0n/gosmopolitan v1.2.2 // indirect
173+
github.com/yagipy/maintidx v1.0.0 // indirect
174+
github.com/yeya24/promlinter v0.3.0 // indirect
175+
github.com/ykadowak/zerologlint v0.1.5 // indirect
176+
gitlab.com/bosi/decorder v0.4.2 // indirect
177+
go-simpler.org/musttag v0.13.0 // indirect
178+
go-simpler.org/sloglint v0.9.0 // indirect
179+
go.uber.org/atomic v1.7.0 // indirect
180+
go.uber.org/automaxprocs v1.6.0 // indirect
181+
go.uber.org/multierr v1.6.0 // indirect
182+
go.uber.org/zap v1.24.0 // indirect
183+
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
184+
golang.org/x/mod v0.24.0 // indirect
185+
golang.org/x/sync v0.13.0 // indirect
186+
golang.org/x/sys v0.32.0 // indirect
187+
golang.org/x/text v0.22.0 // indirect
188+
golang.org/x/tools v0.32.0 // indirect
189+
google.golang.org/protobuf v1.36.5 // indirect
190+
gopkg.in/ini.v1 v1.67.0 // indirect
191+
gopkg.in/yaml.v2 v2.4.0 // indirect
192+
gopkg.in/yaml.v3 v3.0.1 // indirect
193+
honnef.co/go/tools v0.6.1 // indirect
194+
mvdan.cc/gofumpt v0.8.0 // indirect
195+
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
196+
)

0 commit comments

Comments
 (0)