api

package module
v0.0.0-...-de2d0f4 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: Apache-2.0 Imports: 39 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ErrorObjectNotExist = iota
	ErrorObjectDuplicated
	ErrorNoObjectUpdated
	ErrorNoObjectDeleted
	ErrorMissingParam
	ErrorInvalidParam
	ErrorQuotaExceed
	ErrorPermissionDenied
	ErrorOperationFailed
	ErrorInternalError
)

application error

Variables

This section is empty.

Functions

func APIBoxSessionGetKeyAction

func APIBoxSessionGetKeyAction(c *Context) interface{}

返回 Cookie 密钥对

func Create

func Create(c *Context, bean interface{}, params *Params) interface{}

func CreateEx

func CreateEx(c *Context, bean interface{}, params *Params, querySettings map[string]string) interface{}

func Delete

func Delete(c *Context, bean interface{}, params *Params) interface{}

func Detail

func Detail(c *Context, bean interface{}, params *Params) interface{}

func DetailJoin

func DetailJoin(c *Context, bean interface{}, params *Params, joinConds [][]string) interface{}

func HasDriver

func HasDriver(name string) bool

HasDriver return if sql driver is registered.

func IsError

func IsError(x interface{}) bool

func List

func List(c *Context, beans interface{}, params *Params, queryDefines map[string]string) interface{}

func ListJoin

func ListJoin(c *Context, beans interface{}, params *Params, querySettings map[string]string, joinConds [][]string) interface{}

func Move

func Move(c *Context, bean interface{}, srcIndex, dstIndex uint32) interface{}

func SessionCreate

func SessionCreate(c *Context, session *xorm.Session, bean interface{}, params *Params) interface{}

func SessionCreateEx

func SessionCreateEx(c *Context, session *xorm.Session, bean interface{}, params *Params, querySettings map[string]string) interface{}

func SessionDelete

func SessionDelete(c *Context, session *xorm.Session, bean interface{}, params *Params) interface{}

func SessionDetail

func SessionDetail(c *Context, session *xorm.Session, beans interface{}, params *Params) interface{}

func SessionDetailJoin

func SessionDetailJoin(c *Context, session *xorm.Session, bean interface{}, params *Params, joinConds [][]string) interface{}

func SessionList

func SessionList(c *Context, session *xorm.Session, beans interface{}, params *Params, querySettings map[string]string) interface{}

func SessionListJoin

func SessionListJoin(c *Context, session *xorm.Session, beans interface{}, params *Params, querySettings map[string]string, joinConds [][]string) interface{}

func SessionMove

func SessionMove(c *Context, session *xorm.Session, bean interface{}, srcIndex, dstIndex uint32) interface{}

func SessionUpdate

func SessionUpdate(c *Context, session *xorm.Session, bean interface{}, params *Params) interface{}

func SessionUpdateEx

func SessionUpdateEx(c *Context, session *xorm.Session, bean interface{}, params *Params, querySettings map[string]string) interface{}

func Update

func Update(c *Context, bean interface{}, params *Params) interface{}

func UpdateEx

func UpdateEx(c *Context, bean interface{}, params *Params, querySettings map[string]string) interface{}

func WriteData

func WriteData(w http.ResponseWriter, r *http.Request, data interface{},
	apiAction string, apiFormat string, apiCallback string, apiDebug string)

func WriteResponse

func WriteResponse(c *Context, data interface{})

WriteResponse format api result according to the format specified by request params.

Types

type ActionFunc

type ActionFunc func(c *Context) (data interface{})

type App

type App struct {
	Name             string
	Host             string
	Addr             string
	ServerName       string
	Router           *mux.Router
	Config           *config.Config
	DB               *DbManager
	Model            *ModelManager
	Error            *ErrorManager
	Logger           *Logger
	Routes           []*Route
	Hooks            map[string][]ActionFunc
	UnderMaintenance bool
	Middlewares      map[string]negroni.Handler

	HTTPServer *http.Server
	// contains filtered or unexported fields
}

