Documentation
¶
Index ¶
- Variables
- func CheckCnameRecord(dnsResolver, domain, recordName, targetValue string) (bool, error)
- func CheckHtmlMetaTag(domain, metaTagName, metaTagContent string) (bool, error)
- func CheckJsonFile(domain, fileName string, expectedValue interface{}) (bool, error)
- func CheckTxtRecord(dnsResolver, domain, hostName, recordContent string) (bool, error)
- func CheckXmlFile(domain, fileName string, expectedValue interface{}) (bool, error)
- func IsSecure(domain string, timeout time.Duration) (bool, error)
- func IsValidDomainName(domain string) bool
- type DnsRecordInstruction
- type FileInstruction
- func GenerateJson(appName string) (*FileInstruction, error)
- func GenerateJsonFromConfig(config *config.JsonGenerator, useInternalCode bool) (*FileInstruction, error)
- func GenerateXml(appName string, sanitizeAppName bool) (*FileInstruction, error)
- func GenerateXmlFromConfig(config *config.XmlGenerator, useInternalCode bool) (*FileInstruction, error)
- type HtmlMetaInstruction
Constants ¶
This section is empty.
Variables ¶
var InvalidAppNameError = errors.New("app name cannot be empty")
InvalidAppNameError indicates that the app name is invalid.
var InvalidDomainError = errors.New("invalid domain name")
InvalidDomainError indicates that the domain name is invalid
var InvalidResponseError = errors.New("invalid response status code returned by the server")
InvalidResponseError indicates that the response is invalid
Functions ¶
func CheckCnameRecord ¶
CheckCnameRecord checks if the domain has a DNS CNAME record with the specified values to verify ownership of the domain
Parameters:
- dnsResolver: the DNS server to use
- domain: the domain name to verify the ownership
- recordName: the name of the DNS CNAME record to check
- targetValue: the value of recordName
Returns:
- true if the ownership of the domain is verified
- error if any
Example:
dnsResolver = dnsresolver.CloudflareDNS domain := "website.com" recordName := "1234567890" targetValue := "verify.myapp.com" verified, err := domainverify.CheckDnsCnameRecord(dnsResolver, domain, recordName, targetValue)
func CheckHtmlMetaTag ¶
CheckHtmlMetaTag checks if the html meta tag exists and has the expected value
Parameters:
domain: the domain name to check metaTagName: the name of the meta tag to check metaTagContent: the expected value of the meta tag
Returns:
- true if the ownership of the domain is verified
- error if any
func CheckJsonFile ¶
CheckJsonFile checks if the json file exists and has the expected content to verify ownership of the domain
Parameters:
- domain: the domain name to check
- fileName: the name of the json file to check
- expectedValue: the expected content
Returns:
- true if the ownership of the domain is verified
- error if any
Example:
type OwnershipVerification struct {
Code string `json:"myapp_site_verification"`
}
data := OwnershipVerification{Code: "1234567890"}
domain := "website.com"
fileName := "myapp-site-verification.json" // excepted file content: {"myapp_site_verification": "1234567890"}
verified, err := domainverify.CheckJsonFile(domain, fileName, data)
func CheckTxtRecord ¶
CheckTxtRecord checks if the domain has a DNS TXT record with the specified values to verify ownership of the domain
Parameters:
- dnsResolver: the DNS server to use
- domain: the domain name to verify
- hostName: the TXT record name
- recordContent: the content of the TXT record
Returns:
- true if the ownership of the domain is verified
- error if any
Example:
dnsResolver = dnsresolver.CloudflareDNS domain := "website.com" hostName := "@" recordContent := "myapp-site-verification=1234567890" verified, err := domainverify.CheckDnsTxtRecord(dnsServer, domain, hostName, recordContent)
func CheckXmlFile ¶
CheckXmlFile checks if the xml file exists and has the expected content to verify ownership of the domain
Parameters:
- domain: the domain name to check
- fileName: the name of the xml file to check
- expectedValue: the expected content
Returns:
- true if the ownership of the domain is verified
- error if any
Example:
type OwnershipVerification struct {
XMLName struct{} `xml:"verification"`
Code string `xml:"code" json:"myapp_site_verification"`
}
data := OwnershipVerification{Code: "1234567890"}
domain := "website.com"
fileName := "myappSiteAuth.xml" // excepted file content: <verification><code>1234567890</code></verification>
verified, err := domainverify.CheckXmlFile(domain, fileName, data)
func IsSecure ¶
IsSecure returns a boolean value indicating whether the specified domain supports a secure connection over HTTPS or not. If the domain is not reachable, an error is returned.
func IsValidDomainName ¶
IsValidDomainName checks if a string is a valid domain name.
Types ¶
type DnsRecordInstruction ¶
DnsRecordInstruction is the CNAME or TXT record instruction.
func GenerateCnameRecordFromConfig ¶
func GenerateCnameRecordFromConfig(config *config.CnameRecordGenerator) (*DnsRecordInstruction, error)
GenerateCnameRecordFromConfig generates the CNAME verification method instructions. It uses the provided config.CnameGenerator to generate the instructions.
func GenerateTxtRecord ¶
func GenerateTxtRecord(appName string) (*DnsRecordInstruction, error)
GenerateTxtRecord generates the TXT verification method instructions. appName is the name of the app that is requesting the verification (e.g. bing, google, etc.). It will be used as prefix of the record attribute.
func GenerateTxtRecordFromConfig ¶
func GenerateTxtRecordFromConfig(config *config.TxtRecordGenerator, useInternalCode bool) (*DnsRecordInstruction, error)
GenerateTxtRecordFromConfig generates the TXT verification method instructions. It uses the provided config.TxtGenerator to generate the instructions. If useInternalCode is true, internal K-Sortable Globally Unique ID will be generated for the record attribute value. Otherwise, the RecordAttribute in the config.TxtGenerator will be used.
type FileInstruction ¶
FileInstruction is the JSON or XML file instruction.
func GenerateJson ¶
func GenerateJson(appName string) (*FileInstruction, error)
GenerateJson generates the JSON verification method instructions. appName is the name of the app that is requesting the verification (e.g. google, bing, etc.). It will be used as prefix of the file name and the attribute name. Note that the appName will be sanitized to non-alphanumeric characters.
func GenerateJsonFromConfig ¶
func GenerateJsonFromConfig(config *config.JsonGenerator, useInternalCode bool) (*FileInstruction, error)
GenerateJsonFromConfig generates the JSON verification method instructions. It uses the provided config.JsonGenerator to generate the instructions. If useInternalCode is true, internal K-Sortable Globally Unique ID will be generated. Otherwise, the code in the config.JsonGenerator will be used.
func GenerateXml ¶
func GenerateXml(appName string, sanitizeAppName bool) (*FileInstruction, error)
GenerateXml generates the XML verification method instructions. appName is the name of the app that is requesting the verification (e.g. bing, google, etc.). It will be used as prefix of the file name. Note that the appName will be sanitized to non-alphanumeric characters.
func GenerateXmlFromConfig ¶
func GenerateXmlFromConfig(config *config.XmlGenerator, useInternalCode bool) (*FileInstruction, error)
GenerateXmlFromConfig generates the XML verification method instructions. It uses the provided config.XmlGenerator to generate the instructions. If useInternalCode is true, internal K-Sortable Globally Unique ID will be generated. Otherwise, the code in the config.XmlGenerator will be used.
type HtmlMetaInstruction ¶
HtmlMetaInstruction is the Html meta tag instruction.
func GenerateHtmlMeta ¶
func GenerateHtmlMeta(appName string, sanitizeAppName bool) (*HtmlMetaInstruction, error)
GenerateHtmlMeta generates the HTML meta tag verification method instructions. appName is the name of the app that is requesting the verification (e.g. msvalidate.01, mysuperapp, etc.). It will be used as the name of the meta tag. Note that the appName will be sanitized to non-alphanumeric characters.
func GenerateHtmlMetaFromConfig ¶
func GenerateHtmlMetaFromConfig(config *config.HmlMetaTagGenerator, useInternalCode bool) (*HtmlMetaInstruction, error)
GenerateHtmlMetaFromConfig generates the HTML meta tag verification method instructions. It uses the provided config.HmlMetaTagGenerator to generate the instructions. If useInternalCode is true, internal K-Sortable Globally Unique ID will be generated. Otherwise, the code in the config.HmlMetaTagGenerator will be used.