lego

package module
v0.0.0-...-5e78559 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: GPL-3.0 Imports: 27 Imported by: 0

README

lego

Documentation

Index

Constants

View Source
const (
	// HTTP配置-固定常量
	K_GGF_CONFIG_HTTP_SECTION = "HTTP"
	K_GGF_CONFIG_HTTP_DOMAIN  = "DOMAIN"
	K_GGF_CONFIG_HTTP_PORT    = "PORT"
	// 代码配置-固定常量
	K_GGF_CONFIG_CODE_SECTION         = "CODE"
	K_GGF_CONFIG_CODE_PROJNAME        = "PRJNAME"
	K_GGF_CONFIG_CODE_PRJPREX         = "PRJPREX"
	K_GGF_CONFIG_CODE_TOKEN_SECRETKEY = "TOKEN_SECRETKEY"
	K_GGF_CONFIG_CODE_REQ_SIGNKEY     = "REQ_SIGNKEY"
	// 数据库配置
	K_GGF_CONFIG_DB_SECTION = "DATABASE"
	K_GGF_CONFIG_DB_MASTER  = "MASTER_DB"
	// 授权相关
	K_GGF_CONFIG_AUTH_SECTION  = "AUTH"
	K_GGF_CONFIG_AUTH_LOGINURL = "LOGINURL"
)
View Source
const (
	TOKEN_EXPIRE_CODE = 10001
)

Variables

This section is empty.

Functions

func APIGET

func APIGET(path string, h fasthttp.RequestHandler, checktoken bool)
注册路由,GET的方式
  • parmas @path -- 访问路径 @h -- 处理handler @checktoken -- 是否校验token @checktoken -- 是否校验资源权限 @checkip -- 是否检查调用方ip

func APIGETWITHOUTSIGN

func APIGETWITHOUTSIGN(path string, h fasthttp.RequestHandler)

一些默认不需要签名的接口

func APIPOST

func APIPOST(path string, h fasthttp.RequestHandler, checktoken bool)
注册路由,Post的方式
  • parmas @path -- 访问路径 @h -- 处理handler @checktoken -- 是否校验token

func APIPOSTWITHOUTSIGN

func APIPOSTWITHOUTSIGN(path string, h fasthttp.RequestHandler)

一些默认不需要签名的接口

func APIPOSTv2

func APIPOSTv2(path string, fn interface{}, checktoken bool)

func AddBeanToSynList

func AddBeanToSynList(bean interface{})

/* 把要同步的表结构,传到初始化列表里面 */

func BuildSqlByQueryMap

func BuildSqlByQueryMap(qmap map[string]interface{}) (string, string, []interface{}, error)

内部功能函数-组装mysql 语句

func DBEngineClose

func DBEngineClose()

func DoSynBeans

func DoSynBeans(sourceName string)

同步数据库

func GET

func GET(path string, h fasthttp.RequestHandler, checksession bool)
注册路由,GET的方式
  • parmas @path -- 访问路径 @h -- 处理handler @checktoken -- 是否校验token

func GetDBEngine

func GetDBEngine() *xorm.EngineGroup

获取数据库引擎对象

func GetDBEngineByName

func GetDBEngineByName(sourceName string) *xorm.EngineGroup

按名字,获取数据库引擎对象

func GetIniByKey

func GetIniByKey(section string, key string) string

* env

func GetIniByKeyWithReload

func GetIniByKeyWithReload(section string, key string, reloadini bool) string

* 有时候改了配置,想不重启的情况,调用这个

func GetRedisConn

func GetRedisConn() (redis.Conn, error)
获取Redis连接
  • params: ---

func GetRequestHandler

func GetRequestHandler(ctx *fasthttp.RequestCtx)

func GetRouter

func GetRouter() *fasthttprouter.Router

获取httprouter指针

func GetSqlByCondition

func GetSqlByCondition(cond *QryConditions) (string, []interface{}, error)

