-
Notifications
You must be signed in to change notification settings - Fork 1
/
processor.go
42 lines (36 loc) · 833 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
package oneword
import (
"github.com/airenas/lt-text-to-ipa/internal/pkg/service/api"
)
// Processor does one specific step
type Processor interface {
Process(*Data) error
}
// MainWorker does transcription work
type MainWorker struct {
processors []Processor
}
//Process is main method
func (mw *MainWorker) Process(input string, returnSAMPA bool) (*api.WordInfo, error) {
data := &Data{}
data.Word = input
data.ReturnSAMPA = returnSAMPA
err := mw.processAll(data)
if err != nil {
return nil, err
}
return data.Result, nil
}
//Add adds a processor to the end
func (mw *MainWorker) Add(pr Processor) {
mw.processors = append(mw.processors, pr)
}
func (mw *MainWorker) processAll(data *Data) error {
for _, pr := range mw.processors {
err := pr.Process(data)
if err != nil {
return err
}
}
return nil
}