39 lines
950 B
Go
39 lines
950 B
Go
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build standalone
|
|
|
|
package checker
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strings"
|
|
|
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
|
)
|
|
|
|
// RenderForm exposes a minimal /check form when running standalone.
|
|
func (p *dnsvizProvider) RenderForm() []sdk.CheckerOptionField {
|
|
return []sdk.CheckerOptionField{
|
|
{
|
|
Id: "domain_name",
|
|
Type: "string",
|
|
Label: "Domain name",
|
|
Placeholder: "example.com",
|
|
Required: true,
|
|
Description: "Fully-qualified domain name to analyse with DNSViz.",
|
|
},
|
|
}
|
|
}
|
|
|
|
// ParseForm builds the CheckerOptions from the human-facing /check form.
|
|
func (p *dnsvizProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
|
|
domain := strings.TrimSpace(r.FormValue("domain_name"))
|
|
if domain == "" {
|
|
return nil, errors.New("domain name is required")
|
|
}
|
|
opts := sdk.CheckerOptions{
|
|
"domain_name": strings.TrimSuffix(domain, "."),
|
|
}
|
|
return opts, nil
|
|
}
|