* 从condition对象中拼接sql

func GetSqlByConditionGroup

func GetSqlByConditionGroup(condlist []QryConditions) (string, []interface{}, error)

* 从condition对象组中拼接sql

func GetSqlByWhereFeildList

func GetSqlByWhereFeildList(wheremap []QMapWhereField) (string, []interface{}, error)

* 从field列表中获取,该条件组条件的sql及参数

func GetSyncModelBeanlist

func GetSyncModelBeanlist() []interface{}

获取结构列表

func GetUserIdFromToken

func GetUserIdFromToken(passToken string) (uid int64, err error)

JWT-中间件 * GetUserIdFromToken * 从jwt字符串中解析获得userid

func LoadConfigFrom

func LoadConfigFrom(fname string)

func ModuleRegist

func ModuleRegist(m GGModule)

func POST

func POST(path string, h fasthttp.RequestHandler, checksession bool)
注册路由,POST的方式
  • parmas @path -- 访问路径 @h -- 处理handler @checktoken -- 是否校验token

func POSTv2

func POSTv2(path string, fn interface{}, checksession bool)

*params

@fn -- 指向一个函数的interface类型,
       此函数第一个参数必须是fasthttp.RequestCtx类型,
       第二个参数为承载在body里面json格式数据的对象

处理逻辑 1. 先通过反射,将fn的类型信息查询出来 2. 根据fn的类型信息,判断第一个参数必须是fasthttp.RequestCtx类型,第二个参数是Args,既body里面的数据类型 3. 通过反射,将Args的类型信息提取出来,用于在Unmarshal()中将body里面的数据解析出来

example: lego.POSTv2("/admin/Test_mode/editpage2", vc.ListJson2, lego.LEGO_SESSION_YPE_ADMIN, false)

func (vc *Test_modeCtrl) ListJson2(Ctx *fasthttp.RequestCtx, Args *Args) {
    fmt.Printf("ListJson2: %v", Args)
}

func QueryListByMap

func QueryListByMap(qmap map[string]interface{}) ([]map[string]string, int64, error)

*******************************************************************************************

构建sql语句

func RedisDeleteKey

func RedisDeleteKey(key string) (int, error)

* 再多封装一次,DEL的用法.

func RedisGeoAdd

func RedisGeoAdd(key string, lat, lng float64, id string) (int, error)

GEO 相关

func RedisGeoDist

func RedisGeoDist(key, id1, id2 string) (string, error)

func RedisGeoPos

func RedisGeoPos(key, id string) (lat, lng float64, err error)

func RedisGeoRadius

func RedisGeoRadius(key string, lat, lng float64, radius int) ([]string, error)

半径内元素个数

func RedisGeoRemove

func RedisGeoRemove(setkey string, members ...string) (int, error)

* SET集合删除成员

func RedisGetKey

func RedisGetKey(key string) (string, error)

* 再多封装一次,get、set的用法.

func RedisKeyExists

func RedisKeyExists(key string) (int, error)

* 再多封装一次,查key是否存在的用法.

func RedisListLPush

func RedisListLPush(key string, val interface{}) (int, error)

列表相关

func RedisListLen

func RedisListLen(key string) (int, error)

func RedisListRPush

func RedisListRPush(key string, val interface{}) (int, error)

func RedisListRange

func RedisListRange(key string, begin, end int) ([]string, error)

func RedisPublish

func RedisPublish(chenel, message string) (int, error)

* 发布及订阅者模式

func RedisSETNX

func RedisSETNX(key, val string) (int, error)

* 分布式锁

func RedisSetAdd

func RedisSetAdd(setkey string, members ...string) (int, error)

* SET集合设置成员

func RedisSetExist

func RedisSetExist(setkey string, member string) (bool, error)

* SET集合-- 判断元素是否在集合中

func RedisSetKey

func RedisSetKey(key, value, expiretime string, ifexpire bool) (string, error)

* 再多封装一次,get、set的用法.