func NewApp

func NewApp() (*App, error)

NewApp create an application with config file: config/app.yaml.

func NewAppFromFile

func NewAppFromFile(configFile string) (*App, error)

NewAppFromFile create an application from config file.

func NewAppFromYaml

func NewAppFromYaml(yamlStr string) (*App, error)

NewAppFromYaml create an application from specified yaml config string.

func (*App) AddListenEventHandler

func (app *App) AddListenEventHandler(h ListenEventHandler)

AddListenEventHandler add handler when listen return.

func (*App) Close

func (app *App) Close() error

func (*App) GetLogger

func (app *App) GetLogger() *logging.Logger

func (*App) Hook

func (app *App) Hook(tag string, actionFunc ActionFunc) *App

Hook add set global hook action at specified tag.

func (*App) InitDb

func (app *App) InitDb()

InitDb load mysql and sqlite3 config section to app.

func (*App) InitError

func (app *App) InitError()

InitError register error and word map for app.

func (*App) LoadConfigWords

func (app *App) LoadConfigWords()

LoadConfigWords load words config section to app.

func (*App) LoadFilterErrors

func (app *App) LoadFilterErrors()

LoadFilterErrors load filter errors to app.

func (*App) RegisterModel

func (app *App) RegisterModel(model interface{})

RegisterModel register a model for app.

func (*App) RegisterModels

func (app *App) RegisterModels(models []interface{})

RegisterModels register models for app.

func (*App) Route

func (app *App) Route(routes []*Route) http.HandlerFunc

Route return a handler func using by http.HandleFunc.

func (*App) Run

func (app *App) Run(routes []*Route) error

Run will start a http server to run your application.

func (*App) SessionStore

func (app *App) SessionStore() (*session.CookieStore, error)

SessionStore return the session store of application.

func (*App) SetRoutes

func (app *App) SetRoutes(routes []*Route)

SetRoutes set the routes of application.

func (*App) Use

func (app *App) Use(middlewares ...negroni.Handler)

Use will run middleware around the request handler.

func (*App) UseBefore

func (app *App) UseBefore(refMwName string, middleware negroni.Handler)

UseBefore will insert a middleware before specified middleware, and run middleware around the request handler.

func (*App) UseNamed

func (app *App) UseNamed(mName string, middleware negroni.Handler)

UseNamed will run a named middleware around the request handler.

func (*App) UseNamedBefore

func (app *App) UseNamedBefore(refMwName string, mName string, middleware negroni.Handler)

UseNamedBefore will insert a named middleware before specified middleware, and run middleware around the request handler.

type Context

type Context struct {
	App    *App
	Input  *Input
	Output *Output
	DB     *DbManager
	Model  *ModelManager
	Error  *ErrorManager
}

func NewContext

func NewContext(app *App, w http.ResponseWriter, r *http.Request) (*Context, error)

func (*Context) Clear

func (c *Context) Clear()

Clear removes all values stored for a given request. This is usually called by a handler wrapper to clean up request variables at the end of a request lifetime. See ClearHandler().

func (*Context) CloseResponse

func (c *Context) CloseResponse()

CloseResponse ignore the action return value and will not response anymore when action return.

func (*Context) Delete

func (c *Context) Delete(key interface{})

Delete removes a value stored for a given key in a given request.

func (*Context) Get

func (c *Context) Get(key interface{}) interface{}

Get returns a value stored for a given key in a given request.

func (*Context) GetAll

func (c *Context) GetAll() map[interface{}]interface{}

GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.

func (*Context) GetAllOk

func (c *Context) GetAllOk() (map[interface{}]interface{}, bool)

GetAllOk returns all stored values for the request as a map and a boolean value that indicates if the request was registered.

func (*Context) GetDB

