user

package module
v0.0.0-...-9ad353d Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: MIT Imports: 2 Imported by: 10

README

User 用户模块

提供一系列与网站用户相关的接口与操作函数

接口

  • 用户帐号接口 Account

使用方式

帐号管理
//Account对象
account:=user.NewAccount()
account.Keyword="keyword"
account.Account="account"

TrueOrFalse:=account.Equal(account2)

//Accounts对象
accounts:=user.NewAccounts()
//绑定帐号。如果帐号已经存在,会返回错误 user.ErrAccountBindingExists
acccounts.Bind(account1)
//解绑帐号。如果帐号不存在,会返回错误 user.ErrAccountUnbindingNotExists
acccounts.Unbind(account1)
//判断帐号是否存在
TrueOrFalse:=accounts.Exist(account1)

//区分大小写的帐号创建器,返回的帐号为"AaBbCc"
account=CaseSensitiveAcountProvider.NewAccount("keyword","AaBbCc")

//不区分大小写的帐号创建器,返回的帐号为"aabbcc"
account=CaseInsensitiveAcountProvider.NewAccount("keyword","AaBbCc")    

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CaseInsensitiveAcountProvider = &PlainAccountProvider{
	Prefix:          "",
	CaseInsensitive: true,
}

CaseInsensitiveAcountProvider plain account provider which case insensitive

View Source
var CaseSensitiveAcountProvider = &PlainAccountProvider{
	Prefix:          "",
	CaseInsensitive: false,
}

CaseSensitiveAcountProvider plain account provider which case sensitive

View Source
var ErrAccountBindingExists = errors.New("account binding exists")

ErrAccountBindingExists error rasied when account exists when binding

View Source
var ErrAccountUnbindingNotExists = errors.New("account unbinding does not exist")

ErrAccountUnbindingNotExists error rasied when account does not exist when unbinding

View Source
var ErrUserExists = errors.New("user exists")

ErrUserExists error raseid when user does exist.

View Source
var ErrUserNotExists = errors.New("user does not exist")

ErrUserNotExists error raseid when user does not exist.

Functions

This section is empty.

Types

type Account

type Account struct {
	//User accont keyword
	Keyword string
	//user account name
	Account string
}

Account user account struct

func NewAccount

func NewAccount() *Account

NewAccount create new account.

func (*Account) Equal

func (a *Account) Equal(account *Account) bool

Equal check if an account is euqal to another.

type AccountProvider

type AccountProvider interface {
	//NewAccount create new account with keyword and account
	NewAccount(keyword string, account string) (*Account, error)
}

AccountProvider account provider interface

type Accounts

type Accounts []*Account

Accounts type account list

func NewAccounts

func NewAccounts() *Accounts

NewAccounts creatre new accounts

func (*Accounts) Bind

func (a *Accounts) Bind(account *Account) error

Bind add account to accountlist. Return any error if raised. If account exists in account list,error ErrAccountBindingExists will be raised.

func (*Accounts) Data

func (a *Accounts) Data() []*Account

Data return account data

func (*Accounts) Exists

func (a *Accounts) Exists(account *Account) bool

Exists check if an account is in account list.

func (*Accounts) Unbind

func (a *Accounts) Unbind(account *Account) error

Unbind remove account from accountlist. Return any error if raised. If account not exists in account list,error ErrAccountUnbindingNotExists will be raised.

type PlainAccountProvider

type PlainAccountProvider struct {
	Prefix          string
	CaseInsensitive bool
}

PlainAccountProvider plain account provider.

func (*PlainAccountProvider) NewAccount

func (p *PlainAccountProvider) NewAccount(keyword string, account string) (*Account, error)

NewAccount create new account is CaseInsensitive is true,account name will be convert to lower

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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