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.
This commit is contained in:
parent
2710dfb459
commit
5ba745982e
2 changed files with 74 additions and 2 deletions
69
checker/interactive.go
Normal file
69
checker/interactive.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue