-
Notifications
You must be signed in to change notification settings - Fork 2
/
processor.go
54 lines (46 loc) · 866 Bytes
/
processor.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
54
package processor
import (
"encoding/json"
"github.com/google/uuid"
"io/ioutil"
"log"
)
type Processor interface {
InChannel() chan DataUnit
Process()
}
func Name(n string) string {
uuid, err := uuid.NewUUID()
if err != nil {
log.Fatal(err)
}
return n + "_" + uuid.String()
}
type DataUnit struct {
Processor *Processor
Url string
Html []byte
Outputs []interface{}
}
type Output interface {
Json() ([]byte, error)
}
type processorsC struct {
Type string `json:"type"`
TFUrl string `json:"tensorflow_url"`
}
type Config struct {
Processors []processorsC `json:"processors"`
}
func ParseConfig(p *string) (Config, error) {
cf, err := ioutil.ReadFile(*p)
if err != nil {
return Config{}, err
}
config := Config{}
err = json.Unmarshal([]byte(cf), &config)
if err != nil {
return Config{}, nil
}
return config, nil
}