-
Notifications
You must be signed in to change notification settings - Fork 1
/
expr.go
49 lines (41 loc) · 1.11 KB
/
expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gbind
import (
"bytes"
"context"
"fmt"
"reflect"
)
var (
dot = []byte{'.'}
)
// NewExecer The function type of the excer generator
type NewExecer func(values [][]byte) (Execer, error)
// Execer A Execer need to implement the methods
type Execer interface {
Exec(ctx context.Context, value reflect.Value, data interface{}, opt *DefaultOption) (context.Context, error)
Name() string
}
// execerFactory save all of the excer generators
type execerFactory struct {
m map[string]NewExecer
}
// newexecerFactory save all of the excer generators
func newexecerFactory() *execerFactory {
return &execerFactory{
m: map[string]NewExecer{},
}
}
// regitster your own implemented generator
func (ef *execerFactory) regitster(name string, excerFunc NewExecer) *execerFactory {
ef.m[name] = excerFunc
return ef
}
// getExecer get an execer
func (ef *execerFactory) getExecer(value []byte) (execer Execer, err error) {
var values = bytes.Split(value, dot)
newExecer, ok := ef.m[SliceToString(values[0])]
if !ok {
return nil, fmt.Errorf("syntax error: not support source %s", values[0])
}
return newExecer(values)
}