user

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT, MIT Imports: 6 Imported by: 0

README

go-user

供Go语言使用的轻量用户系统

单用户格式化字符串为id:pswd:sl:lc

四个字段的含义为:

字段名 含义
id 用户名
pswd 密码
sl speed limit,该用户的限速(单位:KB/s)
lc login count,该用户的同时登录地限制数

Documentation

Index

Constants

View Source
const (
	// FullMsg 登录数量已满
	FullMsg = "full"
	// FreeMsg 登录数量未满
	FreeMsg = "free"
	// NoLimitMsg 没有登录限制
	NoLimitMsg = "no limit"
)
View Source
const (
	SharedUser  = iota // 0 表示不限制登录
	PrivateUser        // 1 表示只允许一个登录地
)

账户类型,PrivateUser的同时登录地限制为1,而SharedUser则没有限制

Variables

This section is empty.

Functions

This section is empty.

Types

type ReqUser

type ReqUser struct {
	Location string
	// contains filtered or unexported fields
}

ReqUser 请求登录使用的临时用户

func ParseReqUser

func ParseReqUser(userStr, locaction string) (*ReqUser, error)

ParseReqUser 通过字符串创建ReqUser

type ValidUser

type ValidUser struct {
	// contains filtered or unexported fields
}

ValidUser 提供基本和轻量的账户系统 必须使用 ParseValidUser 函数进行构造

func ParseValidUser

func ParseValidUser(userStr string) (validUser *ValidUser, err error)

ParseValidUser 通过格式化的字符串构造新的ValidUser 标准格式化字符串为 id:password:speedlimit:logincount

func (*ValidUser) CheckAuth

func (user *ValidUser) CheckAuth(user2Check *ReqUser) error

CheckAuth 检查请求ValidUser的密码是否正确,并检查是否超出登录限制

func (*ValidUser) Count

func (user *ValidUser) Count() string

Count 以比例的格式输出当前登录地占用状况,如 2/5

func (*ValidUser) SpeedLimiter

func (user *ValidUser) SpeedLimiter() ratelimit.Limiter

SpeedLimiter 该用户的速度控制器

func (*ValidUser) ToString

func (user *ValidUser) ToString() string

ToString 将ValidUser格式化为字符串 只输出ID和密码

Jump to

Keyboard shortcuts

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