models

package
v0.0.0-...-320587e Latest Latest
Warning

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

Go to latest
Published: May 27, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

rpcx服务列表 1. 加载用户关系数据到redis中 2. 新增系统账户,修改系统或者员工角色时,需要修改用户与角色之间的关系

Index

Constants

This section is empty.

Variables

View Source
var (
	METHOD_TYPE_GET    = 10 // GET
	METHOD_TYPE_POST   = 20 // POST
	METHOD_TYPE_PUT    = 30 // PUT
	METHOD_TYPE_PATCH  = 40 // PATCH
	METHOD_TYPE_DELETE = 50 // DELETE
)
View Source
var (
	RootMap map[string]*Tree = map[string]*Tree{
		"GET":    &Tree{Value: -1},
		"POST":   &Tree{Value: -1},
		"PUT":    &Tree{Value: -1},
		"PATCH":  &Tree{Value: -1},
		"DELETE": &Tree{Value: -1},
	}
)
View Source
var (
	WhiteLists []*WhiteListInfo // 白名单信息列表
)

Functions

func AddRoleFunctions

func AddRoleFunctions(funcId int, roleIds []int, o *orm.Ormer) (retCode int, err error)

func AddUserRole

func AddUserRole(userId, roleId int) (id int, retcode int, err error)

func GetFuncId

func GetFuncId(info *HttpRequestInfo) (funcId int, entityStr string, retcode int, err error)

func GetFuncIdsByRoleId

func GetFuncIdsByRoleId(id int) (funcIds []int, retcode int, err error)

根据角色ID, 获取功能ID列表

func GetMethodNameByType

func GetMethodNameByType(methodType int) (methodName string)

根据HTTP方法类型,获取方法名称

func GetMethodTypeByName

func GetMethodTypeByName(methodName string) (methodType int)

根据HTTP方法名,获取方法类型

func GetRoleIdByName

func GetRoleIdByName(name string) (id int, retcode int, err error)

通过角色名称,获取角色ID

func GetRoleIdsByUserId

func GetRoleIdsByUserId(id int) (roleIds []int, retcode int, err error)

根据用户ID,获取角色ID列表 input: @param userId output: @param roleIds

func GetRoleName

func GetRoleName(roles []*Role, roleId int64) (name string, retcode int, err error)

func GetThirdReginMarkKey

func GetThirdReginMarkKey(uri string) (markKey string, retcode int, err error)

解析获取thid_region_mark_key eg. /v1/storages/warehouses/:id/invalid -> :id 错误判断,如果不是以'/'开头,则返回错误

func IsExistInWhiteList

func IsExistInWhiteList(info *HttpRequestInfo) (isInWhiteList bool, retcode int, err error)

func LoadMapTree

func LoadMapTree() (err error)

初始化多叉树, 并把func表数据加载到内存中

func LoadWhiteList

func LoadWhiteList(pageIndex, pageSize int64) (retcode int, err error)

2. 加载白名单列表到内存中

func PrintTree

func PrintTree()

打印树

Types

type Entities

type Entities struct {
	Id        int       `orm:"column(entity_id);auto"`
	RegionId  int       `orm:"column(region_id);null"`
	Name      string    `orm:"column(name);size(300);null"`
	ThirdId   int       `orm:"column(third_id);null"`
	Status    int16     `orm:"column(status);null"`
	UpdatedAt time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt time.Time `orm:"column(created_at);type(datetime);null"`
}

func (*Entities) TableName

func (t *Entities) TableName() string

type FunctionInfos

type FunctionInfos struct {
	Id     int    `json:"function_id"`
	Method string `json:"method"`
	Name   string `json:"name"`
	Uri    string `json:"uri"`
}

func GetFunctions

func GetFunctions(pageIndex int64, pageSize int64, searchKey string) (funcInfos []*FunctionInfos, count int64, realCount int64, retcode int, err error)

获取功能列表与搜索 搜索支持:名称和URI

type Functions

type Functions struct {
	Id                 int       `orm:"column(function_id);auto"`
	Name               string    `orm:"column(name);size(60);null"`
	RegionId           int       `orm:"column(region_id);null"`
	Uri                string    `orm:"column(uri);size(500);null"`
	ThirdRegionMarkKey string    `orm:"column(third_region_mark_key);size(300);null"`
	MethodType         int16     `orm:"column(method_type);null"`
	Status             int16     `orm:"column(status);null"`
	UpdatedAt          time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt          time.Time `orm:"column(created_at);type(datetime);null"`
}

