config

package
v0.2.0-beta5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaseCamel

func CaseCamel(ctx context.Context, table string, column string) string

func CaseCamelUpper

func CaseCamelUpper(ctx context.Context, table string, column string) string

func CaseSnake

func CaseSnake(ctx context.Context, table string, column string) string

func Ori

func Ori(ctx context.Context, table string, column string) string

func RegAccessListProvider

func RegAccessListProvider(name string, provider AccessListProvider)

func RegDbMetaProvider

func RegDbMetaProvider(name string, provider DbMetaProvider)

func RegRequestListProvider

func RegRequestListProvider(name string, provider RequestListProvider)

Types

type Access

type Access struct {
	// 禁用_access权限校验, 默认为false, 需手动开启
	NoVerify bool

	// 用于 根据accessName+user来自定义添加sql条件, 完成数据的权限限制
	ConditionFunc AccessCondition

	// nodeRole 为前端显式指定的role, 需要此函数中判断该role是不是用户角色之一, 返回最终该节点的角色
	DefaultRoleFunc DefaultRole
	// contains filtered or unexported fields
}

func NewAccess

func NewAccess() *Access

func (*Access) AddRole

func (a *Access) AddRole(roles []string) *Access

AddRole 添加应用中额外的角色

func (*Access) GetAccess

func (a *Access) GetAccess(tableAlias string, noVerify bool) (*AccessConfig, error)

func (*Access) GetAccessRole

func (a *Access) GetAccessRole(table string, method string) ([]string, string, error)

func (*Access) RoleList

func (a *Access) RoleList() []string

type AccessCondition

type AccessCondition func(ctx context.Context, req ConditionReq, condition *ConditionRet) error

type AccessConfig

type AccessConfig struct {
	Debug     int8
	Name      string
	Alias     string
	Get       []string
	Head      []string
	Gets      []string
	Heads     []string
	Post      []string
	Put       []string
	Delete    []string
	CreatedAt *gtime.Time
	Detail    string

	RowKeyGen string // 主键生成策略
	RowKey    string
	FieldsGet map[string]*FieldsGetValue
	Executor  string
}

func (*AccessConfig) GetFieldsGetInByRole

func (a *AccessConfig) GetFieldsGetInByRole(role string) map[string][]string

func (*AccessConfig) GetFieldsGetOutByRole

func (a *AccessConfig) GetFieldsGetOutByRole(role string) []string

type AccessListProvider

type AccessListProvider func(ctx context.Context) []AccessConfig

type ActionConfig

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

func (*ActionConfig) ConditionFunc

func (c *ActionConfig) ConditionFunc(ctx context.Context, req ConditionReq, condition *ConditionRet) error

func (*ActionConfig) DefaultRoleFunc

func (c *ActionConfig) DefaultRoleFunc() DefaultRole

func (*ActionConfig) Func

func (c *ActionConfig) Func(name string) Func

func (*ActionConfig) GetAccessConfig

func (c *ActionConfig) GetAccessConfig(key string, noVerify bool) (*AccessConfig, error)

func (*ActionConfig) GetRequest

func (c *ActionConfig) GetRequest(tag string, method string, version string) (*RequestConfig, error)

func (*ActionConfig) NoVerify

func (c *ActionConfig) NoVerify() bool

func (*ActionConfig) RowKeyGen

func (c *ActionConfig) RowKeyGen(ctx context.Context, genFuncName string, accessName string, data model.Map) (model.Map, error)

type Column

type Column struct {
	// 字段名
	Name string
}

type ConditionReq

type ConditionReq struct {
	AccessName          string // _access 中的alias
	TableAccessRoleList []string
	Method              string
	NodeReq             g.Map  //节点的请求数据
	NodeRole            string // 节点的角色
}

type ConditionRet

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

func NewConditionRet

func NewConditionRet() *ConditionRet

func (*ConditionRet) Add

func (c *ConditionRet) Add(k string, v any)

func (*ConditionRet) AddRaw

func (c *ConditionRet) AddRaw(k string, v any)

func (*ConditionRet) Where

func (c *ConditionRet) Where() map[string]any

type Config

type Config struct {
	Access *Access

	Functions *functions

	MaxTreeWidth int
	MaxTreeDeep  int

	// dbFieldStyle 数据库字段命名风格 请求传递到数据库中
	DbFieldStyle FieldStyle

	// jsonFieldStyle 数据库返回的字段
	JsonFieldStyle FieldStyle

	DbMeta *DBMeta

	AccessListProvider  string
	RequestListProvider string
	DbMetaProvider      string
	// contains filtered or unexported fields
}

func New

func New() *Config

func (*Config) ActionConfig

func (c *Config) ActionConfig() *ActionConfig

func (*Config) QueryConfig

func (c *Config) QueryConfig() *QueryConfig

func (*Config) ReLoad

func (c *Config) ReLoad()

func (*Config) RowKeyGen

func (c *Config) RowKeyGen(ctx context.Context, genFuncName string, accessName string, data model.Map) (model.Map, error)

func (*Config) RowKeyGenFunc

func (c *Config) RowKeyGenFunc(name string, f RowKeyGenFuncHandler)

func (*Config) RowKeyGenList

