Documentation ¶
Overview ¶
Package ogo provides ...
Package ogo provides ...
解析http请求的各种条件
Index ¶
- Constants
- Variables
- func Accessor() *logs.OLogger
- func AddTagHook(tag string, hook TagHook)
- func AddWorker(w WorkerInterface)
- func CacheGet(key string) (string, error)
- func CacheIncrByFloat(key string, value float64) error
- func CacheSet(key, value string, expire int) error
- func ClusterClient() *redis.ClusterClient
- func Config() config.ConfigContainer
- func Critical(format string, v ...interface{})
- func Debug(format string, v ...interface{})
- func Defer(c *web.C, h http.Handler) http.Handler
- func EnvInit(c *web.C, h http.Handler) http.Handler
- func Error(format string, v ...interface{})
- func GetDbFields(i interface{}, ops ...interface{}) (s []string)
- func GetLock(key string) (string, error)
- func GetSumFields(i interface{}, g []string) (s string)
- func Info(format string, v ...interface{})
- func Log(level, format string, v ...interface{})
- func Logger() *logs.OLogger
- func OmqBlockTask(msg ...string) (string, error)
- func OmqDel(key string) (string, error)
- func OmqGet(key string) (string, error)
- func OmqPool() *omq.Pool
- func OmqPop(msg ...string) ([]string, error)
- func OmqSet(key, value string, expire int) error
- func OmqTask(msg ...string) error
- func OpenDB(tag, dns string) (err error)
- func ParseHeaders(c *web.C, h http.Handler) http.Handler
- func ParseParams(c *web.C, h http.Handler) http.Handler
- func PostHook(hook OgoHook)
- func PreHook(hook OgoHook)
- func ReleaseLock(key string) error
- func Run()
- func SetOnlineKey(id, key string, p interface{}) bool
- func Trace(format string, v ...interface{})
- func Warn(format string, v ...interface{})
- func WriteMsg(v ...interface{})
- type Access
- type ActionInterface
- type Aggregation
- type Aggregations
- type AppLog
- type BaseConverter
- type BaseModel
- func (bm *BaseModel) AddTable(tags ...string)
- func (bm *BaseModel) CheckerFactory() Checker
- func (bm *BaseModel) CreateRow() (Model, error)
- func (bm *BaseModel) DBConn(tag string) *gorp.DbMap
- func (bm *BaseModel) DeleteRow(id string) (affected int64, err error)
- func (bm *BaseModel) Fill(j []byte) error
- func (bm *BaseModel) Filter() (Model, error)
- func (bm *BaseModel) GetChecker() Checker
- func (bm *BaseModel) GetConditions() []*Condition
- func (bm *BaseModel) GetCount() (cnt int64, err error)
- func (bm *BaseModel) GetCountNSum() (cnt int64, sum float64)
- func (bm *BaseModel) GetCtx() *RESTContext
- func (bm *BaseModel) GetFields() []string
- func (bm *BaseModel) GetModel() Model
- func (bm *BaseModel) GetOlder() Model
- func (bm *BaseModel) GetPagination() *Pagination
- func (bm *BaseModel) GetRow(ext ...interface{}) (Model, error)
- func (bm *BaseModel) GetRows() (l *List, err error)
- func (bm *BaseModel) GetSum(d []string) (l *List, err error)
- func (bm *BaseModel) New(c ...interface{}) Model
- func (bm *BaseModel) NewList() interface{}
- func (bm *BaseModel) PKey() (f string, v string, ai bool)
- func (bm *BaseModel) Protect() (Model, error)
- func (bm *BaseModel) ReadPrepare() (b *gorp.Builder, err error)
- func (bm *BaseModel) SetConditions(cs ...*Condition) (cons []*Condition, err error)
- func (bm *BaseModel) SetCtx(c *RESTContext)
- func (bm *BaseModel) SetFields(fs []string)
- func (bm *BaseModel) SetModel(m Model) Model
- func (bm *BaseModel) SetPagination(p *Pagination)
- func (bm *BaseModel) TableName() (n string)
- func (bm *BaseModel) UpdateRow(ext ...interface{}) (affected int64, err error)
- func (bm *BaseModel) Valid() (Model, error)
- type Checker
- type Condition
- type Environ
- type HStack
- type HTTPLog
- type Handler
- type List
- type ListInfo
- type Lock
- type Model
- type Mux
- func (mux *Mux) Accessor() (*logs.OLogger, error)
- func (mux *Mux) AddTagHook(tag string, hook TagHook)
- func (mux *Mux) ClusterClient() (*redis.ClusterClient, error)
- func (mux *Mux) Config() (config.ConfigContainer, error)
- func (mux *Mux) Env() (*Environ, error)
- func (mux *Mux) Logger() (*logs.OLogger, error)
- func (mux *Mux) NewRouter(c interface{}, endpoint string) RouterInterface
- func (mux *Mux) OmqPool() (*omq.Pool, error)
- func (mux *Mux) PostHook(hook OgoHook)
- func (mux *Mux) PreHook(hook OgoHook)
- func (mux *Mux) Run()
- type OTPSpec
- type OgoHook
- type Online
- type OnlineMap
- type OrderBy
- type Pagination
- type RESTContext
- func (rc *RESTContext) AppLoggingCtag(ctag string)
- func (rc *RESTContext) AppLoggingNew(i interface{})
- func (rc *RESTContext) AppLoggingOld(i interface{})
- func (rc *RESTContext) AppLoggingResult(i interface{})
- func (rc *RESTContext) Critical(format string, v ...interface{})
- func (rc *RESTContext) Debug(format string, v ...interface{})
- func (rc *RESTContext) Error(format string, v ...interface{})
- func (rc *RESTContext) GetCondition(k string) (con *Condition, err error)
- func (rc *RESTContext) GetEnv(k string) (v interface{})
- func (rc *RESTContext) GetLock(key string) (err error)
- func (rc *RESTContext) GetQueryParam(key string) (r string, c int)
- func (rc *RESTContext) GetQueryParams(key string) (rs []string)
- func (rc *RESTContext) HTTPBack() (err error)
- func (rc *RESTContext) HTTPEmptyGif() (err error)
- func (rc *RESTContext) HTTPError(status int) (err error)
- func (rc *RESTContext) HTTPOK(data []byte) (err error)
- func (rc *RESTContext) HTTPRedirect(url string) (err error)
- func (rc *RESTContext) Info(format string, v ...interface{})
- func (rc *RESTContext) LaunchTasks() error
- func (rc *RESTContext) NewAppLogging(al *AppLog)
- func (rc *RESTContext) NewRESTError(status int, msg interface{}) (re error)
- func (rc *RESTContext) Output(data interface{}) (err error)
- func (rc *RESTContext) Print(format string, v ...interface{})
- func (rc *RESTContext) PushTask(queue, tag, value string) error
- func (rc *RESTContext) RESTBadRequest(msg interface{}) (err error)
- func (rc *RESTContext) RESTError(err error) error
- func (rc *RESTContext) RESTGenericError(status int, msg interface{}) (err error)
- func (rc *RESTContext) RESTNotFound(msg interface{}) (err error)
- func (rc *RESTContext) RESTNotOK(msg interface{}) (err error)
- func (rc *RESTContext) RESTOK(data interface{}) (err error)
- func (rc *RESTContext) RESTPanic(msg interface{}) (err error)
- func (rc *RESTContext) RESTTFA(data interface{}) (err error)
- func (rc *RESTContext) ReleaseLocks()
- func (rc *RESTContext) SaveAccess()
- func (rc *RESTContext) ServeBinary(mimetype string, data []byte)
- func (rc *RESTContext) SetEnv(k string, v interface{})
- func (rc *RESTContext) SetHeader(k, v string)
- func (rc *RESTContext) SetOTP(s ...string)
- func (rc *RESTContext) SetStatus(status int)
- func (rc *RESTContext) Trace(format string, v ...interface{})
- func (rc *RESTContext) Warn(format string, v ...interface{})
- func (rc *RESTContext) WriteBytes(data []byte) (n int, e error)
- type RESTError
- type Report
- type ReportInfo
- type Route
- type RouteOption
- type Router
- func (rtr *Router) AddRoute(m string, p interface{}, h Handler, options ...RouteOption)
- func (rtr *Router) CRUD(i interface{}, flag int) Handler
- func (rtr *Router) DefaultRoutes()
- func (_ *Router) Defer(i interface{})
- func (rtr *Router) Delete(c *RESTContext)
- func (rtr *Router) EmptyGif(c *RESTContext)
- func (rtr *Router) EmptyHtml(c *RESTContext)
- func (rtr *Router) GenericRoute(i interface{}, flag int)
- func (rtr *Router) Get(c *RESTContext)
- func (rtr *Router) GetEndpoint() string
- func (rtr *Router) Head(c *RESTContext)
- func (rtr *Router) Init()
- func (rtr *Router) New(c interface{}, mux *Mux, endpoint string)
- func (rtr *Router) NotFound(c *RESTContext)
- func (_ *Router) OnCheck(i interface{}) (interface{}, error)
- func (_ *Router) OnCreate(i interface{}) (interface{}, error)
- func (_ *Router) OnDelete(i interface{}) (interface{}, error)
- func (_ *Router) OnGet(i interface{}) (interface{}, error)
- func (_ *Router) OnSearch(i interface{}) (interface{}, error)
- func (_ *Router) OnUpdate(i interface{}) (interface{}, error)
- func (rtr *Router) Options(c *RESTContext)
- func (rtr *Router) Patch(c *RESTContext)
- func (rtr *Router) Post(c *RESTContext)
- func (_ *Router) PostCheck(i interface{}) (interface{}, error)
- func (_ *Router) PostCreate(i interface{}) (interface{}, error)
- func (_ *Router) PostDelete(i interface{}) (interface{}, error)
- func (_ *Router) PostGet(i interface{}) (interface{}, error)
- func (_ *Router) PostSearch(i interface{}) (interface{}, error)
- func (_ *Router) PostUpdate(i interface{}) (interface{}, error)
- func (_ *Router) PreCheck(i interface{}) (interface{}, error)
- func (_ *Router) PreCreate(i interface{}) (interface{}, error)
- func (_ *Router) PreDelete(i interface{}) (interface{}, error)
- func (_ *Router) PreGet(i interface{}) (interface{}, error)
- func (_ *Router) PreSearch(i interface{}) (interface{}, error)
- func (_ *Router) PreUpdate(i interface{}) (interface{}, error)
- func (rtr *Router) Put(c *RESTContext)
- func (rtr *Router) RouteDelete(rt *Route)
- func (rtr *Router) RouteGet(rt *Route)
- func (rtr *Router) RouteHead(rt *Route)
- func (rtr *Router) RouteNotFound(rt *Route)
- func (rtr *Router) RoutePatch(rt *Route)
- func (rtr *Router) RoutePost(rt *Route)
- func (rtr *Router) RoutePut(rt *Route)
- func (rtr *Router) Trace(c *RESTContext)
- func (_ *Router) Trigger(i interface{}) (interface{}, error)
- type RouterInterface
- type SelfConverter
- type TagHook
- type Task
- type TemporaryCounter
- type TimeRange
- type Worker
- func (w *Worker) Critical(format string, v ...interface{})
- func (w *Worker) Debug(format string, v ...interface{})
- func (w *Worker) Error(format string, v ...interface{})
- func (w *Worker) Info(format string, v ...interface{})
- func (w *Worker) Init(mux *Mux, name string)
- func (w *Worker) Main() error
- func (w *Worker) Print(format string, v ...interface{})
- func (w *Worker) Trace(format string, v ...interface{})
- func (w *Worker) Warn(format string, v ...interface{})
- type WorkerInterface
Constants ¶
const ( DBTAG string = "db" READTAG string = "read" WRITETAG string = "write" )
const ( OriginalRemoteAddrKey = "originalRemoteAddr" // 查询类型 CTYPE_IS = iota CTYPE_NOT CTYPE_OR CTYPE_LIKE CTYPE_GT CTYPE_LT CTYPE_JOIN CTYPE_RANGE CTYPE_ORDER CTYPE_PAGE CTYPE_RAW )
Key to use when setting the request ID.
const ( // db tag DBTAG_PK = "pk" DBTAG_LOGIC = "logic" //tag TAG_REQUIRED = "R" // 必填 TAG_GENERATE = "G" // 服务端生成, 同时不可编辑 TAG_CONDITION = "C" // 可作为查询条件 TAG_DENY = "D" // 不可编辑, 可为空 TAG_SECRET = "S" // 保密,一般不见人 TAG_HIDDEN = "H" // 隐藏 TAG_DEFAULT = "DEF" // 默认 TAG_TIMERANGE = "TR" // 时间范围条件 TAG_REPORT = "RPT" // 报表字段 TAG_CANGROUP = "GRP" // 可以group操作 TAG_ORDERBY = "O" // 可排序(默认DESC) TAG_AORDERBY = "AO" // 正排序(默认DESC) TAG_VERIFIABLE = "V" // 验证后可修改 TAG_RETURN = "RET" // 返回,创建后需要返回数值 TAG_SUM = "SUM" // 求和 TAG_TSUM = "TS" // 总求和(放到聚合中,只能有一个) TAG_COUNT = "COUNT" // 计数 TAG_AGGREGATION = "AGG" // 聚合 // ext field EXF_SUM = "sum" EXF_COUNT = "count" )
const ( // ogo daemon/http framework version. VERSION = "1.0" DEFAULT_PORT = "8001" // generic action const GA_GET = 1 << iota GA_SEARCH GA_POST GA_DELETE GA_PATCH //GA_PUT GA_HEAD GA_ALL = GA_GET | GA_SEARCH | GA_POST | GA_DELETE | GA_PATCH | GA_HEAD KEY_SKIPAUTH = "skipauth" KEY_SKIPLOGIN = "skiplogin" KEY_SKIPPERM = "skipperm" KEY_TPL = "tpl" //env key RequestIDKey = "_reqid_" SaveBodyKey = "_sb_" NoLogKey = "_nl_" PaginationKey = "_pagination_" FieldsKey = "_fields_" TimeRangeKey = "_tr_" OrderByKey = "_ob_" ConditionsKey = "_conditions_" LogPrefixKey = "_prefix_" EndpointKey = "_endpoint_" RowkeyKey = "_rk_" SelectorKey = "_selector_" MimeTypeKey = "_mimetype_" DispositionMTKey = "_dmt_" ContentMD5Key = "_md5_" DispositionPrefix = "_dp_" DIMENSION_KEY = "_dimension_" //在restcontext中的key SIDE_KEY = "_sidekey_" USERID_KEY = "_userid_" APPID_KEY = "_appid_" STAG_KEY = "_stag_" PERMISSION_KEY = "_perm_" EXT_KEY = "_ext_" // 内容类型 ContentTypeJSON = 1 << iota ContentTypeHTML ContentTypeXML )
{{{ const
const (
TD_TOTAL_FIELD = "_total_"
)
Variables ¶
var ( ErrRequired = errors.New("field is required") ErrNonEditable = errors.New("field is non-editable") ErrNonSearchable = errors.New("field is non-searchable") ErrExists = errors.New("field value exists") ErrInvalid = errors.New("invalid_query") ErrNoRecord = errors.New("No_record") ErrNeedField = errors.New("Need field but missing") )
错误代码
var (
DataAccessor = make(map[string]string) // tablename::{read/write} => tag
)
var (
EmptyGifBytes, _ = base64.StdEncoding.DecodeString(base64GifPixel)
)
Functions ¶
func AddTagHook ¶
{{{ func AddTagHook(tag string, hook TagHook) * tag hook
func CacheIncrByFloat ¶
{{{ func CacheIncrByFloat(key string, value float64) error *
func ClusterClient ¶
func ClusterClient() *redis.ClusterClient
{{{ func ClusterClient() *redis.ClusterClient *
func Config ¶
func Config() config.ConfigContainer
{{{ func Config() config.ConfigContainer * 默认的配置就是DMux的配置
func GetDbFields ¶
func GetDbFields(i interface{}, ops ...interface{}) (s []string)
{{{ GetDbFields(i interface{}, ops ...interface{}) (s string) * 从struct中解析数据库字段以及字段选项
func GetSumFields ¶
{{{ func GetSumFields(i interface{}, g []string) (s string) * 从struct中解析数据库字段以及字段选项,为了报表
func OmqBlockTask ¶
{{{ func OmqBlockTask(msg ...string) (string, error) *
func ParseHeaders ¶
{{{ func ParseHeaders(c *web.C, h http.Handler) http.Handler * headers相关处理
func ParseParams ¶
{{{ func ParseParams(c *web.C, h http.Handler) http.Handler { *
func SetOnlineKey ¶
{{{ func SetOnlineKey(id string, ol *Online,p interface{}) bool *
Types ¶
type Access ¶
type Access struct { Time time.Time `json:"t"` Service string `json:"sn,omitempty"` Session string `json:"s"` Duration string `json:"d"` Http *HTTPLog `json:"http,omitempty"` App interface{} `json:"app,omitempty"` //rest app日志 Debug interface{} `json:"debug,omitempty"` //app debug日志 }
func NewAccess ¶
func NewAccess(opts ...interface{}) *Access
{{{ func NewAccess(opts ...interface{}) *Access *
func (*Access) GetApp ¶
func (ac *Access) GetApp() interface{}
{{{ func (ac *Access) GetApp() interface{} * 放置app日志
type ActionInterface ¶
type ActionInterface interface { PreGet(i interface{}) (interface{}, error) //获取前 OnGet(i interface{}) (interface{}, error) //获取中 PostGet(i interface{}) (interface{}, error) //获取后 PreSearch(i interface{}) (interface{}, error) // 搜索前的检查 OnSearch(i interface{}) (interface{}, error) // 搜索前的检查 PostSearch(i interface{}) (interface{}, error) // 搜索后的检查 PreCreate(i interface{}) (interface{}, error) // 插入前的检查 OnCreate(i interface{}) (interface{}, error) // 插入前的检查 PostCreate(i interface{}) (interface{}, error) // 插入后的处理 PreUpdate(i interface{}) (interface{}, error) // 更新前的检查 OnUpdate(i interface{}) (interface{}, error) // 更新前的检查 PostUpdate(i interface{}) (interface{}, error) // 更新后的操作 PreDelete(i interface{}) (interface{}, error) // 删除前的检查 OnDelete(i interface{}) (interface{}, error) // 删除前的检查 PostDelete(i interface{}) (interface{}, error) // 删除后的检查 PreCheck(i interface{}) (interface{}, error) // 搜索前的检查 OnCheck(i interface{}) (interface{}, error) // 搜索前的检查 PostCheck(i interface{}) (interface{}, error) // 搜索后的检查 Trigger(i interface{}) (interface{}, error) //触发器 Defer(i interface{}) //触发器 }
type Aggregation ¶
type Aggregation struct { Key string `json:"key,omitempty"` Value string `json:"value,omitempty"` Count int `json:"count"` Amount float64 `json:"amount"` }
func UpdateAggregation ¶
func UpdateAggregation(as []Aggregation, a Aggregation) []Aggregation
{{{ func UpdateAggregation(as []Aggregation, a Aggregation) []Aggregation *
type Aggregations ¶
type Aggregations map[string][]Aggregation
func BuildAggregationsFromList ¶
func BuildAggregationsFromList(l *List, groups ...[]string) (as Aggregations)
{{{ func BuildAggregationsFromList(l *List, groups ...[]string) Aggregations * 从list生成Aggregations, 传入groups
type AppLog ¶
type AppLog struct { Ctag string `json:"ctag"` Query interface{} `json:"query,omitempty"` New interface{} `json:"new,omitempty"` Old interface{} `json:"old,omitempty"` Result interface{} `json:"result,omitempty"` }
type BaseConverter ¶
type BaseConverter struct{}
func (BaseConverter) FromDb ¶
func (_ BaseConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
{{{ func (_ BaseConverter) FromDb(target interface{}) (gorp.CustomScanner, bool) * 类型转换, 主要处理标准类型; 自定义类型通过SelfConverter实现
func (BaseConverter) ToDb ¶
func (_ BaseConverter) ToDb(val interface{}) (interface{}, error)
{{{ func (_ BaseConverter) ToDb(val interface{}) (interface{}, error) *
type BaseModel ¶
type BaseModel struct { Count int64 `json:"count,omitempty" filter:",H,G,D"` // 计数 Sum float64 `json:"sum,omitempty" filter:",H,G,D"` // 求和 Ext map[string]interface{} `json:"ext,omitempty" filter:",H,G,D"` // 扩展 Error error `json:"-" db:"-"` Model Model `json:"-" db:"-"` // contains filtered or unexported fields }
基础model,在这里可以实现Model接口, 其余的只需要嵌入这个struct,就可以继承这些方法
func (*BaseModel) CheckerFactory ¶
{{{ func (bm *BaseModel) CheckerFactory() Checker *
func (*BaseModel) CreateRow ¶
{{{ func (bm *BaseModel) CreateRow() (Model, error) * 根据条件获取一条记录, model为表结构
func (*BaseModel) DeleteRow ¶
{{{ func (bm *BaseModel) DeleteRow(id string) (affected int64, err error) * 删除记录(逻辑删除)
func (*BaseModel) GetChecker ¶
{{{ func (bm *BaseModel) GetChecker() Checker *
func (*BaseModel) GetConditions ¶
{{{ func (bm *BaseModel) GetConditions() []*Condition *
func (*BaseModel) GetCount ¶
{{{ func (bm *BaseModel) GetCount() (cnt int64, err error) * 获取list, 通用函数
func (*BaseModel) GetCountNSum ¶
{{{ func (bm *BaseModel) GetCountNSum() (cnt int64, sum float64) * 获取计数以及求和, 通用函数
func (*BaseModel) GetCtx ¶
func (bm *BaseModel) GetCtx() *RESTContext
{{{ func (bm *BaseModel) GetCtx() *RESTContext *
func (*BaseModel) GetPagination ¶
func (bm *BaseModel) GetPagination() *Pagination
{{{ func (bm *BaseModel) GetPagination() *Pagination *
func (*BaseModel) GetRow ¶
{{{ func (bm *BaseModel) GetRow(ext ...interface{}) (Model, error) * 根据条件获取一条记录, model为表结构
func (*BaseModel) GetSum ¶
{{{ func (bm *BaseModel) GetSum(d []string) (l *List, err error) * 获取list, 通用函数
func (*BaseModel) NewList ¶
func (bm *BaseModel) NewList() interface{}
{{{ func (bm *BaseModel) NewList() *[]Model *
func (*BaseModel) ReadPrepare ¶
{{{ func (bm *BaseModel) ReadPrepare() (b *gorp.Builder, err error) * 查询准备
func (*BaseModel) SetConditions ¶
{{{ func (bm *BaseModel) SetConditions(cs ...*Condition) (cons []*Condition, err error) * 生成条件
func (*BaseModel) SetCtx ¶
func (bm *BaseModel) SetCtx(c *RESTContext)
{{{ func (bm *BaseModel) SetCtx(c *RESTContext) *
func (*BaseModel) SetPagination ¶
func (bm *BaseModel) SetPagination(p *Pagination)
{{{ func (bm *BaseModel) SetPagination(p *Pagination) * 生成条件
type Condition ¶
type Condition struct { Table string Field string Is interface{} Not interface{} Or interface{} Gt interface{} Lt interface{} Like interface{} Join interface{} Range interface{} //范围条件, btween ? and ? Order interface{} Page interface{} Raw string //原始字符串 }
func GetCondition ¶
{{{ func GetCondition(cs []*Condition, k string) (con *Condition, err error) *
func NewCondition ¶
func ParseCondition ¶
{{{ func ParseCondition(typ string, con *Condition) *Condition *
type Environ ¶
type Environ struct { WorkPath string // working path(abs) AppPath string // application path ProcName string // proc name Worker string // worker name AppConfigPath string // config file path RunMode string // run mode, "dev" or "prod" AccessPath string // acces log file path TplDir string // tpl dir Daemonize bool // daemonize or not EnableGzip bool // enable gzip or not DebugLevel int // debug level PidFile string // pidfile abs path Port string // http port IndentJSON bool // indent JSON MaxMemory int64 //max memory(form-data) Location *time.Location // location // contains filtered or unexported fields }
{{{ type Environ struct
type HTTPLog ¶
type HTTPLog struct { Status int `json:"sc"` IP string `json:"ip"` Method string `json:"m"` URI string `json:"uri"` Proto string `json:"p"` ReqBody string `json:"qb,omitempty"` ReqLength int `json:"ql"` //请求body大小 RepLength int `json:"pl"` //返回body大小 Host string `json:"h"` InHeader *http.Header `json:"ih,omitempty"` OutHeader http.Header `json:"oh,omitempty"` }
type Handler ¶
type Handler func(c *RESTContext)
type Model ¶
type Model interface { SetModel(m Model) Model GetModel() Model SetCtx(c *RESTContext) GetCtx() *RESTContext SetConditions(cs ...*Condition) ([]*Condition, error) GetConditions() []*Condition SetPagination(p *Pagination) GetPagination() *Pagination SetFields(fs []string) GetFields() []string GetChecker() Checker New(c ...interface{}) Model NewList() interface{} // 返回一个空结构列表 // db AddTable(tags ...string) DBConn(tag string) *gorp.DbMap // 数据库连接 TableName() string // 返回表名称, 默认结构type名字(小写), 有特别的表名称,则自己implement 这个方法 PKey() (string, string, bool) // key字段,以及是否auto incr ReadPrepare() (*gorp.Builder, error) // data accessor GetRow(ext ...interface{}) (Model, error) //获取单条记录 GetRows() (*List, error) //获取多条记录 GetOlder() Model //获取旧记录 GetSum(d []string) (*List, error) //获取多条记录 GetCount() (int64, error) //获取多条记录 GetCountNSum() (int64, float64) //获取count and sum CreateRow() (Model, error) //创建单条记录 UpdateRow(ext ...interface{}) (int64, error) //更新记录 DeleteRow(id string) (int64, error) //更新记录 CheckerFactory() Checker //检查存在性 Fill([]byte) error //填充内容 Valid() (Model, error) //数据验证 Filter() (Model, error) //数据过滤(创建,更新后) Protect() (Model, error) //数据保护(获取数据时过滤字段) }
func BuildModel ¶
{{{ func BuildModel(m Model,c ...interface{}) Model { * 第一个参数,model,必须是指针; 第二个参数, *RESTContext
type Mux ¶
type Mux struct { Workers map[string]*Worker Routes map[string]*Route Hooks HStack //TagHooks map[string]TagHook TagHooks *utils.SafeMap // contains filtered or unexported fields }
{{{ type Mux struct
var (
DMux *Mux
)
{{{ variables
func (*Mux) AddTagHook ¶
{{{ func (mux *Mux) AddTagHook(tag string, hook TagHook) * struct 中定义tag来调用钩子
func (*Mux) ClusterClient ¶
{{{ func (mux *Mux) ClusterClient() (*redis.ClusterClient, error) *
func (*Mux) Config ¶
func (mux *Mux) Config() (config.ConfigContainer, error)
{{{ func (mux *Mux) Config() (config.ConfigContainer, error) * 获取配置信息
func (*Mux) NewRouter ¶
func (mux *Mux) NewRouter(c interface{}, endpoint string) RouterInterface
{{{ func (mux *Mux) NewRouter(c interface{}, endpoint string) RouterInterface * 这样做的目的是给rounter设置mux(mux可多个) -- mux=multiplexer,复用器
type OgoHook ¶
type OgoHook func(c *RESTContext) error
type Online ¶
func GetOnlineKey ¶
{{{ func GetOnlineKey(id string) (*Online,error) * 获取在线的key
type OnlineMap ¶
type OnlineMap struct {
// contains filtered or unexported fields
}
var (
OnlineCache *OnlineMap
)
type Pagination ¶
分页信息
func NewPagination ¶
func NewPagination(page, perPage string) (p *Pagination)
条件信息
{{{ func NewPagation(page, perPage string) (p *Pagination)
type RESTContext ¶
type RESTContext struct { web.C Response http.ResponseWriter Request *http.Request Status int ContentLength int RequestBody []byte Accept int //接受类型 Version string OTP *OTPSpec Access *Access Route *Route App interface{} // contains filtered or unexported fields }
http context, 封装第三方包goji
func RCHolder ¶
func RCHolder(c web.C, w http.ResponseWriter, r *http.Request) (*RESTContext, func(c web.C, w http.ResponseWriter, r *http.Request) *RESTContext, error)
{{{ func rcHolder(c web.C, w http.ResponseWriter, r *http.Request) (func(c web.C, w http.ResponseWriter, r *http.Request) *RESTContext) * 利用闭包初始化RESTContext, 并防止某些关键字段被重写(RequestBody)
func (*RESTContext) AppLoggingCtag ¶
func (rc *RESTContext) AppLoggingCtag(ctag string)
{{{ func (rc *RESTContext) AppLoggingCtag(ctag string) * 新
func (*RESTContext) AppLoggingNew ¶
func (rc *RESTContext) AppLoggingNew(i interface{})
{{{ func (rc *RESTContext) AppLoggingNew(i interface{}) * 设置环境变量
func (*RESTContext) AppLoggingOld ¶
func (rc *RESTContext) AppLoggingOld(i interface{})
{{{ func (rc *RESTContext) AppLoggingOld(i interface{}) * 旧
func (*RESTContext) AppLoggingResult ¶
func (rc *RESTContext) AppLoggingResult(i interface{})
{{{ func (rc *RESTContext) AppLoggingResult(i interface{}) * 结果日志
func (*RESTContext) Critical ¶
func (rc *RESTContext) Critical(format string, v ...interface{})
func (*RESTContext) Debug ¶
func (rc *RESTContext) Debug(format string, v ...interface{})
func (*RESTContext) Error ¶
func (rc *RESTContext) Error(format string, v ...interface{})
func (*RESTContext) GetCondition ¶
func (rc *RESTContext) GetCondition(k string) (con *Condition, err error)
{{{ func (rc *RESTContext) GetCondition(k string) (con *Condition, err error) * 设置参数查询条件
func (*RESTContext) GetEnv ¶
func (rc *RESTContext) GetEnv(k string) (v interface{})
{{{ func (rc *RESTContext) GetEnv(k string) (v interface{}) * 设置环境变量
func (*RESTContext) GetLock ¶
func (rc *RESTContext) GetLock(key string) (err error)
{{{ func (rc *RESTContext) GetLock(key string) (err error) *
func (*RESTContext) GetQueryParam ¶
func (rc *RESTContext) GetQueryParam(key string) (r string, c int)
{{{ func (rc *RESTContext) GetQueryParam(key string) (string, int)
func (*RESTContext) GetQueryParams ¶
func (rc *RESTContext) GetQueryParams(key string) (rs []string)
{{{ func (rc *RESTContext) GetQueryParams(key string) (string, int)
func (*RESTContext) HTTPBack ¶
func (rc *RESTContext) HTTPBack() (err error)
{{{ func (rc *RESTContext) HTTPBack() (err error) * 属于request的错误
func (*RESTContext) HTTPEmptyGif ¶
func (rc *RESTContext) HTTPEmptyGif() (err error)
{{{ func (rc *RESTContext) HTTPEmptyGif() (err error) * 属于request的错误
func (*RESTContext) HTTPError ¶
func (rc *RESTContext) HTTPError(status int) (err error)
{{{ func (rc *RESTContext) HTTPError(status int) (err error) *
func (*RESTContext) HTTPOK ¶
func (rc *RESTContext) HTTPOK(data []byte) (err error)
{{{ func (rc *RESTContext) HTTPOK(data []byte) (err error) * 属于request的错误
func (*RESTContext) HTTPRedirect ¶
func (rc *RESTContext) HTTPRedirect(url string) (err error)
{{{ func (rc *RESTContext) HTTPRedirect(url string) (err error) * 属于request的错误
func (*RESTContext) Info ¶
func (rc *RESTContext) Info(format string, v ...interface{})
func (*RESTContext) LaunchTasks ¶
func (rc *RESTContext) LaunchTasks() error
{{{ func (rc *RESTContext) LaunchTasks() error *
func (*RESTContext) NewAppLogging ¶
func (rc *RESTContext) NewAppLogging(al *AppLog)
{{{ func (rc *RESTContext) NewAppLogging(al *AppLog) * 新建App日志
func (*RESTContext) NewRESTError ¶
func (rc *RESTContext) NewRESTError(status int, msg interface{}) (re error)
{{{ func (rc *RESTContext) NewRESTError(status int, msg interface{}) (re error) *
func (*RESTContext) Output ¶
func (rc *RESTContext) Output(data interface{}) (err error)
{{{ func (rc *RESTContext) Output(data interface{}) (err error) *
func (*RESTContext) Print ¶
func (rc *RESTContext) Print(format string, v ...interface{})
func (*RESTContext) PushTask ¶
func (rc *RESTContext) PushTask(queue, tag, value string) error
{{{ func (rc *RESTContext) PushTask(queue, tag, value string) error *
func (*RESTContext) RESTBadRequest ¶
func (rc *RESTContext) RESTBadRequest(msg interface{}) (err error)
{{{ func (rc *RESTContext) RESTBadRequest(msg interface{}) (err error) * BadRequest
func (*RESTContext) RESTError ¶
func (rc *RESTContext) RESTError(err error) error
{{{ func (rc *RESTContext) RESTError(msg interface{}) (err error) * 内部错误
func (*RESTContext) RESTGenericError ¶
func (rc *RESTContext) RESTGenericError(status int, msg interface{}) (err error)
{{{ func (rc *RESTContext) RESTGenericError(status int, msg interface{}) (err error) * 普通错误,就是没有抓到error时报的错
func (*RESTContext) RESTNotFound ¶
func (rc *RESTContext) RESTNotFound(msg interface{}) (err error)
{{{ func (rc *RESTContext) RESTNotFound(msg interface{}) (err error) *
func (*RESTContext) RESTNotOK ¶
func (rc *RESTContext) RESTNotOK(msg interface{}) (err error)
{{{ func (rc *RESTContext) RESTNotOK(msg interface{}) (err error) * 属于request的错误
func (*RESTContext) RESTOK ¶
func (rc *RESTContext) RESTOK(data interface{}) (err error)
{{{ func (rc *RESTContext) RESTOK(data interface{}) (err error) * 属于request的错误
func (*RESTContext) RESTPanic ¶
func (rc *RESTContext) RESTPanic(msg interface{}) (err error)
{{{ func (rc *RESTContext) RESTPanic(msg interface{}) (err error) * 内部错误
func (*RESTContext) RESTTFA ¶
func (rc *RESTContext) RESTTFA(data interface{}) (err error)
{{{ func (rc *RESTContext) RESTTFA(data interface{}) (err error) * rest tfa回应
func (*RESTContext) ReleaseLocks ¶
func (rc *RESTContext) ReleaseLocks()
{{{ func (rc *RESTContext) ReleaseLocks() * 释放所有锁
func (*RESTContext) SaveAccess ¶
func (rc *RESTContext) SaveAccess()
{{{ func (rc *RESTContext) SaveAccess() * 设置环境变量
func (*RESTContext) ServeBinary ¶
func (rc *RESTContext) ServeBinary(mimetype string, data []byte)
{{{ func (rc *RESTContext) ServeBinary(mimetype string, data []byte) * 直接出二进制内容
func (*RESTContext) SetEnv ¶
func (rc *RESTContext) SetEnv(k string, v interface{})
{{{ func (rc *RESTContext) SetEnv(k string, v interface{}) * 设置环境变量
func (*RESTContext) SetHeader ¶
func (rc *RESTContext) SetHeader(k, v string)
{{{ func (rc *RESTContext) SetHeader(k,v string) * set header
func (*RESTContext) SetOTP ¶
func (rc *RESTContext) SetOTP(s ...string)
{{{ func (rc *RESTContext) SetOTP(v,t,s string) * 设置环境变量
func (*RESTContext) SetStatus ¶
func (rc *RESTContext) SetStatus(status int)
{{{ func (rc *RESTContext) SetStatus(status int) * 构建Status Code
func (*RESTContext) Trace ¶
func (rc *RESTContext) Trace(format string, v ...interface{})
{{{ RESTContext loggers * 可以在每个debug信息带上session
func (*RESTContext) Warn ¶
func (rc *RESTContext) Warn(format string, v ...interface{})
func (*RESTContext) WriteBytes ¶
func (rc *RESTContext) WriteBytes(data []byte) (n int, e error)
{{{ func (rc *RESTContext) WriteBytes(data []byte) (n int, e error) * 输出内容,如果需要压缩,统一在这里进行
type RESTError ¶
type Report ¶
type Report struct { ReportInfo *ReportInfo `json:"report_info,omitempty"` Aggregations Aggregations `json:"aggregations,omitempty"` //聚合 List *List `json:"list,omitempty"` }
func (*Report) WithDefaults ¶
{{{ func (rpt *Report) WithDefaults() *Report *
type ReportInfo ¶
type ReportInfo struct { Dimension []string `json:"dimension,omitempty"` // 维度 Type string `json:"type,omitempty"` // 报表类型 Tz string `json:"tz,omitempty"` // 时区 Currency string `json:"currency,omitempty"` // 货币 Start *time.Time `json:"start,omitempty"` // 开始时间 End *time.Time `json:"end,omitempty"` // 开始时间 }
type Route ¶
type RouteOption ¶
type RouteOption map[interface{}]interface{}
type Router ¶
type Router struct { Endpoint string Routes map[string]*Route Hooks map[string]TagHook SRoutes []*Route //排序的Route ReqCount int //访问计数 Mux *Mux Controller interface{} //既是RouterInterface, 也是 ActionInterface }
func (*Router) AddRoute ¶
func (rtr *Router) AddRoute(m string, p interface{}, h Handler, options ...RouteOption)
{{{ func (rtr *Router) AddRoute(m string, p interface{}, h Handler, options ...RouteOption) *
func (*Router) CRUD ¶
{{{ func (rtr *Router) CRUD(i interface{}, flag int) Handler * 通用的操作方法, 根据flag返回 * 必须符合通用的restful风格
func (*Router) DefaultRoutes ¶
func (rtr *Router) DefaultRoutes()
{{{ func (rtr *Router) DefaultRoutes() * 默认路由, 如果已经定义了则忽略,没有定义则加上
func (*Router) Defer ¶
func (_ *Router) Defer(i interface{})
}}} {{{ func (_ *Router) Defer(i interface{}) *
func (*Router) Delete ¶
func (rtr *Router) Delete(c *RESTContext)
func (*Router) EmptyGif ¶
func (rtr *Router) EmptyGif(c *RESTContext)
func (*Router) EmptyHtml ¶
func (rtr *Router) EmptyHtml(c *RESTContext)
func (*Router) GenericRoute ¶
{{{ func (rtr *Router) GenericRoute(i interface{}, flag int) * 自动路由, 任何implelent了Action的类型都可以使用
func (*Router) GetEndpoint ¶
{{{ func (rtr *Router) GetEndpoint() string *
func (*Router) Head ¶
func (rtr *Router) Head(c *RESTContext)
func (*Router) NotFound ¶
func (rtr *Router) NotFound(c *RESTContext)
func (*Router) Options ¶
func (rtr *Router) Options(c *RESTContext)
func (*Router) Patch ¶
func (rtr *Router) Patch(c *RESTContext)
func (*Router) Post ¶
func (rtr *Router) Post(c *RESTContext)
func (*Router) PostCreate ¶
}}} {{{ func (_ *Router) PostCreate(i interface{}) (interface{}, error) *
func (*Router) PostDelete ¶
}}} {{{ func (_ *Router) PostDelete(i interface{}) (interface{}, error) *
func (*Router) PostSearch ¶
}}} {{{ func (_ *Router) PostSearch(i interface{}) (interface{}, error) *
func (*Router) PostUpdate ¶
}}} {{{ func (_ *Router) PostUpdate(i interface{}) (interface{}, error) *
func (*Router) Put ¶
func (rtr *Router) Put(c *RESTContext)
func (*Router) RouteDelete ¶
func (*Router) RouteNotFound ¶
func (*Router) RoutePatch ¶
func (*Router) Trace ¶
func (rtr *Router) Trace(c *RESTContext)
type RouterInterface ¶
type RouterInterface interface { New(interface{}, *Mux, string) AddRoute(m string, p interface{}, h Handler, options ...RouteOption) DefaultRoutes() //默认路由 GetEndpoint() string Init() //method Get(*RESTContext) Post(*RESTContext) Put(*RESTContext) Delete(*RESTContext) Patch(*RESTContext) Head(*RESTContext) Options(*RESTContext) Trace(*RESTContext) NotFound(*RESTContext) // action CRUD(i interface{}, flag int) Handler }
func NewRouter ¶
func NewRouter(c interface{}, endpoint string) RouterInterface
{{{ func NewRouter(c interface{}, endpoint string) RouterInterface * 默认用DMux设置给router
type SelfConverter ¶
type SelfConverter interface { ToDb() (interface{}, error) //入库 FromDb(interface{}) (gorp.CustomScanner, bool) //出库 }
出/入库转换器
type TemporaryCounter ¶
type TemporaryCounter struct { Name string // 计数器名称 Total string // 汇总字段 TotalAmount float64 Journal string //流水号 JournalAmount float64 //金额 }
func (*TemporaryCounter) ClearJournal ¶
func (tc *TemporaryCounter) ClearJournal(journal string) error
{{{ func (tc *TemporaryCounter) ClearJournal(journal string) error * 清除临时扣除
func (*TemporaryCounter) GetTotalAmount ¶
func (tc *TemporaryCounter) GetTotalAmount() (float64, error)
{{{ func (tc *TemporaryCounter) GetTotalAmount() (float64, error) * 获取临时扣除总额
func (*TemporaryCounter) Incr ¶
func (tc *TemporaryCounter) Incr(amount float64) error
{{{ func (tc *TemporaryCounter) Incr(amount float64) error * 临时扣除(就是在TemporaryCounter增加一笔)
type WorkerInterface ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
zhaoonline storage service
|
zhaoonline storage service |
config
Package main provides ...
|
Package main provides ... |
hooks
Package hooks provides ...
|
Package hooks provides ... |
routers
zhaoonline storage service zhaoonline storage service
|
zhaoonline storage service zhaoonline storage service |
libs
|
|
这里实现bitmap索引 Package serving provides ...
|
这里实现bitmap索引 Package serving provides ... |