Skip to content

Commit

Permalink
符合golint 规范,使用it代替this 作为接收器
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jan 26, 2019
1 parent 1ae1874 commit ad71d92
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 390 deletions.
20 changes: 10 additions & 10 deletions ExpressionEngineExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ type ExpressionEngineExpr struct {
}

//引擎名称
func (this *ExpressionEngineExpr) Name() string {
func (it *ExpressionEngineExpr) Name() string {
return "ExpressionEngineExpr"
}

//编译一个表达式
//参数:lexerArg 表达式内容
//返回:interface{} 编译结果,error 错误
func (this *ExpressionEngineExpr) Lexer(expression string) (interface{}, error) {
expression = this.repleaceExpression(expression)
func (it *ExpressionEngineExpr) Lexer(expression string) (interface{}, error) {
expression = it.repleaceExpression(expression)
var result, err = expr.Parse(expression)
return result, err
}

//执行一个表达式
//参数:lexerResult=编译结果,arg=参数
//返回:执行结果,错误
func (this *ExpressionEngineExpr) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) {
func (it *ExpressionEngineExpr) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) {
output, err := expr.Run(lexerResult.(expr.Node), arg)
return output, err
}

//替换表达式中的值 and,or,参数 替换为实际值
func (this *ExpressionEngineExpr) repleaceExpression(expression string) string {
func (it *ExpressionEngineExpr) repleaceExpression(expression string) string {
if expression == "" {
return expression
}
Expand All @@ -41,7 +41,7 @@ func (this *ExpressionEngineExpr) repleaceExpression(expression string) string {
return expression
}

func (this *ExpressionEngineExpr) split(str string) (stringItems []string) {
func (it *ExpressionEngineExpr) split(str string) (stringItems []string) {
if str == "" {
return nil
}
Expand Down Expand Up @@ -69,10 +69,10 @@ func (this *ExpressionEngineExpr) split(str string) (stringItems []string) {
}

//Lexer缓存,可不提供。
func (this *ExpressionEngineExpr) LexerCache() ExpressionEngineLexerCache {
if this.mapCache == nil {
func (it *ExpressionEngineExpr) LexerCache() ExpressionEngineLexerCache {
if it.mapCache == nil {
var cache = ExpressionEngineLexerMapCache{}.New()
this.mapCache = &cache
it.mapCache = &cache
}
return this.mapCache
return it.mapCache
}
14 changes: 7 additions & 7 deletions ExpressionEngineGovaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ import (
type ExpressionEngineGovaluate struct {
}

func (this *ExpressionEngineGovaluate) Name() string {
func (it *ExpressionEngineGovaluate) Name() string {
return "ExpressionEngineGovaluate"
}

//编译一个表达式
//参数:lexerArg 表达式内容
//返回:interface{} 编译结果,error 错误
func (this *ExpressionEngineGovaluate) Lexer(expression string) (interface{}, error) {
expression = this.repleaceExpression(expression)
func (it *ExpressionEngineGovaluate) Lexer(expression string) (interface{}, error) {
expression = it.repleaceExpression(expression)
return govaluate.NewEvaluableExpression(expression)
}

//执行一个表达式
//参数:lexerResult=编译结果,arg=参数
//返回:执行结果,错误
func (this *ExpressionEngineGovaluate) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) {
func (it *ExpressionEngineGovaluate) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) {
return compileResult.(*govaluate.EvaluableExpression).Evaluate(arg.(map[string]interface{}))
}

//替换表达式中的值 and,or,参数 替换为实际值
func (this *ExpressionEngineGovaluate) repleaceExpression(expression string) string {
func (it *ExpressionEngineGovaluate) repleaceExpression(expression string) string {
if expression == "" {
return expression
}
Expand All @@ -37,7 +37,7 @@ func (this *ExpressionEngineGovaluate) repleaceExpression(expression string) str
return expression
}

func (this *ExpressionEngineGovaluate) split(str string) (stringItems []string) {
func (it *ExpressionEngineGovaluate) split(str string) (stringItems []string) {
if str == "" {
return nil
}
Expand Down Expand Up @@ -65,6 +65,6 @@ func (this *ExpressionEngineGovaluate) split(str string) (stringItems []string)
}

//Lexer缓存,可不提供。
func (this *ExpressionEngineGovaluate) LexerCache() ExpressionEngineLexerCache {
func (it *ExpressionEngineGovaluate) LexerCache() ExpressionEngineLexerCache {
return nil
}
18 changes: 9 additions & 9 deletions ExpressionEngineJee.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const (
type ExpressionEngineJee struct {
}

func (this *ExpressionEngineJee) Name() string {
func (it *ExpressionEngineJee) Name() string {
return "ExpressionEngineJee"
}

//编译一个表达式
//参数:lexerArg 表达式内容
//返回:interface{} 编译结果,error 错误
func (this *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) {
tokenized, err := jee.Lexer(this.LexerAndOrSupport(lexerArg))
func (it *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) {
tokenized, err := jee.Lexer(it.LexerAndOrSupport(lexerArg))
if err != nil {
return nil, utils.NewError("ExpressionEngineJee", err)
}
Expand All @@ -41,7 +41,7 @@ func (this *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) {
//执行一个表达式
//参数:lexerResult=编译结果,arg=参数
//返回:执行结果,错误
func (this *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) {
func (it *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) {
var jeeMsg jee.BMsg
switch operation {
case JeeOperation_Marshal_Map:
Expand Down Expand Up @@ -73,16 +73,16 @@ func (this *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{}
}

//编译后立即执行
func (this *ExpressionEngineJee) LexerEval(lexerArg string, arg interface{}, operation int) (interface{}, error) {
var lexer, error = this.Lexer(lexerArg)
func (it *ExpressionEngineJee) LexerEval(lexerArg string, arg interface{}, operation int) (interface{}, error) {
var lexer, error = it.Lexer(lexerArg)
if error != nil {
return nil, error
}
return this.Eval(lexer, arg, operation)
return it.Eval(lexer, arg, operation)
}

//添加and 和 or 语法支持
func (this *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string {
func (it *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string {
var buf bytes.Buffer
strs := strings.Split(lexerArg, " or ")
if len(strs) > 1 {
Expand Down Expand Up @@ -118,6 +118,6 @@ func (this *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string {
}

//Lexer缓存,可不提供。
func (this *ExpressionEngineJee) LexerCache() ExpressionEngineLexerCache {
func (it *ExpressionEngineJee) LexerCache() ExpressionEngineLexerCache {
return nil
}
24 changes: 12 additions & 12 deletions ExpressionEngineLexerMapCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ type ExpressionEngineLexerMapCache struct {
lock sync.RWMutex
}

func (this ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache {
if this.mapCache == nil {
this.mapCache = make(map[string]interface{})
func (it ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache {
if it.mapCache == nil {
it.mapCache = make(map[string]interface{})
}
return this
return it
}

func (this *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{}) error {
func (it *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{}) error {
if expression == "" {
return utils.NewError("ExpressionEngineLexerMapCache", "set lexerMap chache key can not be ''!")
}
this.lock.Lock()
defer this.lock.Unlock()
this.mapCache[expression] = lexer
it.lock.Lock()
defer it.lock.Unlock()
it.mapCache[expression] = lexer
return nil
}
func (this *ExpressionEngineLexerMapCache) Get(expression string) (interface{}, error) {
func (it *ExpressionEngineLexerMapCache) Get(expression string) (interface{}, error) {
var result interface{}
this.lock.RLock()
defer this.lock.RUnlock()
result = this.mapCache[expression]
it.lock.RLock()
defer it.lock.RUnlock()
result = it.mapCache[expression]
return result, nil
}
40 changes: 20 additions & 20 deletions ExpressionEngineProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,59 @@ func (ExpressionEngineProxy) New(engine ExpressionEngine, useLexerCache bool) Ex
}

//引擎名称
func (this ExpressionEngineProxy) Name() string {
if this.expressionEngine == nil {
func (it ExpressionEngineProxy) Name() string {
if it.expressionEngine == nil {
return ""
}
return this.expressionEngine.Name()
return it.expressionEngine.Name()
}

//编译一个表达式
//参数:lexerArg 表达式内容
//返回:interface{} 编译结果,error 错误
func (this *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) {
if this.expressionEngine == nil {
func (it *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) {
if it.expressionEngine == nil {
return nil, utils.NewError("ExpressionEngineProxy", "ExpressionEngineProxy not init for ExpressionEngineProxy{}.New(...)")
}
if this.expressionEngine.LexerCache() != nil && this.lexerCacheable {
if it.expressionEngine.LexerCache() != nil && it.lexerCacheable {
//如果 提供缓存,则使用缓存
cacheResult, cacheErr := this.expressionEngine.LexerCache().Get(expression)
cacheResult, cacheErr := it.expressionEngine.LexerCache().Get(expression)
if cacheErr != nil {
return nil, cacheErr
}
if cacheResult != nil {
return cacheResult, nil
}
}
var result, err = this.expressionEngine.Lexer(expression)
if this.expressionEngine.LexerCache() != nil && this.lexerCacheable {
var result, err = it.expressionEngine.Lexer(expression)
if it.expressionEngine.LexerCache() != nil && it.lexerCacheable {
//如果 提供缓存,则使用缓存
this.expressionEngine.LexerCache().Set(expression, result)
it.expressionEngine.LexerCache().Set(expression, result)
}
return result, err
}

//执行一个表达式
//参数:lexerResult=编译结果,arg=参数
//返回:执行结果,错误
func (this *ExpressionEngineProxy) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) {
if this.expressionEngine == nil {
func (it *ExpressionEngineProxy) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) {
if it.expressionEngine == nil {
return nil, utils.NewError("ExpressionEngineProxy", "ExpressionEngineProxy not init for ExpressionEngineProxy{}.New(...)")
}
return this.expressionEngine.Eval(lexerResult, arg, operation)
return it.expressionEngine.Eval(lexerResult, arg, operation)
}

func (this *ExpressionEngineProxy) LexerCache() ExpressionEngineLexerCache {
if this.expressionEngine == nil {
func (it *ExpressionEngineProxy) LexerCache() ExpressionEngineLexerCache {
if it.expressionEngine == nil {
return nil
}
return this.expressionEngine.LexerCache()
return it.expressionEngine.LexerCache()
}

func (this *ExpressionEngineProxy) SetUseLexerCache(isUseCache bool) error {
this.lexerCacheable = isUseCache
func (it *ExpressionEngineProxy) SetUseLexerCache(isUseCache bool) error {
it.lexerCacheable = isUseCache
return nil
}
func (this *ExpressionEngineProxy) LexerCacheable() bool {
return this.lexerCacheable
func (it *ExpressionEngineProxy) LexerCacheable() bool {
return it.lexerCacheable
}
4 changes: 2 additions & 2 deletions GoMybatisEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type GoMybatisEngine struct {
DB *sql.DB
}

func (this GoMybatisEngine) NewSession() Session {
func (it GoMybatisEngine) NewSession() Session {
uuid := utils.CreateUUID()
var mysqlLocalSession = LocalSession{
SessionId: uuid,
db: this.DB,
db: it.DB,
}
var session = Session(&mysqlLocalSession)
return session
Expand Down
14 changes: 7 additions & 7 deletions GoMybatisEngine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ type TestSession struct {
Session
}

func (this *TestSession) Id() string {
func (it *TestSession) Id() string {
return "sadf"
}
func (this *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) {
func (it *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) {
resultsSlice := make([]map[string][]byte, 0)

result := make(map[string][]byte)
Expand All @@ -140,19 +140,19 @@ func (this *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) {
resultsSlice = append(resultsSlice, result)
return resultsSlice, nil
}
func (this *TestSession) Exec(sqlorArgs string) (*Result, error) {
func (it *TestSession) Exec(sqlorArgs string) (*Result, error) {
return nil, nil
}
func (this *TestSession) Rollback() error {
func (it *TestSession) Rollback() error {
return nil
}
func (this *TestSession) Commit() error {
func (it *TestSession) Commit() error {
return nil
}
func (this *TestSession) Begin() error {
func (it *TestSession) Begin() error {
return nil
}
func (this *TestSession) Close() {
func (it *TestSession) Close() {

}

Expand Down
2 changes: 1 addition & 1 deletion GoMybatisExpressionTypeConvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type GoMybatisExpressionTypeConvert struct {
}

//表达式类型转换器
func (this GoMybatisExpressionTypeConvert) Convert(arg SqlArg) interface{} {
func (it GoMybatisExpressionTypeConvert) Convert(arg SqlArg) interface{} {
if arg.Type.Kind() == reflect.Struct && arg.Type.String() == Adapter_DateType {
return arg.Value.(time.Time).Nanosecond()
}
Expand Down
8 changes: 4 additions & 4 deletions GoMybatisSqlArgTypeConvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type GoMybatisSqlArgTypeConvert struct {
}

//Sql内容类型转换器
func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string {
func (it GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string {
var argValue = arg.Value
var argType = arg.Type
if argValue == nil {
Expand All @@ -32,7 +32,7 @@ func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string {
case reflect.String:
var argStr bytes.Buffer
argStr.WriteString(`'`)
argStr.WriteString(this.toString(&arg))
argStr.WriteString(it.toString(&arg))
argStr.WriteString(`'`)
return argStr.String()
case reflect.Struct:
Expand All @@ -45,10 +45,10 @@ func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string {
}
break
}
return this.toString(&arg)
return it.toString(&arg)
}

func (this GoMybatisSqlArgTypeConvert) toString(value *SqlArg) string {
func (it GoMybatisSqlArgTypeConvert) toString(value *SqlArg) string {
if value.Value == nil {
return ""
}
Expand Down
Loading

0 comments on commit ad71d92

Please sign in to comment.