func (*Functions) InsertFunctionNoLock

func (t *Functions) InsertFunctionNoLock(o *orm.Ormer) (retcode int, err error)

func (*Functions) ReadFunctionNoLock

func (t *Functions) ReadFunctionNoLock(o *orm.Ormer) (retcode int, err error)

func (*Functions) TableName

func (t *Functions) TableName() string

func (*Functions) UpdateFunctionNoLock

func (t *Functions) UpdateFunctionNoLock(o *orm.Ormer) (retcode int, err error)

type GrbacServer

type GrbacServer struct{}

func (*GrbacServer) AddUserRole

func (s *GrbacServer) AddUserRole(in *pb.UserRole, out *pb.UserRole) (err error)

func (*GrbacServer) DelUserRole

func (s *GrbacServer) DelUserRole(in *pb.UserRole, out *pb.UserRole) (err error)

func (*GrbacServer) GetRoleByRoleCode

func (s *GrbacServer) GetRoleByRoleCode(in *pb.String, out *pb.Role) (err error)

func (*GrbacServer) LoadGrbacUserRel

func (t *GrbacServer) LoadGrbacUserRel(in *pb.GrbacUserRel, out *pb.GrbacUserRel) (err error)

func (*GrbacServer) ModifyUserRole

func (t *GrbacServer) ModifyUserRole(in *pb.GrbacUserRel, out *pb.GrbacUserRel) (err error)

2. 新增系统账户,修改系统或者员工角色时,需要修改用户与角色之间的关系

type HttpRequestInfo

type HttpRequestInfo struct {
	Body   string `json:"body"`
	Method string `json:"method"`
	Uri    string `json:"uri"`
}

type Regions

type Regions struct {
	Id        int       `orm:"column(region_id);auto"`
	Code      string    `orm:"column(code);size(50);null"`
	Name      string    `orm:"column(name);size(50);null"`
	Status    int16     `orm:"column(status);null"`
	UpdatedAt time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt time.Time `orm:"column(created_at);type(datetime);null"`
}

func (*Regions) TableName

func (t *Regions) TableName() string

type Role

type Role struct {
	RoleId    int       `orm:"column(role_id);auto" json:"role_id"`
	RegionId  int       `orm:"column(region_id);null"`
	Name      string    `orm:"column(name);size(50);null" json:"name"`
	Code      string    `orm:"column(code);size(20);null" json:"code"`
	Status    int16     `orm:"column(status);null"`
	UpdatedAt time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt time.Time `orm:"column(created_at);type(datetime);null"`
}

func GetRoleByRoleCode

func GetRoleByRoleCode(code string, o *orm.Ormer) (role Role, retCode int, err error)

func GetRoles

func GetRoles() (roles []*Role, retcode int, err error)

获取<角色ID, 角色名称> 列表

func (*Role) InsertRoleNoLock

func (t *Role) InsertRoleNoLock(o *orm.Ormer) (retcode int, err error)

func (*Role) ReadRoleNoLock

func (t *Role) ReadRoleNoLock(o *orm.Ormer) (retcode int, err error)

func (*Role) TableName

func (t *Role) TableName() string

func (*Role) UpdateRoleNoLock

func (t *Role) UpdateRoleNoLock(o *orm.Ormer) (retcode int, err error)

type RoleFunctionRelationships

type RoleFunctionRelationships struct {
	Id         int       `orm:"column(role_function_relationship_id);auto"`
	RoleId     int       `orm:"column(role_id);null"`
	FunctionId int       `orm:"column(function_id);null"`
	RegionId   int       `orm:"column(region_id);null"`
	Status     int16     `orm:"column(status);null"`
	UpdatedAt  time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt  time.Time `orm:"column(created_at);type(datetime);null"`
}

func GetRoleFunctions

func GetRoleFunctions(pageIndex int64, pageSize int64, roleId int, searchKey string) (roleFunctions []*RoleFunctionRelationships, count int64, realCount int64, retcode int, err error)

func (*RoleFunctionRelationships) InsertRoleFunctionNoLock

func (t *RoleFunctionRelationships) InsertRoleFunctionNoLock(o *orm.Ormer) (retcode int, err error)

func (*RoleFunctionRelationships) ReadRoleFunctionNoLock

func (t *RoleFunctionRelationships) ReadRoleFunctionNoLock(o *orm.Ormer) (retcode int, err error)

func (*RoleFunctionRelationships) TableName

func (t *RoleFunctionRelationships) TableName() string

