From eb7b6d1a904d5987b26dfd94bbe071aa79e340ea Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 24 Apr 2026 12:54:01 +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 and renamed CheckerInteractive to server.Interactive. Update main.go to import server and call server.New, switch the compile-time assertion to server.Interactive, and isolate the interactive form code behind the standalone build tag so plugin/builtin builds skip net/http entirely. --- Dockerfile | 2 +- Makefile | 7 +++++-- checker/definition.go | 2 +- checker/interactive.go | 16 ++++++++++------ go.mod | 2 +- go.sum | 4 ++-- main.go | 6 +++--- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 112385c..3d80622 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-email-keys . +RUN CGO_ENABLED=0 go build -tags standalone -ldflags "-X main.Version=${CHECKER_VERSION}" -o /checker-email-keys . FROM scratch COPY --from=builder /checker-email-keys /checker-email-keys diff --git a/Makefile b/Makefile index b1b1b12..a2216c5 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/checker/definition.go b/checker/definition.go index 12325c4..e999477 100644 --- a/checker/definition.go +++ b/checker/definition.go @@ -19,7 +19,7 @@ const ( ) // Definition is the package-level helper returned to the host by the -// plugin entrypoint and used by sdk.NewServer via the provider's +// plugin entrypoint and used by server.New via the provider's // CheckerDefinitionProvider implementation. func Definition() *sdk.CheckerDefinition { return &sdk.CheckerDefinition{ diff --git a/checker/interactive.go b/checker/interactive.go index 45e1693..a69039a 100644 --- a/checker/interactive.go +++ b/checker/interactive.go @@ -1,3 +1,5 @@ +//go:build standalone + package checker import ( @@ -5,14 +7,16 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" "strings" "github.com/miekg/dns" sdk "git.happydns.org/checker-sdk-go/checker" + "git.happydns.org/checker-sdk-go/checker/server" ) -// RenderForm implements sdk.CheckerInteractive. It exposes the minimal +// RenderForm implements server.Interactive. It exposes the minimal // inputs needed to bootstrap a standalone OPENPGPKEY/SMIMEA check: an // email address (the local part is hashed into the owner name) and a // kind selector. The DNS resolver and severity-tuning options mirror @@ -63,7 +67,7 @@ func (p *emailKeyProvider) RenderForm() []sdk.CheckerOptionField { } } -// ParseForm implements sdk.CheckerInteractive. It validates the inputs, +// ParseForm implements server.Interactive. It validates the inputs, // resolves the DNS record matching the requested kind, and returns the // CheckerOptions that Collect expects, including a synthesised service // envelope built from the live DNS answer. @@ -102,7 +106,7 @@ func (p *emailKeyProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error } resolverOpt := strings.TrimSpace(r.FormValue(OptionResolver)) - owner := dns.Fqdn(ownerHashHex(username) + "." + strings.TrimPrefix(prefix, ".") + "." + domain) + owner := dns.Fqdn(ownerHashHex(username) + "." + prefix + "." + domain) ctx, cancel := context.WithTimeout(r.Context(), dnsTimeout*3) defer cancel() @@ -160,12 +164,12 @@ func (p *emailKeyProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error // parseFloatOr parses a decimal string, returning fallback on error. func parseFloatOr(s string, fallback float64) float64 { - var f float64 - if _, err := fmt.Sscanf(s, "%f", &f); err != nil { + f, err := strconv.ParseFloat(s, 64) + if err != nil { return fallback } return f } // Compile-time assertion that the provider implements the optional interface. -var _ sdk.CheckerInteractive = (*emailKeyProvider)(nil) +var _ server.Interactive = (*emailKeyProvider)(nil) diff --git a/go.mod b/go.mod index 541266a..9748cd3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.happydns.org/checker-email-keys go 1.25.0 require ( - git.happydns.org/checker-sdk-go v1.1.0 + git.happydns.org/checker-sdk-go v1.3.0 github.com/ProtonMail/go-crypto v1.1.0-alpha.0 github.com/miekg/dns v1.1.72 ) diff --git a/go.sum b/go.sum index 1a849ac..286a592 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.happydns.org/checker-sdk-go v1.1.0 h1:xgR39X1Mh+v481BHTDYHtGYFL1qRwldTsehazwSc67Y= -git.happydns.org/checker-sdk-go v1.1.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= github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0= github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= diff --git a/main.go b/main.go index d7e1801..12d8ed2 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "log" emailkeys "git.happydns.org/checker-email-keys/checker" - sdk "git.happydns.org/checker-sdk-go/checker" + "git.happydns.org/checker-sdk-go/checker/server" ) // Version is the standalone binary's version. Override with: @@ -20,8 +20,8 @@ func main() { emailkeys.Version = Version - server := sdk.NewServer(emailkeys.Provider()) - if err := server.ListenAndServe(*listenAddr); err != nil { + srv := server.New(emailkeys.Provider()) + if err := srv.ListenAndServe(*listenAddr); err != nil { log.Fatalf("server error: %v", err) } }