func (c *Context) GetDB(key interface{}) *xorm.Engine

GetDB returns a *xorm.Engine value stored for a given key in a given request.

func (*Context) GetInt

func (c *Context) GetInt(key interface{}) int

GetInt returns a int value stored for a given key in a given request.

func (*Context) GetInt32

func (c *Context) GetInt32(key interface{}) int32

GetInt32 returns a int32 value stored for a given key in a given request.

func (*Context) GetInt32Ok

func (c *Context) GetInt32Ok(key interface{}) (int32, bool)

GetInt32 returns a int32 value stored and presence state like multi-value return of map access.

func (*Context) GetInt64

func (c *Context) GetInt64(key interface{}) int64

GetInt64 returns a int64 value stored for a given key in a given request.

func (*Context) GetInt64Ok

func (c *Context) GetInt64Ok(key interface{}) (int64, bool)

GetInt64 returns a int64 value stored and presence state like multi-value return of map access.

func (*Context) GetIntOk

func (c *Context) GetIntOk(key interface{}) (int, bool)

GetInt returns a int value stored and presence state like multi-value return of map access.

func (*Context) GetOk

func (c *Context) GetOk(key interface{}) (interface{}, bool)

GetOk returns stored value and presence state like multi-value return of map access.

func (*Context) GetString

func (c *Context) GetString(key interface{}) string

GetString returns a string value stored for a given key in a given request.

func (*Context) GetStringOk

func (c *Context) GetStringOk(key interface{}) (string, bool)

GetString returns a string value stored and presence state like multi-value return of map access.

func (*Context) GetUint

func (c *Context) GetUint(key interface{}) uint

GetUint returns a uint value stored for a given key in a given request.

func (*Context) GetUint32

func (c *Context) GetUint32(key interface{}) uint32

GetUint32 returns a uint32 value stored for a given key in a given request.

func (*Context) GetUint32Ok

func (c *Context) GetUint32Ok(key interface{}) (uint32, bool)

GetUint32 returns a uint32 value stored and presence state like multi-value return of map access.

func (*Context) GetUint64

func (c *Context) GetUint64(key interface{}) uint64

GetUint64 returns a uint64 value stored for a given key in a given request.

func (*Context) GetUint64Ok

func (c *Context) GetUint64Ok(key interface{}) (uint64, bool)

GetUint64 returns a uint64 value stored and presence state like multi-value return of map access.

func (*Context) GetUintOk

func (c *Context) GetUintOk(key interface{}) (uint, bool)

GetUint returns a uint value stored and presence state like multi-value return of map access.

func (*Context) NewParams

func (c *Context) NewParams() *Params

Clear removes all values stored for a given request. This is usually called by a handler wrapper to clean up request variables at the end of a request lifetime. See ClearHandler().

func (*Context) Request

func (c *Context) Request() *http.Request

Response return current request.

func (*Context) Response

func (c *Context) Response() http.ResponseWriter

Response return current response writer.

func (*Context) Session

func (c *Context) Session(sessionName string) (*Session, error)

Session return the session with specified name.

func (*Context) Set

func (c *Context) Set(key, val interface{})

Set stores a value for a given key in a given request.

func (*Context) UpgradeWebsocket

func (c *Context) UpgradeWebsocket() (*websocket.Conn, error)

UpgradeWebsocket upgrade current request to websocket, and return the websocket connection.

type DbManager

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

func NewDbManager

func NewDbManager() *DbManager

NewDbManager create and return a db manager object.

func (*DbManager) AddMysql

func (dbm *DbManager) AddMysql(dbAlias, protocol, address, user, passwd, dbName string, maxIdleConns, maxOpenConns int) error

AddMysql add a mysql database to db mananger object.

func (*DbManager) AddSqlite3

func (dbm *DbManager) AddSqlite3(dbAlias, sqliteDb string, persistent bool) error

AddSqlite3 add a sqlite3 database to db mananger object.

