func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
	if config == nil {
		return nil, errors.New("namecheap: the configuration of the DNS provider is nil")
	}
	if config.APIUser == "" || config.APIKey == "" {
		return nil, errors.New("namecheap: credentials missing")
	}
	if config.ClientIP == "" {
		clientIP, err := getClientIP(config.HTTPClient, config.Debug)
		if err != nil {
			return nil, fmt.Errorf("namecheap: %w", err)
		}
		config.ClientIP = clientIP
	}
	return &DNSProvider{config: config}, nil
}
NewDNSProviderConfig return a DNSProvider instance configured for Namecheap.
package namecheap
import (
	"errors"
	"fmt"
	"io"
	"net/http"
	"strconv"
	"strings"
	"time"
	"github.com/go-acme/lego/v4/challenge/dns01"
	"github.com/go-acme/lego/v4/log"
	"github.com/go-acme/lego/v4/platform/config/env"
	"golang.org/x/net/publicsuffix"
)
const (
	defaultBaseURL = "https://api.namecheap.com/xml.response"
	sandboxBaseURL = "https://api.sandbox.namecheap.com/xml.response"
	getIPURL       = "https://dynamicdns.park-your-domain.com/getip"
)
const (
	envNamespace = "NAMECHEAP_"
	EnvAPIUser = envNamespace + "API_USER"
	EnvAPIKey  = envNamespace + "API_KEY"
	EnvSandbox = envNamespace + "SANDBOX"
	EnvDebug   = envNamespace + "DEBUG"
	EnvTTL                = envNamespace + "TTL"
	EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
	EnvPollingInterval    = envNamespace + "POLLING_INTERVAL"
	EnvHTTPTimeout        = envNamespace + "HTTP_TIMEOUT"
)
type challenge struct {
	domain   string
	key      string
	keyFqdn  string
	keyValue string
	tld      string
	sld      string
	host     string
}
type Config struct {
	Debug              bool
	BaseURL            string
	APIUser            string
	APIKey             string
	ClientIP           string
	PropagationTimeout time.Duration
	PollingInterval    time.Duration
	TTL                int
	HTTPClient         *http.Client
}
func NewDefaultConfig() *Config {
	baseURL := defaultBaseURL
	if env.GetOrDefaultBool(EnvSandbox, false) {
		baseURL = sandboxBaseURL
	}
	return &Config{
		BaseURL:            baseURL,
		Debug:              env.GetOrDefaultBool(EnvDebug, false),
		TTL:                env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
		PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Minute),
		PollingInterval:    env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
		HTTPClient: &http.Client{
			Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
		},
	}
}
type DNSProvider struct {
	config *Config
}
func NewDNSProvider() (*DNSProvider, error) {
	values, err := env.Get(EnvAPIUser, EnvAPIKey)
	if err != nil {
		return nil, fmt.Errorf("namecheap: %w", err)
	}
	config := NewDefaultConfig()
	config.APIUser = values[EnvAPIUser]
	config.APIKey = values[EnvAPIKey]
	return NewDNSProviderConfig(config)
}