db

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Client *mongo.Client

	Domains  *mongo.Collection // The main collection to store the entries
	NotFound *mongo.Collection // Store domains that not found by Lookup
	TopList  *mongo.Collection // Store and count successful lookups
)

Functions

func Connect

func Connect(uri string) error

Connect connects to the database using the standard Connection URI.

func Disconnect

func Disconnect() error

Disconnect gracefully disconnect from the database.

func GetStat

func GetStat() (int64, error)

GetStat returns the total number of domains.

func Insert

func Insert(d string) (bool, error)

Insert inserts the given domain d to the *domains* database. Checks if d is valid, do a Clean() and then splits into sub|domain|tld parts.

Returns true if d is new and inserted into the database. If domain is invalid, returns fault.ErrInvalidDomain. If failed to get parts of d (eg.: d is a TLD), returns ault.ErrGetPartsFailed.

func InsertNotFound added in v0.14.0

func InsertNotFound(d string) (bool, error)

InsertNotFound inserts the given domain d to the *notFound* database. Checks if d is valid, do a Clean() and removes the subdomain from d.

Returns true if d is new and inserted into the database. If domain is invalid or failed to remove the subdomain, returns fault.ErrInvalidDomain.

func InsertTopList added in v0.14.0

func InsertTopList(d string) (bool, error)

InsertTopList inserts the given domain d to the *topList* database or increase the counter if exists. Checks if d is valid, do a Clean() and removes the subdomain from d.

Returns true if d is new and inserted into the database. If domain is invalid or failed to remove the subdomain, returns fault.ErrInvalidDomain.

func Lookup

func Lookup(d string) ([]string, error)

Lookup query the DB and returns a list subdomains.

If d has a subdomain, removes it before the query.

If d is invalid return fault.ErrInvalidDomain. If failed to get parts of d (eg.: d is a TLD), returns ault.ErrGetPartsFailed.

func Starts added in v0.14.0

func Starts(d string) ([]string, error)

Starts query the DB and returns a list of Second Level Domains (eg.: example) that starts with d.

Domain d must be a valid Second Level Domain (eg.: "example"). This function validate with IsValidSLD() and Clean().

Returns fault.ErrInvalidDomain is d is not a valid Second Level Domain.

func TLD added in v0.14.0

func TLD(d string) ([]string, error)

TLD query the DB and returns a list of TLDs for the given domain d.

Domain d must be a valid Second Level Domain (eg.: "example").

NOTE: This function not validate adn Clean() d!

Types

type DomainSchema added in v0.14.0

type DomainSchema struct {
	Domain string `bson:"domain" json:"domain"`
	TLD    string `bson:"tld" json:"tld"`
	Sub    string `bson:"sub" json:"sub"`
}

Schema used in the "domains" collection.

func (*DomainSchema) FullDomain added in v0.14.0

func (d *DomainSchema) FullDomain() string

Returns the domain and tld only (eg.: domain.tld)

func (*DomainSchema) String added in v0.14.0

func (d *DomainSchema) String() string

Returns the full hostname (eg.: sub.domain.tld).

type NotFoundSchema added in v0.14.0

type NotFoundSchema struct {
	Domain string `bson:"domain" json:"domain"`
}

Schema used in *notFound* collection.

type TopListSchema added in v0.14.0

type TopListSchema struct {
	Domain string `bson:"domain" json:"domain"`
	Count  int    `bson:"count" json:"count"`
}

Schema used in *topList* collection.

Jump to

Keyboard shortcuts

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