func (*DbManager) GetMysql

func (dbm *DbManager) GetMysql(dbAlias string) (*xorm.Engine, error)

GetMysql return a mysql db engine.

func (*DbManager) GetSqlite3

func (dbm *DbManager) GetSqlite3(dbAlias string) (*xorm.Engine, error)

GetSqlite3 return a sqlite3 db engine.

func (*DbManager) RemoveMysql

func (dbm *DbManager) RemoveMysql(dbAlias string)

RemoveMysql remove a mysql database from db mananger object.

func (*DbManager) RemoveSqlite3

func (dbm *DbManager) RemoveSqlite3(dbAlias string)

RemoveSqlite remove a sqlite3 database from db mananger object.

func (*DbManager) SetMysql

func (dbm *DbManager) SetMysql(dbAlias string, engine *xorm.Engine)

SetMysql set a mysql db engine to dbAlias.

func (*DbManager) SetMysqlLogLevel

func (dbm *DbManager) SetMysqlLogLevel(dbAlias string, level string)

SetMysqlLogLevel set log level for the mysql xorm engine.

func (*DbManager) SetMysqlShowSQL

func (dbm *DbManager) SetMysqlShowSQL(dbAlias string, show bool)

SetMysqlShowSQL set whether to show sql for the mysql xorm engine.

func (*DbManager) SetSqlite3

func (dbm *DbManager) SetSqlite3(dbAlias string, engine *xorm.Engine)

SetSqlite3 return a sqlite3 db engine.

func (*DbManager) SetSqlite3LogLevel

func (dbm *DbManager) SetSqlite3LogLevel(dbAlias string, level string)

SetSqlite3LogLevel set log level for the sqlite3 xorm engine.

func (*DbManager) SetSqlite3ShowSQL

func (dbm *DbManager) SetSqlite3ShowSQL(dbAlias string, show bool)

SetSqlite3ShowSQL set whether to show sql for the sqlite3 xorm engine.

type Error

type Error struct {
	Code    string
	Message string
	Data    interface{}
}

func NewError

func NewError(code string, message string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) SetData

func (e *Error) SetData(data interface{}) *Error

func (*Error) SetErrorData

func (e *Error) SetErrorData(err error) *Error

func (*Error) SetMessage

func (e *Error) SetMessage(message string) *Error

type ErrorDefine

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

func NewErrorDefine

func NewErrorDefine(code string, fieldCounts []int, msgTmpls map[string]map[int]string) *ErrorDefine

NewErrorDefine return an error define.

type ErrorManager

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

func NewErrorManager

func NewErrorManager() *ErrorManager

NewErrorManager return an error manager.

func (*ErrorManager) GetLang

func (em *ErrorManager) GetLang() string

GetLang return the default language of ErrorManager.

func (*ErrorManager) New

func (em *ErrorManager) New(errType ErrorType, fields ...string) *Error

New return an new error with specified error type. If error type need more fields, fields should be specified and will fill to error code. The message output in response will be automatically generated according to error code.

func (*ErrorManager) NewGroupError

func (em *ErrorManager) NewGroupError(group string, errType ErrorType, fields ...string) *Error

NewGroupError return an new error with specified error type of specified group.

func (*ErrorManager) RegisterError

func (em *ErrorManager) RegisterError(errType ErrorType, define *ErrorDefine)

RegisterError register a new error define in default group.

func (*ErrorManager) RegisterErrors

func (em *ErrorManager) RegisterErrors(defines map[ErrorType]*ErrorDefine)

RegisterErrors register new error defines in default group.

func (*ErrorManager) RegisterGroupError

func (em *ErrorManager) RegisterGroupError(group string, errType ErrorType, define *ErrorDefine)

RegisterGroupError register a new error define in specified group.

func (*ErrorManager) RegisterGroupErrors

func (em *ErrorManager) RegisterGroupErrors(group string, defines map[ErrorType]*ErrorDefine)

