ab

package module
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ab

  • page 控制页码 page_size 控制条数
    • 最大均为100 100页 100条
  • order(asc) order_desc
  • search搜索 __会被替换为% search=__赵日天 会替换为 %赵日天
  • filter_[字段名] 进行过滤 filter_id=1 最长64位请注意 and关系
  • or_[字段名] 进行过滤 or_id=2 最长64位 or关系

限制

  • 目前不支持header为json的请求 只能是form 受限于iris解析

new version

  • support read write split , use mysql storage and redis read!
  • custom set cache time , hot point set 1 hour cache time .

process

  • read
fetch -> redis -> has -> return
fetch -> redis -> not has -> mysql -> save to redis -> return
  • update
req -> delete redis item -> mysql -> lazy(nms) delete redis item
  • delete
req -> mysql -> delete redis item

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNum

func IsNum(s string) bool

func IsZeroOfUnderlyingType added in v1.1.9

func IsZeroOfUnderlyingType(x interface{}) bool

func LimitHandler added in v1.3.2

func LimitHandler(l *limiter.Limiter, errBack ...func(*errors.HTTPError, iris.Context)) iris.Handler

func Replace added in v1.1.9

func Replace(origin, newData interface{}) error

Types

type Config

type Config struct {
	Party iris.Party
	MysqlInstance
	RedisInstance
	Models     []*SingleModel
	ErrorTrace func(err error, event, from, router string) // error trace func
}

config

type MysqlConfig added in v1.3.0

type MysqlConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	DbName   string
	PoolSize int
	ShowSql  bool
}

type MysqlInstance added in v1.3.0

type MysqlInstance struct {
	MysqlConfig
	Mdb *xorm.Engine
}

type RedisConfig added in v1.3.0

type RedisConfig struct {
	Host     string
	Port     int
	Password string
	Db       int
	PoolSize int
}

type RedisInstance added in v1.3.0

type RedisInstance struct {
	RedisConfig
	Rdb *redis.Client
}

type RestApi added in v1.3.0

type RestApi struct {
	C *Config
}

func New

func New(c *Config) *RestApi

func (*RestApi) AddData added in v1.3.0

func (c *RestApi) AddData(ctx iris.Context)

AddData 新增数据

func (*RestApi) DeleteData added in v1.3.0

func (c *RestApi) DeleteData(ctx iris.Context)

DeleteData 删除数据 /{id:uint64}

func (*RestApi) EditData added in v1.3.0

func (c *RestApi) EditData(ctx iris.Context)

EditData 编辑数据 /{id:uint64}

func (*RestApi) GetAllFunc added in v1.3.0

func (c *RestApi) GetAllFunc(ctx iris.Context)

GetAllFunc 获取所有 page控制页码 page_size控制条数 最大均为100 100页 100条 order(asc) order_desc search搜索 __会被替换为% eg:search=__赵日天 sql会替换为 %赵日天 filter_[字段名] 进行过滤 eg:filter_id=1 and的关系 or_[字段名] 进行过滤 eg:or_id=2 or的关系 使用header的Cache-control no-cache 跳过缓存

func (*RestApi) GetSingle added in v1.3.0

func (c *RestApi) GetSingle(ctx iris.Context)

GetSingle 单个 /{id:uint64}

func (*RestApi) Run added in v1.3.0

func (c *RestApi) Run()

type SingleModel added in v1.1.5

type SingleModel struct {
	Middlewares []context.Handler
	Prefix      string      // 路由前缀
	Suffix      string      // 路由后缀
	Model       interface{} // xorm model

	PrivateContextKey string // 上下文key string int uint
	PrivateColName    string // 数据库字段名 MapName or ColName is ok

	AllowMethods      []string // allow methods first
	DisableMethods    []string // get(all) get(single) post put delete
	AllowSearchFields []string // 搜索的字段 struct名称

	GetAllFunc         func(ctx iris.Context)                                                         // 覆盖获取全部方法
	GetAllResponse     interface{}                                                                    // 获取所有返回的内容替换 仅替换data数组 同名替换
	GetAllResponseFunc func(ctx iris.Context, result iris.Map, dataList []map[string]string) iris.Map // 返回内容替换的方法
	GetAllExtraFilters map[string]string                                                              // 额外的固定过滤 key(数据库列名) 和 value 若与请求过滤重复则覆盖 优先级最高
	GetAllMustFilters  map[string]string                                                              // 获取全部必须拥有筛选

	GetSingleFunc         func(ctx iris.Context)                               // 覆盖获取单条方法
	GetSingleResponse     interface{}                                          // 获取单个返回的内容替换
	GetSingleResponseFunc func(ctx iris.Context, item interface{}) interface{} // 获取单个返回内容替换的方法
	GetSingleExtraFilters map[string]string                                    // 额外的固定过滤 key(数据库列名) 和 value 若与请求过滤重复则覆盖 优先级最高

	PostFunc         func(ctx iris.Context)                               // 覆盖新增方法
	PostValidator    interface{}                                          // 新增自定义验证器
	PostResponseFunc func(ctx iris.Context, item interface{}) interface{} //
	PostResponse     interface{}                                          // 新增返回内容
	PostDataParse    func(ctx iris.Context, raw interface{}) interface{}  //

	PutFunc      func(ctx iris.Context) // 覆盖修改方法
	PutValidator interface{}            // 修改验证器
	PutResponse  interface{}            // 修改返回内容

	DeleteFunc      func(ctx iris.Context) // 覆盖删除方法
	DeleteValidator interface{}            // 删除验证器
	DeleteResponse  interface{}            // 删除返回内容

	CacheTime          time.Duration                          // full cache time
	GetAllCacheTime    time.Duration                          // get all cache time
	GetSingleCacheTime time.Duration                          // get single cache time
	DelayDeleteTime    time.Duration                          // 延迟多久双删 default 500ms
	MaxPageSize        int                                    // max page size limit
	MaxPageCount       int                                    // max page count limit
	RateErrorFunc      func(*tollerr.HTTPError, iris.Context) //
	Rate               *limiter.Limiter                       // all
	GetAllRate         *limiter.Limiter                       //
	GetSingleRate      *limiter.Limiter                       //
	AddRate            *limiter.Limiter                       //
	PutRate            *limiter.Limiter                       //
	DeleteRate         *limiter.Limiter                       //
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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