-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
51 lines (42 loc) · 1.2 KB
/
example.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
package main
import (
"strings"
"github.com/DanielMcSheehy/parallel-pipeline/pipeline"
"github.com/spf13/cobra"
)
// example text transformations
func RemoveAllSmileyFaces() *pipeline.Transformer {
return &pipeline.Transformer{
Transform: func(input string) string {
return strings.ReplaceAll(input, "😀", "")
},
}
}
func ReplaceSadWithHappy() *pipeline.Transformer {
return &pipeline.Transformer{
Transform: func(input string) string {
return strings.ReplaceAll(input, "sad", "happy")
},
}
}
var workerCount = 3
func main() {
var cmdTransform = &cobra.Command{
Use: "transform [directory to read] [output directory]",
Short: "transform all files in a directory",
Long: `transform all files in a directory.`,
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
mainPipeline := pipeline.New(workerCount)
mainPipeline.RegisterTransformers(
RemoveAllSmileyFaces(),
ReplaceSadWithHappy(),
)
mainPipeline.Execute(args[0], args[1])
},
}
cmdTransform.Flags().IntVarP(&workerCount, "workers", "w", 3, "number of concurrent workers")
var rootCmd = &cobra.Command{Use: "data-pipeline"}
rootCmd.AddCommand(cmdTransform)
rootCmd.Execute()
}