RegisterGroupErrors register new error defines in specified group.

func (*ErrorManager) RegisterGroupWords

func (em *ErrorManager) RegisterGroupWords(group string, wordMap map[string]map[string]string)

RegisterGroupWords register new word map in specified group.

func (*ErrorManager) RegisterWords

func (em *ErrorManager) RegisterWords(wordMap map[string]map[string]string)

RegisterWords register new word map in default group.

func (*ErrorManager) SetLang

func (em *ErrorManager) SetLang(lang string)

SetLang set the default language when generate message.

type ErrorResult

type ErrorResult struct {
	ACTION  string
	CODE    string
	MESSAGE string
}

type ErrorResultWithData

type ErrorResultWithData struct {
	ACTION  string
	CODE    string
	MESSAGE string
	DATA    interface{}
}

type ErrorType

type ErrorType uint

type Input

type Input struct {
	Request *http.Request
}

func (*Input) Get

func (i *Input) Get(key string) string

获取请求值

func (*Input) GetAction

func (i *Input) GetAction() string

GetAction return the api_action param value.

func (*Input) GetAll

func (i *Input) GetAll() map[string]string

GetAll return all request params.

func (*Input) GetDefault

func (i *Input) GetDefault(key string, defaultValue string) string

获取请求值,如果请求值为空,则返回default值

func (*Input) GetForm

func (i *Input) GetForm() url.Values

GetAll return the row request params.

func (*Input) GetRealIp

func (i *Input) GetRealIp() string

GetRealIp returns the real ip address of request client.

func (*Input) Has

func (i *Input) Has(key string) bool

Has check if the key is exist in request params.

type ListenEventHandler

type ListenEventHandler func(err error)

监听事件处理函数

type Logger

type Logger struct {
	// Logger inherits from log.Logger used to log messages with the Logger middleware
	*logging.Logger
	*utils.Matcher
}

Logger is a middleware handler that logs the request as it goes in and the response as it goes out.

func NewLogger

func NewLogger(appName string) *Logger

NewLogger returns a new Logger instance

func (*Logger) ServeHTTP

func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type ModelDefine

type ModelDefine struct {
	Type          reflect.Type
	MainModelName string
	// contains filtered or unexported fields
}

func (*ModelDefine) FieldGetTag

func (m *ModelDefine) FieldGetTag(field, tagName string) *ModelTag

FieldGetTag get specified tag of field.

func (*ModelDefine) FieldHasTag

func (m *ModelDefine) FieldHasTag(field, tagName string) bool

FieldHasTag check if field has specified tag.

func (*ModelDefine) FieldTags

func (m *ModelDefine) FieldTags(field string) []*ModelTag

FieldTags return tags of specified field.

func (*ModelDefine) Fields

func (m *ModelDefine) Fields() []string

Fields return all fields of model.

func (*ModelDefine) MainFields

func (m *ModelDefine) MainFields() []string

Fields return fields of main table of model.

func (*ModelDefine) RefFields

func (m *ModelDefine) RefFields() []string

Fields return fields of reference table of model.

func (*ModelDefine) TableName

func (m *ModelDefine) TableName(engine *xorm.Engine) string

TableName return table name of model.

func (*ModelDefine) TagFields

func (m *ModelDefine) TagFields(tagName string) []string

TagFields return fields with specified tag name.

type ModelManager

type ModelManager struct {
	Models map[string]*ModelDefine
}

func NewModelManager

func NewModelManager() *ModelManager

func (*ModelManager) Get

func (mm *ModelManager) Get(modelName string) *ModelDefine

Get return specified model.

func (*ModelManager) Has

func (mm *ModelManager) Has(modelName string) bool

Has check if specified model is registered.

func (*ModelManager) Register

func (mm *ModelManager) Register(model interface{})

Register add new model to this manager.

func (*ModelManager) Unregister