func (c *Config) RowKeyGenList() []string

type DBMeta

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

func NewDbMeta

func NewDbMeta(tables []Table) *DBMeta

func (*DBMeta) GetTableColumns

func (d *DBMeta) GetTableColumns(tableName string) (columns []string)

func (*DBMeta) GetTableNameList

func (d *DBMeta) GetTableNameList() []string

type DbMetaProvider

type DbMetaProvider func(ctx context.Context) []Table

type DefaultRole

type DefaultRole func(ctx context.Context, req RoleReq) (string, error)

type ExecutorConfig

type ExecutorConfig struct {
	NoVerify bool

	DBMeta         *DBMeta
	DbFieldStyle   FieldStyle
	JsonFieldStyle FieldStyle
	// contains filtered or unexported fields
}

func NewExecutorConfig

func NewExecutorConfig(accessConfig *AccessConfig, method string, noVerify bool) *ExecutorConfig

func (*ExecutorConfig) AccessRoles

func (c *ExecutorConfig) AccessRoles() []string

func (*ExecutorConfig) Executor

func (c *ExecutorConfig) Executor() string

func (*ExecutorConfig) GetFieldsGetByRole

func (c *ExecutorConfig) GetFieldsGetByRole() *FieldsGetValue

func (*ExecutorConfig) GetFieldsGetInByRole

func (c *ExecutorConfig) GetFieldsGetInByRole() map[string][]string

func (*ExecutorConfig) GetFieldsGetOutByRole

func (c *ExecutorConfig) GetFieldsGetOutByRole() []string

func (*ExecutorConfig) SetRole

func (c *ExecutorConfig) SetRole(role string)

func (*ExecutorConfig) TableColumns

func (c *ExecutorConfig) TableColumns() []string

func (*ExecutorConfig) TableName

func (c *ExecutorConfig) TableName() string

type FieldStyle

type FieldStyle func(ctx context.Context, table string, column string) string

type FieldsGetValue

type FieldsGetValue struct {
	In       map[string][]string
	Out      map[string]string
	MaxCount *int // 可使用的最大分页大小,默认100
}

type Func

type Func struct {
	ParamList []ParamItem
	Batch     bool // 是否为批量处理, 例如在获取列表后一次性将id传入, 然后按照传入的参数数组返回结果数组
	Handler   func(ctx context.Context, param model.Map) (res any, err error)
}

type ParamItem

type ParamItem struct {
	Type string
	Name string
	Desc string
}

type QueryConfig

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

func (*QueryConfig) DefaultRoleFunc

func (c *QueryConfig) DefaultRoleFunc() DefaultRole

func (*QueryConfig) Func

func (c *QueryConfig) Func(name string) Func

func (*QueryConfig) GetAccessConfig

func (c *QueryConfig) GetAccessConfig(key string, noVerify bool) (*AccessConfig, error)

func (*QueryConfig) MaxTreeDeep

func (c *QueryConfig) MaxTreeDeep() int

func (*QueryConfig) MaxTreeWidth

func (c *QueryConfig) MaxTreeWidth() int

func (*QueryConfig) NoVerify

func (c *QueryConfig) NoVerify() bool

type RequestConfig

type RequestConfig struct {
	Debug     int8
	Version   string
	Method    string
	Tag       string
	Structure map[string]*Structure
	Detail    string
	CreatedAt *gtime.Time
	// 节点执行顺序
	ExecQueue []string
	Executor  map[string]string
}

type RequestConfigs

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

func NewRequestConfig

func NewRequestConfig(requestList []RequestConfig) *RequestConfigs

func (*RequestConfigs) GetRequest

func (c *RequestConfigs) GetRequest(tag string, method string, version string) (*RequestConfig, error)

type RequestListProvider

type RequestListProvider func(ctx context.Context) []RequestConfig

type RoleReq

type RoleReq struct {
	AccessName string
	Method     string
	NodeRole   string // 前端传入的节点的角色, 目前未传入则为空
}

type RowKeyGenFuncHandler

type RowKeyGenFuncHandler func(ctx context.Context, req *RowKeyGenReq, ret *RowKeyGenRet) error

type RowKeyGenReq

type RowKeyGenReq struct {
	AccessName string
	Data       model.Map
}

type RowKeyGenRet

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

func NewRowKeyGenRet

func NewRowKeyGenRet() *RowKeyGenRet

func (*RowKeyGenRet) RowKey

func (r *RowKeyGenRet) RowKey(id any)

func (*RowKeyGenRet) RowKeys

func (r *RowKeyGenRet) RowKeys(d model.Map)

type Structure

type Structure struct {
	Must   []string `json:"MUST,omitempty"`
	Refuse []string `json:"REFUSE,omitempty"`

	Unique []string `json:"UNIQUE,omitempty"`

	// 不存在时添加
	Insert g.Map `json:"INSERT,omitempty"`
	// 不存在时就添加,存在时就修改
	Update g.Map `json:"UPDATE,omitempty"`
	// 存在时替换
	Replace g.Map `json:"REPLACE,omitempty"`
	// 存在时移除
	Remove []string `json:"REMOVE,omitempty"`
}

type Table

type Table struct {
	// 表名
	Name    string
	Columns []Column
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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