Documentation ¶
Index ¶
- Constants
- func CheckBool(value interface{}) interface{}
- func CheckFloat(value interface{}) interface{}
- func CheckInt(value interface{}) interface{}
- func CheckObject(value interface{}) interface{}
- func CheckString(value interface{}) interface{}
- func CheckUint(value interface{}) interface{}
- func EmptyValue(kind uint) interface{}
- func EsEnsureIndex(indexCfg string) error
- func EsRemove(biz, id string) error
- func EsSearch(biz, search string, size, offset int) ([]string, error)
- func EsUpsert(biz, id, content string) error
- func GenSeq(n int64) string
- func GetString(s interface{}) string
- func GetStringD(s interface{}, d string) string
- func HttpDo(url, host, method string, header map[string]string, body []byte) (int, []byte, error)
- func Init(cfg *GlobalConfig, processors *[]Processor) error
- func InitEsParam(url, user, pwd, index, analyzer, searchAnalyzer string) error
- func IsEmpty(d interface{}, kind uint) bool
- func IsEmptyArray(d interface{}) bool
- func IsEmptyBool(d interface{}) bool
- func IsEmptyNumber(d interface{}) bool
- func IsEmptyObject(d interface{}) bool
- func IsEmptyString(d interface{}) bool
- func NextSeq(seq string) (string, error)
- func ParseKindArray(value []interface{}, kind uint) interface{}
- func ParseKindMap(value map[string]interface{}, kind uint) interface{}
- func ParseKindValue(value interface{}, kind uint) interface{}
- func Register(method, pattern string, h Handler)
- func RemoveDupArray(s []string) []string
- func UUID() string
- type ExtLog
- type Field
- type FieldSet
- func (fs *FieldSet) BuildAllObj(all map[string]interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildFilterObj(filter map[string]interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildInObj(in map[string]interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildNinObj(nin map[string]interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildOrObj(or []interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildOrderArray(order []string, sort *bson.D) error
- func (fs *FieldSet) BuildRangeObj(rang map[string]interface{}, cond map[string]interface{}) error
- func (fs *FieldSet) BuildSearchContent(obj map[string]interface{}, fields []string) string
- func (fs *FieldSet) BuildSelectObj(slice []string, sel map[string]interface{}) error
- func (fs *FieldSet) CheckObject(obj map[string]interface{}, dotOk bool) error
- func (fs *FieldSet) CheckSearchFields(fields []string) error
- func (fs *FieldSet) InReplace(value *map[string]interface{})
- func (fs *FieldSet) InSort(data *map[string]interface{}) bson.D
- func (fs *FieldSet) IsFieldCreateOnly(field string) bool
- func (fs *FieldSet) IsFieldMember(field string) (uint, bool)
- func (fs *FieldSet) IsFieldReadOnly(field string) bool
- func (fs *FieldSet) IsMapMember(field string) (uint, bool)
- func (fs *FieldSet) OrderArray2Slice(sort *bson.D) []string
- func (fs *FieldSet) OutReplace(value *map[string]interface{})
- func (fs *FieldSet) OutReplaceArray(values []interface{})
- func (fs *FieldSet) ParseSimpleArray(value interface{}, kind uint) interface{}
- func (fs *FieldSet) ParseSimpleValue(value interface{}, kind uint) interface{}
- func (fs *FieldSet) SetCreateOnlyFields(fields []string)
- func (fs *FieldSet) SetReadOnlyFields(fields []string)
- type GlobalConfig
- type Handler
- type Logger
- type Processor
- func (p *Processor) DefaultDelete() Handler
- func (p *Processor) DefaultGet() Handler
- func (p *Processor) DefaultGetColName() func(query url.Values) string
- func (p *Processor) DefaultGetDbName() func(query url.Values) string
- func (p *Processor) DefaultGetPage() Handler
- func (p *Processor) DefaultOnWriteDone() func(method string, vars map[string]string, query url.Values, ...)
- func (p *Processor) DefaultPatch() Handler
- func (p *Processor) DefaultPost() Handler
- func (p *Processor) DefaultPut() Handler
- func (p *Processor) Init() error
- func (p *Processor) Load()
- type Rsp
- type RspGetPageData
- type SearchResponse
Constants ¶
View Source
const ( KindInvalid = uint(reflect.Invalid) KindBool = uint(reflect.Bool) KindInt = uint(reflect.Int64) KindUint = uint(reflect.Uint64) KindFloat = uint(reflect.Float64) KindString = uint(reflect.String) KindObject = uint(reflect.Struct) KindSimpleEnd = uint(999) KindArrayBase = uint(1000) KindArrayBool = KindArrayBase + KindBool KindArrayInt = KindArrayBase + KindInt KindArrayUint = KindArrayBase + KindUint KindArrayFloat = KindArrayBase + KindFloat KindArrayString = KindArrayBase + KindString KindArrayObject = KindArrayBase + KindObject KindArrayEnd = uint(1999) KindMapBase = uint(2000) KindMapBool = KindMapBase + KindBool KindMapInt = KindMapBase + KindInt KindMapUint = KindMapBase + KindUint KindMapFloat = KindMapBase + KindFloat KindMapString = KindMapBase + KindString KindMapObject = KindMapBase + KindObject KindMapEnd = uint(2999) )
Variables ¶
This section is empty.
Functions ¶
func CheckFloat ¶
func CheckFloat(value interface{}) interface{}
func CheckObject ¶
func CheckObject(value interface{}) interface{}
func CheckString ¶
func CheckString(value interface{}) interface{}
func EmptyValue ¶
func EmptyValue(kind uint) interface{}
func EsEnsureIndex ¶
func GetStringD ¶
func Init ¶
func Init(cfg *GlobalConfig, processors *[]Processor) error
func InitEsParam ¶
func IsEmptyArray ¶
func IsEmptyArray(d interface{}) bool
func IsEmptyBool ¶
func IsEmptyBool(d interface{}) bool
func IsEmptyNumber ¶
func IsEmptyNumber(d interface{}) bool
func IsEmptyObject ¶
func IsEmptyObject(d interface{}) bool
func IsEmptyString ¶
func IsEmptyString(d interface{}) bool
func ParseKindArray ¶
func ParseKindArray(value []interface{}, kind uint) interface{}
func ParseKindMap ¶
func ParseKindValue ¶
func ParseKindValue(value interface{}, kind uint) interface{}
func RemoveDupArray ¶
Types ¶
type FieldSet ¶
func BuildFieldSet ¶
func (*FieldSet) BuildAllObj ¶
func (*FieldSet) BuildFilterObj ¶
func (*FieldSet) BuildInObj ¶
func (*FieldSet) BuildNinObj ¶
func (*FieldSet) BuildOrObj ¶
func (*FieldSet) BuildOrderArray ¶
func (*FieldSet) BuildRangeObj ¶
func (*FieldSet) BuildSearchContent ¶
func (*FieldSet) BuildSelectObj ¶
func (*FieldSet) CheckObject ¶
func (*FieldSet) CheckSearchFields ¶
func (*FieldSet) IsFieldCreateOnly ¶
func (*FieldSet) IsFieldReadOnly ¶
func (*FieldSet) OutReplace ¶
func (*FieldSet) OutReplaceArray ¶
func (fs *FieldSet) OutReplaceArray(values []interface{})
func (*FieldSet) ParseSimpleArray ¶
func (*FieldSet) ParseSimpleValue ¶
func (*FieldSet) SetCreateOnlyFields ¶
func (*FieldSet) SetReadOnlyFields ¶
type GlobalConfig ¶
type GlobalConfig struct { Mux *mux.Router // gorilla/mux MgoSess *mgo.Session // mongodb session MgoDefaultDbPrefix string // mongodb default db prefix, using "rest_" if not setting MgoDefaultCol string // mongodb default collection name, using "cn" if not setting EsEnable bool // enable es for search EsUrl string // es url, default: http://127.0.0.1:9200 EsUser string // es username EsPwd string // es password EsIndex string // es index, default: restful EsAnalyzer string // default: ik_max_word EsSearchAnalyzer string // default: ik_max_word }
type Logger ¶
type Logger interface { Debugf(format string, v ...interface{}) Debugln(v ...interface{}) Warnf(format string, v ...interface{}) Warnln(v ...interface{}) Fatalf(format string, v ...interface{}) Fatalln(v ...interface{}) }
var Log Logger
you can reassign Log to your own Logger which contains the methods above
type Processor ¶
type Processor struct { // Business name, usually using plural noun, the uses are as follows: // 1. default db name: rest_{Biz} // 2. value of elasticsearch biz field // 3. logs Biz string // URL Path as service, usually equal to Biz URLPath string // for fields type parsing DataStruct interface{} // fields for search // to use the search feature, you must enable GlobalConfig.EsEnable // field's type must be string or []string SearchFields []string // fields CreateOnly // fields can only be written when creating by POST or PUT CreateOnlyFields []string // fields ReadOnly // fields can not be written or update, data should be loaded into DB by other ways ReadOnlyFields []string // fields type and R/W config FieldSet *FieldSet // CURD handler PostHandler Handler PutHandler Handler PatchHandler Handler GetHandler Handler GetPageHandler Handler DeleteHandler Handler // Do something after data write success // 1. update search data to es OnWriteDone func(method string, vars map[string]string, query url.Values, data map[string]interface{}) // specify db and collection name from URL Query // e.g.: /path?db=dbName&col=colName // default db name: rest_{Biz} // default col name: cn GetDbName func(query url.Values) string GetColName func(query url.Values) string }
func (*Processor) DefaultDelete ¶
func (*Processor) DefaultGet ¶
func (*Processor) DefaultGetColName ¶
func (*Processor) DefaultGetDbName ¶
func (*Processor) DefaultGetPage ¶
func (*Processor) DefaultOnWriteDone ¶
func (*Processor) DefaultPatch ¶
func (*Processor) DefaultPost ¶
func (*Processor) DefaultPut ¶
type RspGetPageData ¶
type RspGetPageData struct { Total int64 `json:"total"` Hits []interface{} `json:"hits"` }
type SearchResponse ¶
type SearchResponse struct { Result string `json:"result"` Error struct { Type string `json:"type"` Reason string `json:"reason"` } `json:"error"` Hits struct { Total int64 `json:"total"` Hits []struct { Id string `json:"_id"` Source struct { Biz string `json:"biz"` Content string `json:"content"` } `json:"_source"` } `json:"hits"` } `json:"hits"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.