func (mm *ModelManager) Unregister(modelName string)

Unregister remove existing model from this manager.

type ModelTag

type ModelTag struct {
	Name   string
	Params []string
}

type MySQLDB

type MySQLDB struct {
	Engine       *xorm.Engine
	Protocol     string
	Address      string
	User         string
	Password     string
	DBName       string
	MaxIdleConns int
	MaxOpenConns int
	ShowSQL      bool
	LogLevel     string
}

type Output

type Output struct {
	ResponseWriter http.ResponseWriter
}

func (*Output) SetHeader

func (o *Output) SetHeader(key, value string)

func (*Output) Write

func (o *Output) Write(data []byte) (int, error)

type ParamRule

type ParamRule struct {
	ParamName string
	Filters   []filter.Filter
	Parsed    bool
}

type Params

type Params struct {
	Rules        []*ParamRule
	RawValues    url.Values
	ParsedValues map[string]interface{}
	Error        *ErrorManager
}

func NewParams

func NewParams(values url.Values, em *ErrorManager) *Params

NewParams return a new Params object.

func (*Params) Add

func (p *Params) Add(paramName string, filters ...filter.Filter) *Params

Add add a new param with filter functions.

func (*Params) AddOrderBy

func (p *Params) AddOrderBy(defaultOrderBy string, defaultOrder string, allowOrderBys []string, allowMultiOrder bool) *Params

SetDefaultOrder set default order of pagination.

func (*Params) AddPagination

func (p *Params) AddPagination() *Params

AddPagination add a pagination params with filter functions.

func (*Params) Del

func (p *Params) Del(paramNames ...string) *Params

Del remove params from list.

func (*Params) Get

func (p *Params) Get(paramName string) interface{}

Get return the parsed value of param.

func (*Params) GetAll

func (p *Params) GetAll() map[string]interface{}

GetAll return all values in params.

func (*Params) GetIP

func (p *Params) GetIP(paramName string) net.IP

GetIP return the parsed value of param as net.IP.

func (*Params) GetIPArray

func (p *Params) GetIPArray(paramName string) []net.IP

GetIPArray return the parsed value of param as net.IP array.

func (*Params) GetInt

func (p *Params) GetInt(paramName string) int

GetInt return the parsed value of param as int.

func (*Params) GetInt32

func (p *Params) GetInt32(paramName string) int32

GetInt32 return the parsed value of param as int32.

func (*Params) GetInt32Array

func (p *Params) GetInt32Array(paramName string) []int32

GetInt32Array return the parsed value of param as int32 array.

func (*Params) GetInt32Range

func (p *Params) GetInt32Range(paramName string) *types.Int32Range

GetInt32Range return the parsed value of param as Int32Range.

func (*Params) GetInt64

func (p *Params) GetInt64(paramName string) int64

GetInt64 return the parsed value of param as int64.

func (*Params) GetInt64Array

func (p *Params) GetInt64Array(paramName string) []int64

GetInt64Array return the parsed value of param as int64 array.

func (*Params) GetInt64Range

func (p *Params) GetInt64Range(paramName string) *types.Int64Range

GetInt64Range return the parsed value of param as Int64Range.

func (*Params) GetIntArray

func (p *Params) GetIntArray(paramName string) []int

GetIntArray return the parsed value of param as int array.

func (*Params) GetIntRange

func (p *Params) GetIntRange(paramName string) *types.IntRange

GetIntRange return the parsed value of param as IntRange.

func (*Params) GetString

func (p *Params) GetString(paramName string) string

GetString return the parsed value of param as string.

func (*Params) GetStringArray

func (p *Params) GetStringArray(paramName string) []string

GetStringArray return the parsed value of param as string array.

func (*Params) GetTime

func (p *Params) GetTime(paramName string) *time.Time

GetTime return the parsed value of param as time.

func (*Params) GetTimeArray

