Documentation
¶
Index ¶
- Constants
- Variables
- func Connect() error
- func Disconnect()
- func GetStat() (d int64, s int64, err error)
- func Init() error
- func Insert(d string) error
- func IsNameTaken(name string) (bool, error)
- func Lookup(d string, full bool) ([]string, error)
- func Update() error
- func UserChangeAdmin(u *user.User, newValue bool) error
- func UserChangeKey(u *user.User) error
- func UserChangeName(u *user.User, name string) error
- func UserCreate(name string, admin bool) (user.User, error)
- func UserDelete(key, name string) error
- func UserGetKey(key string) (user.User, error)
- func UserGetName(name string) (user.User, error)
- func UserList() ([]user.User, error)
Constants ¶
const (
ApiKeyLength = 48
)
Variables ¶
var ( Client *mongo.Client Domains *mongo.Collection Users *mongo.Collection )
Functions ¶
func GetStat ¶
GetStat resturns the total number of domains (d), the total number of subdomains (s) and the error (if any).
func Init ¶
func Init() error
Init creates the indexes in domains and users collection and creates an "admin" user if no admin privileged user is exist.
func Insert ¶
Insert insert the given domain d to the database. Firstly, checks if d is valid. Then split into sub|domain parts. Sharding means, if the document is reached the 16MB limit increase the "shard" field by one.
If domain is invalid, returns fault.ErrInvalidDomain.
If d is publicsuffix, returns fault.ErrPublicSuffix.
func IsNameTaken ¶
IsNameTaken check whether the given user name is already taken.
Returns fault.ErrNameEmpty if name is empty.
func Lookup ¶
Lookup query the DB and returns a list subdomains. If full is true, return the full hostname, not just the subs.
func Update ¶
func Update() error
Update updates the domains if new publixsuffix is added. used at the begining to update the domains if new publicsuffix rule is added to the list. If the stored domain is not valid after the new rules, create a list of full names, rewrite it with Write() where the new rules will apply, and removes it.
func UserChangeAdmin ¶
UserChangeAdmin update the admin field for the given user, and change the admin value in user. If user nil, returns fault.ErrUserNil.
If key/name is empty, returns fault.ErrMissingAPIKey/fault.ErrNameEmpty.
If username is taken, returns fault.ErrNameTaken.
func UserChangeKey ¶
UserChangeKey update the API key for the given user, and change the key in user.
If user nil, returns fault.ErrUserNil.
If u.Key/u.Name is empty, returns fault.ErrMissingAPIKey/fault.ErrNameEmpty.
If document not modified returns fault.ErrNotModified.
func UserChangeName ¶
UserChangeName update the name for the given user, and change the name in user.
If user nil, returns fault.ErrUserNil.
If u.Key/u.Name is empty, returns fault.ErrMissingAPIKey/fault.ErrNameEmpty.
If name is taken, returns fault.ErrNameTaken.
func UserCreate ¶
UserCreate creates a new user in the users collection and returns it. The API key automatically generated. If admin is true, the new user will be an admin.
If user name is already taken returns fault.ErrNameTaken error.
If name is empty returns fault.ErrNameEmpty.
func UserDelete ¶
UserDelete delete user based on key+name.
If user not found, returns fault.ErrNameEmpty error.
If key is empty, returns fault.ErrMissingAPIKey error.
If DeleteOne() deletes 0 user, returns fault.ErrUserNotDeleted.
func UserGetKey ¶
UserGetKey returns the user from the db based on API key.
If user not found, returns fault.ErrUserNotFound error.
If key is empty, returns fault.ErrMissingAPIKey error.
func UserGetName ¶
UserGetName returns the user from the db based on name.
If user not found, returns fault.ErrUserNotFound error.
If name is empty, returns fault.ErrNameEmpty error.
Types ¶
This section is empty.