From b1ebac2198a746ca82990f467589070a0da7a884 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 24 Apr 2026 13:04:28 +0700 Subject: [PATCH] Migrate to checker-sdk-go v1.3.0 with standalone build tag The SDK split the HTTP server scaffolding into the new checker-sdk-go/checker/server subpackage. Update main.go to import server and call server.New, and isolate the interactive form code behind the standalone build tag so plugin/builtin builds skip net/http entirely. --- Dockerfile | 2 +- Makefile | 7 +++++-- README.md | 4 ++-- checker/definition.go | 6 ++---- checker/interactive.go | 8 +++++--- checker/provider.go | 5 ----- go.mod | 2 +- go.sum | 4 ++-- main.go | 6 +++--- plugin/plugin.go | 3 ++- 10 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index c306172..791b24a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 go build -ldflags "-X main.Version=${CHECKER_VERSION}" -o /checker-ping . +RUN CGO_ENABLED=0 go build -tags standalone -ldflags "-X main.Version=${CHECKER_VERSION}" -o /checker-ping . FROM scratch COPY --from=builder /checker-ping /checker-ping diff --git a/Makefile b/Makefile index 70487bb..9b9f6ff 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ CHECKER_SOURCES := main.go $(wildcard checker/*.go) GO_LDFLAGS := -X main.Version=$(CHECKER_VERSION) -.PHONY: all plugin docker clean +.PHONY: all plugin docker test clean all: $(CHECKER_NAME) $(CHECKER_NAME): $(CHECKER_SOURCES) - go build -ldflags "$(GO_LDFLAGS)" -o $@ . + go build -tags standalone -ldflags "$(GO_LDFLAGS)" -o $@ . plugin: $(CHECKER_NAME).so @@ -21,5 +21,8 @@ $(CHECKER_NAME).so: $(CHECKER_SOURCES) $(wildcard plugin/*.go) docker: docker build --build-arg CHECKER_VERSION=$(CHECKER_VERSION) -t $(CHECKER_IMAGE) . +test: + go test -tags standalone ./... + clean: rm -f $(CHECKER_NAME) $(CHECKER_NAME).so diff --git a/README.md b/README.md index 8572c87..6cc3949 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ make The server exposes: -- `GET /health` — health check -- `POST /collect` — collect ping observations (happyDomain external checker protocol) +- `GET /health`, health check +- `POST /collect`, collect ping observations (happyDomain external checker protocol) ### Docker diff --git a/checker/definition.go b/checker/definition.go index e7e44fe..0f2b98f 100644 --- a/checker/definition.go +++ b/checker/definition.go @@ -38,7 +38,7 @@ import ( var Version = "built-in" // Definition returns the CheckerDefinition for the ping checker. -func Definition() *happydns.CheckerDefinition { +func (p *pingProvider) Definition() *happydns.CheckerDefinition { return &happydns.CheckerDefinition{ ID: "ping", Name: "Ping (ICMP)", @@ -89,9 +89,7 @@ func Definition() *happydns.CheckerDefinition { }, }, }, - Rules: []happydns.CheckRule{ - Rule(), - }, + Rules: Rules(), Interval: &happydns.CheckIntervalSpec{ Min: 1 * time.Minute, Max: 1 * time.Hour, diff --git a/checker/interactive.go b/checker/interactive.go index 784db24..f35d217 100644 --- a/checker/interactive.go +++ b/checker/interactive.go @@ -19,6 +19,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +//go:build standalone + package checker import ( @@ -30,7 +32,7 @@ import ( sdk "git.happydns.org/checker-sdk-go/checker" ) -// RenderForm implements sdk.CheckerInteractive. It exposes a minimal form +// RenderForm implements server.Interactive. It exposes a minimal form // letting a human submit one or more ping targets (hostnames or IPs) along // with the usual threshold knobs. func (p *pingProvider) RenderForm() []sdk.CheckerOptionField { @@ -76,8 +78,8 @@ func (p *pingProvider) RenderForm() []sdk.CheckerOptionField { } } -// ParseForm implements sdk.CheckerInteractive. It converts the HTML form -// inputs into a CheckerOptions that Collect can consume directly — pinging +// ParseForm implements server.Interactive. It converts the HTML form +// inputs into a CheckerOptions that Collect can consume directly, pinging // resolves hostnames on its own, so no extra lookups are needed here. func (p *pingProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) { raw := strings.TrimSpace(r.FormValue("addresses")) diff --git a/checker/provider.go b/checker/provider.go index 3b7a411..6488fe8 100644 --- a/checker/provider.go +++ b/checker/provider.go @@ -47,11 +47,6 @@ func (p *pingProvider) Key() happydns.ObservationKey { return ObservationKeyPing } -// Definition implements happydns.CheckerDefinitionProvider. -func (p *pingProvider) Definition() *happydns.CheckerDefinition { - return Definition() -} - // ExtractMetrics implements happydns.CheckerMetricsReporter. func (p *pingProvider) ExtractMetrics(ctx happydns.ReportContext, collectedAt time.Time) ([]happydns.CheckMetric, error) { var data PingData diff --git a/go.mod b/go.mod index 8e1e592..f7e14e2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.happydns.org/checker-ping go 1.25.0 require ( - git.happydns.org/checker-sdk-go v1.2.0 + git.happydns.org/checker-sdk-go v1.3.0 git.happydns.org/happyDomain v0.7.0 github.com/prometheus-community/pro-bing v0.8.0 ) diff --git a/go.sum b/go.sum index 630d66c..d00c58f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.happydns.org/checker-sdk-go v1.2.0 h1:v4MpKAz0W3PwP+bxx3pya8w893sVH5xTD1of1cc0TV8= -git.happydns.org/checker-sdk-go v1.2.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI= +git.happydns.org/checker-sdk-go v1.3.0 h1:FG2kIhlJCzI0m35EhxSgn4UWc9M4ha6aZTeoChu4l7A= +git.happydns.org/checker-sdk-go v1.3.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI= git.happydns.org/happyDomain v0.7.0 h1:NV82/NbcSeRm0+IUZqaK3Vu9Ovl5+vv4AigUJZMdwws= git.happydns.org/happyDomain v0.7.0/go.mod h1:5tgkmqFE65kK359rY49V++49wgZ0gco+Gh9X6tbL+bY= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= diff --git a/main.go b/main.go index a28e774..5ced67f 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( "log" ping "git.happydns.org/checker-ping/checker" - sdk "git.happydns.org/checker-sdk-go/checker" + "git.happydns.org/checker-sdk-go/checker/server" ) var ( @@ -47,8 +47,8 @@ func main() { // CheckerDefinition.Version. ping.Version = Version - server := sdk.NewServer(ping.ProviderWithPrivileged(*privileged)) - if err := server.ListenAndServe(*listenAddr); err != nil { + srv := server.New(ping.ProviderWithPrivileged(*privileged)) + if err := srv.ListenAndServe(*listenAddr); err != nil { log.Fatalf("server error: %v", err) } } diff --git a/plugin/plugin.go b/plugin/plugin.go index 4655463..194a32c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -22,5 +22,6 @@ func NewCheckerPlugin() (*sdk.CheckerDefinition, sdk.ObservationProvider, error) // Propagate the plugin's version to the checker package so it shows up // in CheckerDefinition.Version. ping.Version = Version - return ping.Definition(), ping.Provider(), nil + prvd := ping.Provider() + return prvd.(sdk.CheckerDefinitionProvider).Definition(), prvd, nil }