core

package
v0.0.0-...-95af3ef Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HM_GET  = 10
	HM_POST = 11
	HM_DEL  = 12
)
View Source
const (
	HS_200 = 200
	HS_404 = 404
)
View Source
const MAX_LEVEL = 10

安全模型

Variables

This section is empty.

Functions

func Byte2Int

func Byte2Int(data []byte) int

func CreateUUID

func CreateUUID() string

func GetMd5str

func GetMd5str(value string) string

字符生成md5

func GetNowDate

func GetNowDate() string

func Int2BytesTo

func Int2BytesTo(v int, ret []byte)

func Min

func Min(a, b int) int

func ToDate

func ToDate(t time.Time) string

func ToInt

func ToInt(value string) int64

Types

type AccessContent

type AccessContent struct {
	Remote    string     //记录访问网站的客户端地址
	TimeStart time.Time  //记录访问时间
	Request   string     //用户的http请求起始行信息
	BodySent  int64      //服务器发送给客户端的响应body字节数
	Status    HttpStatus //http状态码,记录请求返回的状态码,例如:200、301、404等
	Referer   string     //记录此次请求是从哪个连接访问过来的,可以根据该参数进行防盗链设置。
	Url       string     //访问的URL地址
	Method    HttpMethod //访问的方法 GET POST DELETE
	Agent     string     //记录客户端访问信息,例如:浏览器、手机客户端等
	TimeEnd   time.Time  //记录访问结束时间
}

访问日志

type AccessLogger

type AccessLogger interface {
	//服务访问
	ToAccess(content *AccessContent)
	//服务访问错误信息记录
	ToError(e *ErrorContent)

	WriteTextToAccess(text string)
}

type AccessToken

type AccessToken struct {
	Id         string
	User       string
	CreateTime int64
	Role       string
}

访问token

func (*AccessToken) IsExpire

func (this *AccessToken) IsExpire(expire int64) bool

func (*AccessToken) Validate

func (this *AccessToken) Validate(value string) bool

校验token

type Application

type Application interface {
	ReloadAuth()     //重新加载权限
	Restart()        //重启
	ShutdownNotify() //关闭通知
	PauseService()
	RestoreService()
	ReloadConfig()
	ReloadApis()
}

应用接口

type AuthClass

type AuthClass struct {
	Code   string                //权限类名
	Fields map[string]*AuthField //权限字段
}

权限类,模板

func CreateAuthClass

func CreateAuthClass(c string) *AuthClass

func (*AuthClass) AddField

func (this *AuthClass) AddField(f *AuthField)

func (*AuthClass) AddFieldByParame

func (this *AuthClass) AddFieldByParame(name, desc string, t FieldType)

type AuthField

type AuthField struct {
	Code string    //字段ID
	Desc string    //描述
	Type FieldType //类型
}

权限字段

func (*AuthField) ToString

func (this *AuthField) ToString(o interface{}) string

type AuthFieldValue

type AuthFieldValue struct {
	Field  *AuthField //字段名称
	Type   ValueType  //取值类型:单值、区间、枚举
	Value  string     //取值范围
	Values []string
}

权限值

func (*AuthFieldValue) Validate

func (this *AuthFieldValue) Validate(v string) bool

type Authobject

type Authobject struct {
	Reverse bool //反向,取反。
	Values  []*AuthFieldValue
}

权限对象

func (*Authobject) Validate

func (this *Authobject) Validate(obj map[string]string) bool

type AuthobjectSet

type AuthobjectSet struct {
	Class         *AuthClass
	Objects       []*Authobject
	ReverseObject []*Authobject
}

权限对象集合

func (*AuthobjectSet) AddAuthObject

func (this *AuthobjectSet) AddAuthObject(reverse bool, values []*AuthFieldValue)

func (*AuthobjectSet) BuildFieldValue

func (this *AuthobjectSet) BuildFieldValue(name string, t ValueType, v string) *AuthFieldValue

func (*AuthobjectSet) Validate

func (this *AuthobjectSet) Validate(key string, obj map[string]string) bool

type DefaultRoleMetaManager

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

func (*DefaultRoleMetaManager) AddRole

func (this *DefaultRoleMetaManager) AddRole(r *Role)

func (*DefaultRoleMetaManager) FindRole

func (this *DefaultRoleMetaManager) FindRole(name string) *Role

type ErrorContent

type ErrorContent struct {
	AccessContent
	ErrorCode    string //错误码
	ErrorMessage string //错误消息内容
	Descript     string //返回结果摘要
}

type FieldType

type FieldType byte

字段类型

const (
	FT_STRING FieldType = 1 //字符
	FT_INT    FieldType = 2 //整数
	FT_DATE   FieldType = 3 //日期
)

type HttpMethod

type HttpMethod byte

http 访问方法

type HttpStatus

type HttpStatus int

http 状态

type Logger

type Logger interface {
}

type Role

type Role struct {
	SuperRole *Role  //继承的角色
	Code      string //角色名称
	// contains filtered or unexported fields
}

角色

func (*Role) AddAuthObjectSet

func (this *Role) AddAuthObjectSet(set *AuthobjectSet)

增加权限集

func (*Role) Validate

func (this *Role) Validate(key string, obj map[string]string, level int32) bool

func (*Role) ValidateSelf

func (this *Role) ValidateSelf(key string, obj map[string]string) bool

type RoleManager

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

角色管理

func (*RoleManager) SetMetaManager

func (this *RoleManager) SetMetaManager(m RoleMetaManager)

func (*RoleManager) Validate

func (this *RoleManager) Validate(rolename string, key string, obj map[string]string) bool

type RoleMetaManager

type RoleMetaManager interface {
	FindRole(name string) *Role
}

元模型管理接口

type TokenManager

type TokenManager struct {
	Expire int64 //过期时间
	Store  TokenStore
}

func (*TokenManager) CreateToken

func (this *TokenManager) CreateToken(user string, role string) (*AccessToken, string)

func (*TokenManager) GetToken

func (this *TokenManager) GetToken(id string) *AccessToken

type TokenStore

type TokenStore interface {
	//获取token
	GetToken(id string) *AccessToken
	//保存token
	SaveToken(id string, t *AccessToken, expire int64)
}

type ValueType

type ValueType byte

值类型

const (
	VT_SINGLE ValueType = 1 //单值
	VT_RANGE  ValueType = 2 //区间
	VT_SET    ValueType = 3 //集合(枚举)
)

Jump to

Keyboard shortcuts

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