checker-zonemaster/checker/interactive.go
Pierre-Olivier Mercier 5ba745982e checker: add standalone interactive form and test target
Implement RenderForm/ParseForm for the zonemasterProvider under the
standalone build tag, enabling browser-based interactive use. Also add
a `make test` target that builds with the same tag.
2026-04-26 17:19:32 +07:00

69 lines
1.8 KiB
Go

//go:build standalone
package checker
import (
"errors"
"net/http"
"strings"
sdk "git.happydns.org/checker-sdk-go/checker"
)
func (p *zonemasterProvider) RenderForm() []sdk.CheckerOptionField {
return []sdk.CheckerOptionField{
{
Id: "domainName",
Type: "string",
Label: "Domain name to check",
Placeholder: "example.com",
Required: true,
Description: "Fully-qualified domain name to submit to the Zonemaster engine.",
},
{
Id: "profile",
Type: "string",
Label: "Profile",
Placeholder: "default",
Description: "Zonemaster test profile to apply (engine-defined; usually \"default\").",
},
{
Id: "language",
Type: "string",
Label: "Result language",
Placeholder: "en",
Description: "Language for human-readable test messages (en, fr, de, es, sv, da, fi, nb, nl, pt).",
},
{
Id: "zonemasterAPIURL",
Type: "string",
Label: "Zonemaster API URL",
Placeholder: "https://zonemaster.net/api",
Description: "JSON-RPC endpoint of the Zonemaster backend to query.",
},
}
}
func (p *zonemasterProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
domainName := strings.TrimSpace(r.FormValue("domainName"))
if domainName == "" {
return nil, errors.New("domainName is required")
}
domainName = strings.TrimSuffix(domainName, ".")
opts := sdk.CheckerOptions{
"domainName": domainName,
}
if v := strings.TrimSpace(r.FormValue("profile")); v != "" {
opts["profile"] = v
}
if v := strings.TrimSpace(r.FormValue("language")); v != "" {
opts["language"] = v
}
if v := strings.TrimSpace(r.FormValue("zonemasterAPIURL")); v != "" {
opts["zonemasterAPIURL"] = strings.TrimSuffix(v, "/")
}
return opts, nil
}