func (*RoleFunctionRelationships) UpdateRoleFunctionNoLock

func (t *RoleFunctionRelationships) UpdateRoleFunctionNoLock(o *orm.Ormer) (retcode int, err error)

type Stack

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

func (*Stack) Pop

func (t *Stack) Pop() (elem string, err error)

func (*Stack) Print

func (t *Stack) Print(sep string, funcId int)

func (*Stack) PrintDeTree

func (t *Stack) PrintDeTree(leaf string, sep string, funcId int)

func (*Stack) Push

func (t *Stack) Push(elem string)

type Tree

type Tree struct {
	Trees    []*Tree
	RegMatch *regexp.Regexp
	Name     string // 节点名称
	Value    int    // 节点值, 也称功能ID
}

每个节点由两部分组成:1.非正则;2.正则

type UserRole

type UserRole struct {
	UserRoleId int       `orm:"column(user_role_id);auto" json:"user_role_id"`
	UserId     int       `orm:"column(user_id);null" json:"user_id"`
	RoleId     int       `orm:"column(role_id);null" json:"role_id"`
	RegionId   int       `orm:"column(region_id);null" json:"region_id"`
	Status     int16     `orm:"column(status);null" json:"status"`
	UpdatedAt  time.Time `orm:"column(updated_at);type(datetime);null" json:"updated_at"`
	CreatedAt  time.Time `orm:"column(created_at);type(datetime);null" json:"created_at"`
}

func GetUserRoleByRoleIdAndUserId

func GetUserRoleByRoleIdAndUserId(userId int, roleId int) (userRole *UserRole, retcode int, err error)

func (*UserRole) InsertUserRoleNoLock

func (t *UserRole) InsertUserRoleNoLock(o *orm.Ormer) (retcode int, err error)

func (*UserRole) ReadUserRoleNoLock

func (t *UserRole) ReadUserRoleNoLock(o *orm.Ormer) (retcode int, err error)

func (*UserRole) TableName

func (t *UserRole) TableName() string

func (*UserRole) UpdateUserRoleNoLock

func (t *UserRole) UpdateUserRoleNoLock(o *orm.Ormer) (retcode int, err error)

type UserRoleInfos

type UserRoleInfos struct {
	Mobile                     string `json:"mobile"`
	Name                       string `json:"name"`
	RoleFunctionRelationshipId int64  `json:"role_function_relationship_id"`
	UserId                     int64  `json:"user_id"`
}

func GetUserRoles

func GetUserRoles(pageIndex, pageSize int64, roleId int, searchKey string) (userRoleInfos []*UserRoleInfos, count int64, realCount int64, retcode int, err error)

3. 用户与角色关系列表和搜索 @param page_index: 页码(1+), page_size: 页面大小,role_id:角色ID,search_key={手机号,用户ID} 难点:1. 搜索手机号,跨服务rpc

  1. 手机号或者用户ID,需要组织两个列表,然后求Union集
  2. 分页

type WhiteList

type WhiteList struct {
	Id         int       `orm:"column(white_list_id);auto"`
	Name       string    `orm:"column(name);size(50);null"`
	Url        string    `orm:"column(url);size(100);null"`
	MethodType int16     `orm:"column(method_type);null"`
	Desc       string    `orm:"column(desc);size(300);null"`
	Status     int16     `orm:"column(status);null"`
	UpdatedAt  time.Time `orm:"column(updated_at);type(datetime);null"`
	CreatedAt  time.Time `orm:"column(created_at);type(datetime);null"`
}

func GetWhiteLists

func GetWhiteLists(pageIndex, pageSize int64) (whiteLists []*WhiteList, count int64, realCount int64, retcode int, err error)

func (*WhiteList) InsertWhiteListNoLock

func (t *WhiteList) InsertWhiteListNoLock(o *orm.Ormer) (retcode int, err error)

func (*WhiteList) ReadWhiteListNoLock

func (t *WhiteList) ReadWhiteListNoLock(o *orm.Ormer) (retcode int, err error)

func (*WhiteList) TableName

func (t *WhiteList) TableName() string

func (*WhiteList) UpdateWhiteListNoLock

func (t *WhiteList) UpdateWhiteListNoLock(o *orm.Ormer) (retcode int, err error)

type WhiteListInfo

type WhiteListInfo struct {
	Url     string // /v1/accounts/:id
	Method  string // GET/PUT/POST/...
	Mark    string // 标记例如: :id , :name
	MarkPos int    // :id 的位置:2
}

Jump to

Keyboard shortcuts

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