/
driver.go
53 lines (48 loc) · 1.11 KB
/
driver.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
50
51
52
53
package app
import (
"errors"
"github.com/eolinker/apinto/application"
"github.com/eolinker/apinto/drivers"
"github.com/eolinker/eosc"
)
//Create 创建驱动实例
func Create(id, name string, v *Config, workers map[eosc.RequireId]eosc.IWorker) (eosc.IWorker, error) {
cfg, err := checkConfig(v)
if err != nil {
return nil, err
}
_, _, err = createFilters(id, cfg.Auth)
if err != nil {
return nil, err
}
a := &app{
WorkerBase: drivers.Worker(id, name),
}
err = a.set(cfg)
return a, err
}
func checkConfig(v interface{}) (*Config, error) {
conf, ok := v.(*Config)
if !ok {
return nil, eosc.ErrorConfigType
}
if conf.Anonymous && len(conf.Auth) > 0 {
return nil, errors.New("it is anonymous app,auths should be empty")
}
if conf.Anonymous && len(conf.Auth) > 0 {
return nil, errors.New("it is anonymous app,auths should be empty")
}
for _, a := range conf.Auth {
err := application.CheckPosition(a.Position)
if err != nil {
return nil, err
}
}
for _, a := range conf.Additional {
err := application.CheckPosition(a.Position)
if err != nil {
return nil, err
}
}
return conf, nil
}