domain_util

package module
v0.0.0-...-4107a72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 4 Imported by: 0

README

Package: domain_util

This package provides utility functions for domain name manipulation and parsing.

Functions:

  1. SplitFldDomainAndSubDomain(domain string) (fldDomain string, subDomainName string, err error)

    • Description: Splits a domain name into its first-level domain (FLD) and subdomain parts.
    • Parameters:
      • domain (string): The domain name to be split.
    • Returns:
      • fldDomain (string): The first-level domain part of the domain.
      • subDomainName (string): The subdomain part of the domain.
      • err (error): Any error that occurs during the process.
    • Example:
      fldDomain, subDomain, err := domain_util.SplitFldDomainAndSubDomain("sub.example.com")
      if err != nil {
          // handle error
      }
      fmt.Println(fldDomain)  // Output: "example.com"
      fmt.Println(subDomain) // Output: "sub"
      
  2. FldDomain(domain string) (string, error)

    • Description: Extracts the first-level domain part from a domain name.
    • Parameters:
      • domain (string): The domain name to extract the FLD from.
    • Returns:
      • string: The first-level domain part of the domain.
      • error: Any error that occurs during the process.
    • Example:
      fldDomain, err := domain_util.FldDomain("sub.example.com")
      if err != nil {
          // handle error
      }
      fmt.Println(fldDomain) // Output: "example.com"
      
  3. FldDomainIgnoreError(domain string) string

    • Description: Extracts the first-level domain part from a domain name, ignoring any errors.
    • Parameters:
      • domain (string): The domain name to extract the FLD from.
    • Returns:
      • string: The first-level domain part of the domain or an empty string if an error occurs.
    • Example:
      fldDomain := domain_util.FldDomainIgnoreError("sub.example.com")
      fmt.Println(fldDomain) // Output: "example.com"
      
  4. IsFldDomain(domain string) (bool, error)

    • Description: Determines if the given domain is a first-level domain.
    • Parameters:
      • domain (string): The domain to check.
    • Returns:
      • bool: True if the domain is a FLD, false otherwise.
      • error: Any error that occurs during the process.
    • Example:
      isFld, err := domain_util.IsFldDomain("example.com")
      if err != nil {
          // handle error
      }
      fmt.Println(isFld) // Output: true
      
  5. *NewHostEntry(host string) (HostEntry, error)

    • Description: Parses a domain name and separates its first-level domain and subdomain information into a HostEntry struct.
    • Parameters:
      • host (string): The domain name to parse.
    • Returns:
      • *HostEntry: A pointer to a HostEntry struct containing the parsed information.
      • error: Any error that occurs during the process.
    • Example:
      entry, err := domain_util.NewHostEntry("sub.example.com")
      if err != nil {
          // handle error
      }
      fmt.Println(entry.Domain) // Output: "example.com"
      

Types:

  1. HostEntry

    • Description: A struct representing a host entry with its domain information.
    • Fields:
      • Host (string): The original host string.
      • Tld (string): The top-level domain.
      • Domain (string): The first-level domain.
      • SubName (string): The subdomain.
      • WildcardBase (string): The base for wildcard records.
      • WildcardRecords []Record: A slice of wildcard records.
      • Wildcard (bool): Indicates if the host has wildcard records.
  2. Record

    • Description: A struct representing a DNS record.
    • Fields:
      • Type (string): The type of the DNS record.
      • Value (string): The value of the DNS record.

Notes:

  • The isASCII function is defined twice with the same implementation. It should be removed or refactored to avoid redundancy.
  • The HostEntry struct contains fields that are not used in the provided functions (WildcardRecords and Wildcard). These fields should be either used or removed to maintain clarity and avoid confusion.

This documentation provides a clear understanding of each function's purpose, parameters, return values, and usage examples, as well as descriptions of the defined types.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FldDomain

func FldDomain(domain string) (string, error)

FldDomain 取域名中的一级域名部分

func FldDomainIgnoreError

func FldDomainIgnoreError(domain string) string

FldDomainIgnoreError 取域名中的一级域名部分,忽略错误,如果有错误的话则会返回空字符串

func IsASCII

func IsASCII(s string) bool

func IsFldDomain

func IsFldDomain(domain string) (bool, error)

IsFldDomain 判断给定的域名是否是一个根域名

func SplitFldDomainAndSubDomain

func SplitFldDomainAndSubDomain(domain string) (fldDomain string, subDomainName string, err error)

SplitFldDomainAndSubDomain 将域名中的一级域名和其子域名分割开

Types

type HostEntry

type HostEntry struct {
	Host            string
	Tld             string
	Domain          string
	SubName         string
	WildcardBase    string
	WildcardRecords []Record
	Wildcard        bool
}

func NewHostEntry

func NewHostEntry(host string) (*HostEntry, error)

NewHostEntry 解析域名,分离其中的一级域名和子域名信息

type Record

type Record struct {
	Type  string `bson:"type"`
	Value string `bson:"value"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL