frame

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DIR_CONFIG  = "./config"
	DIR_RUNTIME = "./runtime"
	DIR_LOGS    = "./logs"
)
View Source
const (
	CODE_ERROR = 510 //错误但不致命
	CODE_SQL   = 511 //sql错误
	CODE_FATAL = 512 //致命错误
	CODE_WARN  = 600 //错误警告3
)

错误代号[600以下的保存到日志,600以上的不保存]

View Source
const (
	VERSION = "1.0.24"
)

Variables

This section is empty.

Functions

func CheckSqlError

func CheckSqlError(err error)

Types

type AppInterface

type AppInterface interface {
	Init(*WebEngine)                                     //站点初始化执行方法(可以放一些中间件处理的东西)
	Config() any                                         //配置文件路径
	Modules() []ModuleInterface                          //加载需要的模块
	Install() error                                      //安装入口
	CheckPermission(webline *Webline, code, name string) //权限验证
	Version() string                                     //当前版本号
}

应用接口

type BaseQuery

type BaseQuery struct {
	Page  int `bind:"page" form:"page"`
	Limit int `bind:"limit" form:"limit"`
}

查询结构

type ComponentInterface

type ComponentInterface interface {
	CompName() string         //组件名称
	Models() []ModelInterface //数据库模型
}

组件接口

type ConfigInterface

type ConfigInterface interface {
	Default() ConfigInterface //默认配置
	BeforeGet()               //请求前
	ConfigName() string       //配置名称
	ConfigAlias() string      //配置别名
	Validate() error          //验证
}

配置接口

type Configer

type Configer interface {
	Config() ConfigInterface
}

type CrontabInterface

type CrontabInterface interface {
	Name() string      //任务名称
	Schedule() string  //定时时间表达式
	Handler(*Taskline) //执行方法
}

定时任务接口

type EventInterface

type EventInterface interface {
	HookCode() string                       //钩子代号,必须对应
	Handler(m *Taskline, arg HookInterface) //事件处理方法
}

事件接口

type HandlerFunc

type HandlerFunc = func(*Webline)

type HookInterface

type HookInterface interface {
	HookName() string //钩子名称
	HookCode() string //钩子代号
}

钩子接口

type LogLevel

type LogLevel int
const (
	LOG_DEBUG LogLevel = iota
	LOG_INFO
	LOG_WARNING
	LOG_ERR
	LOG_OFF
	LOG_UNKNOWN
)

type Logger

type Logger interface {
	Save()
}

日志处理器接口

type MaoConfigInterface

type MaoConfigInterface interface {
	Section(name string) *ini.Section
	Get(c ConfigInterface) ConfigInterface
	GetByAlias(alias string) ConfigInterface
	Save(confPtr ConfigInterface)
}

type MaoLogInterface

type MaoLogInterface interface {
	Debug(v ...any)
	Warn(v ...any)
	Info(v ...any)
	Error(v ...any)
	Debugf(format string, v ...any)
	Warnf(format string, v ...any)
	Infof(format string, v ...any)
	Errorf(format string, v ...any)
}

type Model

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

orm结构体集成该属性可以进行相关操作

func (*Model) Alias

func (this *Model) Alias(alias string) string

表别名

func (*Model) Cols

func (this *Model) Cols(cols ...string) *Model

指定添加修改的字段

func (*Model) Create

func (this *Model) Create() bool

添加数据

func (*Model) Delete

func (this *Model) Delete() bool

删除数据(只针对主键id删除)

func (*Model) Exists

func (this *Model) Exists() bool

是否存在

func (*Model) Get

func (this *Model) Get() bool

查询数据信息(根据ID)

func (*Model) Match

func (this *Model) Match(column string, data any) *Model

根据指定字段获取对象

func (*Model) Must

func (this *Model) Must(cols ...string) *Model

必须有的字段,比如age=0会强制写入数据库

func (*Model) Omit

func (this *Model) Omit(cols ...string) *Model

忽略添加修改的字段

func (*Model) SetData

func (this *Model) SetData(data any) *Model

对data进行增删改查,优先于this.object

func (*Model) SetTableName

func (this *Model) SetTableName(tableName string)

设置表名

func (*Model) TableName

func (this *Model) TableName() string

表名

func (*Model) Update

func (this *Model) Update() bool

修改数据

func (*Model) Where

func (this *Model) Where(query string, args ...any) *Model

使用条件查询

type ModelInterface

type ModelInterface interface {
	TableName() string
	PrimaryKey() any     //主键
	SetTableName(string) //设置表名
	// contains filtered or unexported methods
}

模型接口

type Module

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

任务线包装,用给模块组合使用

func (*Module) SetTaskline

func (this *Module) SetTaskline(t *Taskline)

func (*Module) Taskline

func (this *Module) Taskline() *Taskline

type ModuleInterface

type ModuleInterface interface {
	Install()                         //执行安装操作
	ModuleName() string               //模块名称
	Enable() bool                     //是否启用,为false时自动限制接口访问
	Init(*WebEngine)                  //模块初始化,此处可放置路由
	Crontabs() []CrontabInterface     //定时任务
	Components() []ComponentInterface //组件
	Hooks() []HookInterface           //钩子列表(注册后的事件才能使用)
	Events() []EventInterface         //事件列表(自动寻找对应钩子)
}

模块接口

type NoWebInterface added in v1.0.19

type NoWebInterface interface {
	NoWeb()
}

不启动web服务

type Permission

type Permission struct {
	Name   string        `json:"name"`
	Id     string        `json:"id"`
	Childs []*Permission `json:"childs"`
	Pid    string        `json:"pid"`
}

权限输出

type Router

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

func (*Router) Permission

func (this *Router) Permission(name string, codes ...string)

权限配置使用

type RouterGroup

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

func (*RouterGroup) Any

func (this *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) *Router

func (*RouterGroup) DELETE

func (this *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) *Router

func (*RouterGroup) GET

func (this *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) *Router

GET请求

func (*RouterGroup) Group

func (this *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup

func (*RouterGroup) POST

func (this *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) *Router

func (*RouterGroup) PUT

func (this *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) *Router

func (*RouterGroup) Permission

func (this *RouterGroup) Permission(name string, code ...string) *RouterGroup

权限配置使用

func (*RouterGroup) Use

func (this *RouterGroup) Use(middleware ...HandlerFunc)

type RunMode added in v1.0.3

type RunMode string

运行模式

const (
	RUN_MODE_DEVELOP RunMode = "dev" //开发者模式下会输入日志内容
	RUN_MODE_PRODUCT RunMode = "prod"
)

运行模式

type Server

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

func NewServer

func NewServer(app AppInterface) *Server

func (*Server) GetComponents

func (this *Server) GetComponents() []ComponentInterface

获取所有组件

func (*Server) GetModules

func (this *Server) GetModules() []ModuleInterface

获取所有模块

func (*Server) InstallModule added in v1.0.6

func (this *Server) InstallModule(module ModuleInterface)

安装模块的数据库

func (*Server) LoadModule added in v1.0.6

func (this *Server) LoadModule(module ModuleInterface)

加载模块路由,定时任务等

func (*Server) RemoveModule added in v1.0.6

func (this *Server) RemoveModule()

删除模块(待开发)

func (*Server) Run

func (this *Server) Run()

启动服务

func (*Server) TaskLine added in v1.0.17

func (this *Server) TaskLine() *Taskline

type SetSetTaskLiner

type SetSetTaskLiner interface {
	SetTaskline(*Taskline)
}

任务线处理器

type Taskline

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

func (*Taskline) Config added in v1.0.23

func (this *Taskline) Config() MaoConfigInterface

获取配置对象

func (*Taskline) FindPage

func (this *Taskline) FindPage(db *xorm.Session, listPtr interface{}, page, limit int) int64

分页查询 listPtr = 查询列表指针 page = 页码 limit = 每页查询数量 返回查询总数

func (*Taskline) GetTaskid added in v1.0.3

func (this *Taskline) GetTaskid() int64

获取当前taskline的id

func (*Taskline) LogDebug added in v1.0.18

func (this *Taskline) LogDebug(args ...any)

调试日志输出

func (*Taskline) LogDebugf added in v1.0.18

func (this *Taskline) LogDebugf(format string, args ...any)

调试日志输出,可格式化

func (*Taskline) LogError added in v1.0.18

func (this *Taskline) LogError(args ...any)

错误日志输出

func (*Taskline) LogErrorf added in v1.0.18

func (this *Taskline) LogErrorf(format string, args ...any)

错误日志输出,可格式化

func (*Taskline) LogInfo added in v1.0.18

func (this *Taskline) LogInfo(args ...any)

信息日志输出

func (*Taskline) LogInfof added in v1.0.18

func (this *Taskline) LogInfof(format string, args ...any)

信息日志输出,可格式化

func (*Taskline) LogWarn added in v1.0.18

func (this *Taskline) LogWarn(args ...any)

警告日志输出

func (*Taskline) LogWarnf added in v1.0.18

func (this *Taskline) LogWarnf(format string, args ...any)

警告日志输出,可格式化

func (*Taskline) Mutex

func (this *Taskline) Mutex() *sync.Mutex

当前请求的互斥锁

func (*Taskline) NewTaskLine

func (this *Taskline) NewTaskLine() *Taskline

新建一个任务线

func (*Taskline) OrmModel

func (this *Taskline) OrmModel(model ModelInterface) ModelInterface

实例化一个对象【泛型】

func (*Taskline) OrmSession

func (this *Taskline) OrmSession() *xorm.Session

ORM对象,

func (*Taskline) OrmTable

func (this *Taskline) OrmTable(bean any) *xorm.Session

初始化数据库模型

func (*Taskline) PutHook

func (this *Taskline) PutHook(h HookInterface)

放置钩子

func (*Taskline) RenderConfig

func (this *Taskline) RenderConfig(conf ConfigInterface) ConfigInterface

根据配置接口读取配置信息

func (*Taskline) Transaction

func (this *Taskline) Transaction(fn func())

开启事务,只执行最上面层的事务

func (*Taskline) UseEngine added in v1.0.18

func (this *Taskline) UseEngine(engine *xorm.Engine)

设置ORM数据库引擎,用于多数据库连接的时候

type WebEngine

type WebEngine struct {
	RouterGroup
}

func (*WebEngine) Engine

func (this *WebEngine) Engine() *gin.Engine

func (*WebEngine) MiddleSign

func (this *WebEngine) MiddleSign() HandlerFunc

签名中间件 计算规则 sign=SHA256()

type Webline

type Webline struct {
	*Taskline
	*gin.Context //上下文
	// contains filtered or unexported fields
}

func (*Webline) BindCookie

func (this *Webline) BindCookie(objectPtr interface{})

绑定cookie

func (*Webline) BindForm

func (this *Webline) BindForm(objectPtr interface{})

绑定form

func (*Webline) BindJSON

func (this *Webline) BindJSON(objectPtr interface{})

绑定json

func (*Webline) BindQuery

func (this *Webline) BindQuery(objectPtr interface{})

绑定query

func (*Webline) GetPermissionList

func (this *Webline) GetPermissionList() []*Permission

获取所有权限列表

func (*Webline) GetRouterName added in v1.0.20

func (this *Webline) GetRouterName() string

获取路由名称

func (*Webline) IsMobile

func (this *Webline) IsMobile() bool

是否为移动端

func (*Webline) JSON

func (this *Webline) JSON(code int32, result any, msg ...any)

JSON数据输出

Jump to

Keyboard shortcuts

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