func RedisSetMemberCount

func RedisSetMemberCount(setkey string) (int, error)

* SET集合元素个数

func RedisSetMultiKey

func RedisSetMultiKey(key, value []string) (string, error)

* 一次性设置多个key、val.

func RedisSetRemove

func RedisSetRemove(setkey string, members ...string) (int, error)

* SET集合删除成员

func RedisSetSDIFF

func RedisSetSDIFF(setkey1, setkey2 string) ([]string, error)

* SET集合-- 2个集合的差集

func RedisSetScan

func RedisSetScan(setkey string) ([]string, error)

* SET集合元素读取(所有元素)

func RedisSetSinter

func RedisSetSinter(setkey1, setkey2 string) ([]string, error)

* SET集合-- 2个集合的交集

func SessionGetKeyIntVal

func SessionGetKeyIntVal(key string, ctx *fasthttp.RequestCtx) int64

通过content获取user_id

func SessionGetKeyStringVal

func SessionGetKeyStringVal(key string, ctx *fasthttp.RequestCtx) string

通过content获取user_id

func SetUpSourceDatabase

func SetUpSourceDatabase(dbtype, sourceName string, dbUrls []string, prefix, isdefault bool)

func ShowSysModules

func ShowSysModules()

显示加载了那些模块

func SignKey

func SignKey() string

func TokenPrefix

func TokenPrefix() string

func TokenSecretKey

func TokenSecretKey() string

func UUID

func UUID() int64

* 分布式-雪花uuid

func UUIDWithNoteId

func UUIDWithNoteId(nid int64) int64

* 分布式-雪花uuid

func Validate

func Validate(form interface{}) error

* 提供给外部的表单验证接口

func WEBSOCKET

func WEBSOCKET(path string, h fasthttp.RequestHandler)
websocket,注册
  • parmas @path -- 访问路径 @h -- 处理handler @checktoken -- 是否校验token

Types

type GGModule

type GGModule interface {
	Name() string
	Version() string
	Info() string
}

type QMapWhereField

type QMapWhereField struct {
	FieldName   string
	Opt         string
	Param       interface{}
	CombineWith string // AND OR
	OmitEmpty   bool   // 是否忽略空或0值
}

查询where字段参数类定义

type QryConditions

type QryConditions struct {
	CombineWith string // AND OR
	FieldList   []QMapWhereField
}

func NewQryConditions

func NewQryConditions() QryConditions

func (*QryConditions) AddFeild

func (obj *QryConditions) AddFeild(field QMapWhereField)

type RedisHelper

type RedisHelper struct {
}

type RequestCtxExtent

type RequestCtxExtent struct {
	*fasthttp.RequestCtx
}

func (*RequestCtxExtent) JSON

func (self *RequestCtxExtent) JSON(code int, dataMap map[string]interface{})
输出json
  • @parsm code --- 错误码 data --- 数据

func (*RequestCtxExtent) Peek

func (self *RequestCtxExtent) Peek(key string) []byte
获取参数
  • @parsm code --- 错误码 data --- 数据

func (*RequestCtxExtent) PureHTML

func (self *RequestCtxExtent) PureHTML(fpath string)
********************************************
HTML
  • @parsm name --- 文件路径

func (*RequestCtxExtent) XML

func (self *RequestCtxExtent) XML(dataMap map[string]string)
输出xml
  • @parsm code --- 错误码 data --- 数据

type Server

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

* 服务器类封装

func (*Server) Shutdown

func (sv *Server) Shutdown() error

* 关闭服务

  • params
  • @port -- 端口号

func (*Server) Start

func (sv *Server) Start(port, appname string) error

* 启动服务

  • params
  • @port -- 端口号

func (*Server) Static

func (sv *Server) Static(prefix, root string)
  • 设置静态文件访问路径及文件根目录
  • params @prefix -- 静态资源访问路由前缀 @root -- 存放文件的系统跟目录

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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