1 Star 0 Fork 2

何吕/volantmq

forked from JUMEI_ARCH/volantmq 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
types.go 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
hawklin 提交于 2018-06-20 17:49 +08:00 . bugfix
package auth
// AccessType acl type
type AccessType int
// Status auth
type Status int
// Error auth provider errors
type Error int
// nolint: golint
const (
AccessTypeRead AccessType = 0x1
AccessTypeWrite = 0x2
AccessTypeAll = 0x3
AccessTypeNone = 0x4
)
// nolint: golint
const (
StatusAllow Status = 0
StatusDeny = 1
StatusNone = 2
)
// nolint: golint
const (
ErrInvalidArgs Error = iota
ErrUnknownProvider
ErrAlreadyExists
ErrNotFound
ErrNotOpen
ErrInternal
)
var errorsDesc = map[Error]string{
ErrInvalidArgs: "auth: invalid arguments",
ErrUnknownProvider: "auth: unknown provider",
ErrAlreadyExists: "auth: already exists",
ErrNotFound: "auth: not found",
ErrNotOpen: "auth: not open",
ErrInternal: "auth: internal error",
}
var statusDesc = map[Status]string{
StatusAllow: "auth status: access granted",
StatusDeny: "auth status: access denied",
}
type UserParam struct {
User string `json:user`
Password string `json:password`
Status string `json:status`
Topic string `json:topic`
Access string `json:access`
}
// Provider interface
type Provider interface {
// Password try authenticate with username and password
Password(string, string) Status
// ACL check access type for client id with username
ACL(id string, username string, topic string, accessType AccessType) Status
ListUsers(handle func(string, string, string, string, string)) error
AddUser(param *UserParam) error
DelUser(user string) error
}
// SessionPermissions check session permissions
type SessionPermissions interface {
ACL(id string, username string, topic string, accessType AccessType) Status
}
// Type return string representation of the type
func (t AccessType) Type() string {
switch t {
case AccessTypeRead:
return "read"
case AccessTypeWrite:
return "write"
}
return ""
}
func (e Error) Error() string {
if s, ok := errorsDesc[e]; ok {
return s
}
return "auth: unknown error"
}
func (e Status) Error() string {
if s, ok := statusDesc[e]; ok {
return s
}
return "auth status: unknown status"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kaifazhe/volantmq.git
git@gitee.com:kaifazhe/volantmq.git
kaifazhe
volantmq
volantmq
v0.0.4

搜索帮助