Documentation
¶
Index ¶
- Constants
- func AddDeleteHandle(router *httprouter.Router, route string, handle Handle)
- func AddGetHandle(router *httprouter.Router, route string, handle Handle)
- func AddHandler(router *httprouter.Router, method, route string, handler http.Handler)
- func AddHeadHandle(router *httprouter.Router, route string, handle Handle)
- func AddOptionsHandle(router *httprouter.Router, route string, handle Handle)
- func AddPatchHandle(router *httprouter.Router, route string, handle Handle)
- func AddPostHandle(router *httprouter.Router, route string, handle Handle)
- func AddPutHandle(router *httprouter.Router, route string, handle Handle)
- func CloseDefaultLogger() error
- func ContextGet(ctx context.Context, key interface{}) interface{}
- func ContextSet(r *http.Request, key, val interface{}) *http.Request
- func ErrSQLNoRows(err error) bool
- func GetAesCryptoKey() string
- func GetRealIP(req *http.Request) (ip string)
- func HTMLEscape(url string) string
- func HTMLUnEscape(url string) string
- func HTTPListenAndServe(addr string, router http.Handler)
- func LogDebug(v ...interface{})
- func LogInfo(v ...interface{})
- func MD5(data string) string
- func ReadSerial(name string, baudrate int, bits byte) (data []byte, err error)
- func Redirect(w http.ResponseWriter, url string)
- func ReleaseConfigDB(dbx *DB)
- func ReleaseDB()
- func ResponseJSON(reply *ReplyData, err error, req *http.Request, w http.ResponseWriter) error
- func SHA1(data string) string
- func SHA256(data string) string
- func SHA512(data []byte) ([]byte, error)
- func SetAesCryptoKey(password string)
- func SetCookie(w http.ResponseWriter, name, value, path string, maxAge int)
- func SetDbConfig(cfg DbConfig)
- func WriteBytes(w http.ResponseWriter, response interface{}) error
- func WriteBytesContentType(w http.ResponseWriter, response interface{}, contentType string) error
- func WriteCtxBytes(ctx context.Context, w http.ResponseWriter, response interface{}) error
- func WriteCtxJSON(ctx context.Context, w http.ResponseWriter, response interface{}) error
- func WriteCtxXML(ctx context.Context, w http.ResponseWriter, response interface{}) error
- func WriteJSON(w io.Writer, response interface{}) error
- func WriteXML(w http.ResponseWriter, response interface{}) error
- type AesCrypto
- type ContextKey
- type DB
- func (d *DB) BeginTrans() (err error)
- func (d *DB) Close()
- func (d *DB) Commit() error
- func (d *DB) Connect() (err error)
- func (d *DB) Insert(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)
- func (d *DB) InsertReply(query string, args interface{}) (reply DbReply)
- func (d *DB) Limit(page, pagesize int) string
- func (d *DB) Rollback() error
- func (d *DB) Row(dest interface{}, query string, args interface{}) error
- func (d *DB) Rows(dest interface{}, query string, args interface{}) error
- func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)
- func (d *DB) TransUpdate(query string, args interface{}) (reply DbReply)
- func (d *DB) Update(query string, args interface{}) (RowsAffected int64, err error)
- func (d *DB) UpdateReply(query string, args interface{}) (reply DbReply)
- type DbConfig
- type DbReply
- type Handle
- type JSONQuery
- func (jq *JSONQuery) Array(s ...string) ([]interface{}, error)
- func (jq *JSONQuery) ArrayOfArrays(s ...string) ([][]interface{}, error)
- func (jq *JSONQuery) ArrayOfBools(s ...string) ([]bool, error)
- func (jq *JSONQuery) ArrayOfFloats(s ...string) ([]float64, error)
- func (jq *JSONQuery) ArrayOfInts(s ...string) ([]int, error)
- func (jq *JSONQuery) ArrayOfObjects(s ...string) ([]map[string]interface{}, error)
- func (jq *JSONQuery) ArrayOfStrings(s ...string) ([]string, error)
- func (jq *JSONQuery) Bool(s ...string) (bool, error)
- func (jq *JSONQuery) Float(s ...string) (float64, error)
- func (jq *JSONQuery) Int(s ...string) (int, error)
- func (jq *JSONQuery) Interface(s ...string) (interface{}, error)
- func (jq *JSONQuery) Matrix2D(s ...string) ([][]interface{}, error)
- func (jq *JSONQuery) Object(s ...string) (map[string]interface{}, error)
- func (jq *JSONQuery) String(s ...string) (string, error)
- type Logger
- type Map
- type Message
- type Queue
- func (q *Queue) Back() *list.Element
- func (q *Queue) Front() *list.Element
- func (q *Queue) Init(v interface{}, mark *list.Element) *list.List
- func (q *Queue) InsertAfter(v interface{}, mark *list.Element) *list.Element
- func (q *Queue) InsertBefore(v interface{}, mark *list.Element) *list.Element
- func (q *Queue) Len() int
- func (q *Queue) PushBack(v interface{}) *list.Element
- func (q *Queue) PushFront(v interface{}) *list.Element
- func (q *Queue) Remove(e *list.Element) interface{}
- type ReplyData
- func DbReplyToReply(reply DbReply) *ReplyData
- func ErrReplyData(status int, message string) *ReplyData
- func ErrorsReplyData(status int, errors map[string]string) *ReplyData
- func NewReplyData(status int) *ReplyData
- func OkReplyData() *ReplyData
- func RowReplyData(row interface{}) *ReplyData
- func RowsReplyData(total, pageCount int, rows interface{}) *ReplyData
- type Router
- type RouterHandler
Constants ¶
const ( // DBErrCodeOK ok DBErrCodeOK = 0 // DBErrCodeException exception DBErrCodeException = 1 // DBErrCodeExists exists DBErrCodeExists = 2 // DBErrCodeNotFound not found DBErrCodeNotFound = 3 // DBErrCodeAuthorized authorized DBErrCodeAuthorized = 4 // DBErrCodeNotConnect connect error DBErrCodeNotConnect = 5 )
const ( // ErrOk OK ErrOk = 0 // ErrNotFound 404 route not found ErrNotFound = 1001 // ErrException 500 ErrException = 1002 // ErrBadRequest 400 route params error ErrBadRequest = 1003 // ErrMethodNotAllowed 405 ErrMethodNotAllowed = 1004 // ErrParamsError 415 ErrParamsError = 1005 // ErrUnAuthorized 401 ErrUnAuthorized = 1006 // ErrDataNotFound 404 ErrDataNotFound = 1007 // ErrNotAllowed 405 ErrNotAllowed = 1008 // ErrDataExists 400 ErrDataExists = 1009 // ErrDataValidate 403 ErrDataValidate = 1010 // VarUserAuthorization oauth token VarUserAuthorization = `access_token` // HTTPHeaderAuthorization HTTP header Authorization HTTPHeaderAuthorization = `Authorization` // HTTPHeaderToken HTTP header Authorization X-Token HTTPHeaderToken = `X-Token` )
const ( // KB kilo byte KB int = 1 << (10 * iota) // MB mega byte MB // GB giga byte GB )
const ( // LibName toolkit name Go micro service LibName = `GMS` // LibVersion toolkit version LibVersion = `0.2.2` )
const (
// RequestTimeOut http request timeout (second)
RequestTimeOut = 30
)
Variables ¶
This section is empty.
Functions ¶
func AddDeleteHandle ¶
func AddDeleteHandle(router *httprouter.Router, route string, handle Handle)
AddDeleteHandle add handle to router
func AddGetHandle ¶
func AddGetHandle(router *httprouter.Router, route string, handle Handle)
AddGetHandle add handle to router
func AddHandler ¶
func AddHandler(router *httprouter.Router, method, route string, handler http.Handler)
AddHandler add handler to router
func AddHeadHandle ¶
func AddHeadHandle(router *httprouter.Router, route string, handle Handle)
AddHeadHandle add handle to router
func AddOptionsHandle ¶
func AddOptionsHandle(router *httprouter.Router, route string, handle Handle)
AddOptionsHandle add handle to router
func AddPatchHandle ¶
func AddPatchHandle(router *httprouter.Router, route string, handle Handle)
AddPatchHandle add handle to router
func AddPostHandle ¶
func AddPostHandle(router *httprouter.Router, route string, handle Handle)
AddPostHandle add handle to router
func AddPutHandle ¶
func AddPutHandle(router *httprouter.Router, route string, handle Handle)
AddPutHandle add handle to router
func ContextGet ¶
ContextGet get from context
func ContextSet ¶
ContextSet set to context
func HTMLEscape ¶
HTMLEscape html special char convert
space to ", & to &, < to <, > to >
func HTMLUnEscape ¶
HTMLUnEscape html special char convert
" to space, & to &, < to <, > to >
func HTTPListenAndServe ¶
HTTPListenAndServe new server and start
func ReadSerial ¶
ReadSerial read from serial
func ResponseJSON ¶
ResponseJSON reply JSON
func SetAesCryptoKey ¶
func SetAesCryptoKey(password string)
SetAesCryptoKey set key, key length:16, 24, 32 bytes to AES-128, AES-192, AES-256
func SetCookie ¶
func SetCookie(w http.ResponseWriter, name, value, path string, maxAge int)
SetCookie set http cookie
func WriteBytes ¶
func WriteBytes(w http.ResponseWriter, response interface{}) error
WriteBytes response bytes
func WriteBytesContentType ¶
func WriteBytesContentType(w http.ResponseWriter, response interface{}, contentType string) error
WriteBytesContentType response bytes and Content-Type
func WriteCtxBytes ¶
func WriteCtxBytes(ctx context.Context, w http.ResponseWriter, response interface{}) error
WriteCtxBytes response text data.
func WriteCtxJSON ¶
func WriteCtxJSON(ctx context.Context, w http.ResponseWriter, response interface{}) error
WriteCtxJSON response JSON data.
func WriteCtxXML ¶
func WriteCtxXML(ctx context.Context, w http.ResponseWriter, response interface{}) error
WriteCtxXML response XML data.
func WriteXML ¶
func WriteXML(w http.ResponseWriter, response interface{}) error
WriteXML response XML data.
Types ¶
type AesCrypto ¶
type AesCrypto struct {
Key []byte
}
AesCrypto define
type DB ¶
type DB struct { Driver string // contains filtered or unexported fields }
DB define
func NewConfigDB ¶
NewConfigDB new DB dynamic object
func (*DB) InsertReply ¶
InsertReply insert and return DbReply
func (*DB) TransExec ¶
func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)
TransExec trans execute
func (*DB) TransUpdate ¶
TransUpdate trans update
func (*DB) UpdateReply ¶
UpdateReply update/delete and return DbReply
type DbConfig ¶
type DbConfig struct { Driver string DNS string MaxOpenConns int MaxIdle int MaxLifetime time.Duration }
DbConfig config
type DbReply ¶
DbReply db exec return insert/update/delete
func DbReplyFaild ¶
DbReplyFaild exec faild
type Handle ¶
type Handle func(http.ResponseWriter, *http.Request)
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc.
type JSONQuery ¶
type JSONQuery struct {
// contains filtered or unexported fields
}
JSONQuery is an object that enables querying of a Go map with a simple positional query language.
func NewJSONQuery ¶
NewJSONQuery creates a new JSONQuery obj from []byte.
func (*JSONQuery) ArrayOfArrays ¶
ArrayOfArrays extracts an array of []interface{} (arrays) from some json
func (*JSONQuery) ArrayOfBools ¶
ArrayOfBools extracts an array of bools from some json
func (*JSONQuery) ArrayOfFloats ¶
ArrayOfFloats extracts an array of float64s from some json
func (*JSONQuery) ArrayOfInts ¶
ArrayOfInts extracts an array of ints from some json
func (*JSONQuery) ArrayOfObjects ¶
ArrayOfObjects extracts an array of map[string]interface{} (objects) from some json
func (*JSONQuery) ArrayOfStrings ¶
ArrayOfStrings extracts an array of strings from some json
type Logger ¶
Logger logger
func NewDefaultLogger ¶
NewDefaultLogger defult logger
func ReopenDefaultLogger ¶
ReopenDefaultLogger re open default logger
type Map ¶
type Map map[string]interface{}
Map is a shortcut for map[string]interface{}
func (Map) MarshalXML ¶
MarshalXML allows type Map to be used with xml.Marshal.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue concurrency safe list
func (*Queue) InsertAfter ¶
InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*Queue) InsertBefore ¶
InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*Queue) PushBack ¶
PushBack inserts a new element e with value v at the back of list l and returns e.
type ReplyData ¶
type ReplyData struct { Status int `json:"status" xml:"status"` // Status code Message string `json:"message" xml:"message"` // Message description Errs map[string]string `json:"errors,omitempty" xml:"errors,omitempty"` // Errs errors PageCount int `json:"pageCount,omitempty"` Total int `json:"total,omitempty" xml:"total,omitempty"` // Total data total List interface{} `json:"rows,omitempty" xml:"rows,omitempty"` // List data list Data interface{} `json:"data,omitempty" xml:"data,omitempty"` // Data data attribute }
ReplyData define API output data
func DbReplyToReply ¶
DbReplyToReply db reply to respinse
func ErrReplyData ¶
ErrReplyData creates and return ReplyData with error and message
func ErrorsReplyData ¶
ErrorsReplyData creates and return ReplyData with errors
func NewReplyData ¶
NewReplyData creates and return ReplyData with status and message
func RowReplyData ¶
func RowReplyData(row interface{}) *ReplyData
RowReplyData creates and return ReplyData with attr row
func RowsReplyData ¶
RowsReplyData creates and return ReplyData with total and list