-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.94 KB
/
main.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 main
import (
"fmt"
"time"
"github.com/codeis4fun/go-data-pipeline/data"
"github.com/codeis4fun/go-data-pipeline/pipeline"
"github.com/codeis4fun/go-data-pipeline/transformer"
)
func main() {
// data
person := data.NewPerson("John", "Doe", "London", time.Date(1980, 1, 1, 0, 0, 0, 0, time.UTC), 1.8, 80)
// transformations
nameToUppercase := transformer.NewToUpper(person.Name)
surnameToUppercase := transformer.NewToUpper(person.Surname)
cityToUppercase := transformer.NewToUpper(person.City)
// Create a pipeline
p1 := pipeline.NewPipeline("Transform name, surname and city")
// Add stages to the pipeline
p1.
AddStage("transform name to uppercase", nameToUppercase).
AddStage("transform surname to uppercase", surnameToUppercase).
AddStage("transform city to uppercase", cityToUppercase)
// Run the pipeline
p1.Run()
// transformations
joinNameAndSurname := transformer.NewJoinStrings(nameToUppercase.Output, surnameToUppercase.Output)
enrichCountryByCity := transformer.NewEnrichCountryByCity(cityToUppercase.Output)
enrichAgeByDateOfBirth := transformer.NewEnrichAgeByDateOfBirth(person.DateOfBirth)
enrichBMIByWeightAndHeight := transformer.NewEnrichBMIByHeightAndWeight(person.Height, person.Weight)
// Create a pipeline
p2 := pipeline.NewPipeline("Transform to complete name, enrich country, enrich age and enrich BMI")
// Add stages to the pipeline
p2.
AddStage("transform to complete name", joinNameAndSurname).
AddStage("enrich country by city", enrichCountryByCity).
AddStage("enrich age by date of birth", enrichAgeByDateOfBirth).
AddStage("enrich BMI by weight and height", enrichBMIByWeightAndHeight)
// Run the pipeline
p2.Run()
// Assign the output of the pipeline to the data
personTreated := data.NewPersonTreated(joinNameAndSurname.Output, enrichCountryByCity.Country, enrichAgeByDateOfBirth.Age, enrichBMIByWeightAndHeight.BMI)
// Print the result
fmt.Printf("Person treated: %+v\n", personTreated)
}