func (p *Params) GetTimeArray(paramName string) []*time.Time

GetTimeArray return the parsed value of param as time array.

func (*Params) GetTimeRange

func (p *Params) GetTimeRange(paramName string) *types.TimeRange

GetTimeRange return the parsed value of param as TimeRange.

func (*Params) GetTimestamp

func (p *Params) GetTimestamp(paramName string) uint32

GetTimestamp return the parsed value of param as Timestamp.

func (*Params) GetTimestampRange

func (p *Params) GetTimestampRange(paramName string) *types.TimestampRange

GetTimeRange return the parsed value of param as TimestampRange.

func (*Params) GetUint

func (p *Params) GetUint(paramName string) uint

GetUint return the parsed value of param as uint.

func (*Params) GetUint32

func (p *Params) GetUint32(paramName string) uint32

GetUint32 return the parsed value of param as uint32.

func (*Params) GetUint32Array

func (p *Params) GetUint32Array(paramName string) []uint32

GetUint32Array return the parsed value of param as uint32 array.

func (*Params) GetUint32Range

func (p *Params) GetUint32Range(paramName string) *types.Uint32Range

GetUint32Range return the parsed value of param as Uint32Range.

func (*Params) GetUint64

func (p *Params) GetUint64(paramName string) uint64

GetUint64 return the parsed value of param as uint64.

func (*Params) GetUint64Array

func (p *Params) GetUint64Array(paramName string) []uint64

GetUint64Array return the parsed value of param as uint64 array.

func (*Params) GetUint64Range

func (p *Params) GetUint64Range(paramName string) *types.Uint64Range

GetUint64Range return the parsed value of param as Uint64Range.

func (*Params) GetUintArray

func (p *Params) GetUintArray(paramName string) []uint

GetUintArray return the parsed value of param as uint array.

func (*Params) GetUintRange

func (p *Params) GetUintRange(paramName string) *types.UintRange

GetUintRange return the parsed value of param as UintRange.

func (*Params) Has

func (p *Params) Has(paramName string) bool

Has return the if param exist.

func (*Params) Parse

func (p *Params) Parse() *Error

Parse parse the values according to the rules.

func (*Params) Set

func (p *Params) Set(paramName string, paramValue interface{}) *Params

Set set the param value.

func (*Params) SetDefaultOrder

func (p *Params) SetDefaultOrder(string) *Params

SetDefaultOrder set default order of pagination.

func (*Params) Validate

func (p *Params) Validate(paramName string, filters ...filter.Filter) *Error

Validate one param according to the rule and save the parsed value.

type RequestIdMaker

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

RequestIdMaker is a middleware handler that auto generate the request id and append to response header.

func NewRequestIdMaker

func NewRequestIdMaker() *RequestIdMaker

NewRequestIdMaker returns a new RequestIdMaker instance

func (*RequestIdMaker) ServeHTTP

func (m *RequestIdMaker) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type Result

type Result struct {
	ACTION  string
	CODE    string
	MESSAGE string
	DATA    interface{}
}

type Route

type Route struct {
	ActionCode string
	ActionFunc ActionFunc
	Hooks      map[string][]ActionFunc
}

func NewRoute

func NewRoute(actionCode string, actionFunc ActionFunc) *Route

NewRoute return a new route.

func (*Route) Hook

func (r *Route) Hook(tag string, actionFunc ActionFunc) *Route

Hook add set hook action at specified tag.

type Session

type Session struct {
	session.Session
	// contains filtered or unexported fields
}

func (*Session) Destroy

func (s *Session) Destroy() error

func (*Session) Save

func (s *Session) Save() error

type Sqlite3DB

type Sqlite3DB struct {
	Engine     *xorm.Engine
	DBPath     string
	Persistent bool
	ShowSQL    bool
	LogLevel   string
}

type SuccessResult

type SuccessResult struct {
	ACTION string
	CODE   string
	DATA   interface{}
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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