Skip to content

Commit df5ec34

Browse files
committed
chore: added example usages in readme.md
1 parent b3cb37a commit df5ec34

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

readme.md

+38
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,45 @@ go get github.com/izniburak/pipeline-go
1515
```
1616

1717
## Examples
18+
```go
19+
package main
1820

21+
import (
22+
"fmt"
23+
"strings"
24+
"github.com/izniburak/pipeline-go"
25+
)
26+
27+
type UpperCasePipe struct{}
28+
29+
func (u *UpperCasePipe) Handle(value pipeline.PipeValue, next pipeline.PipeNext) pipeline.PipeValue {
30+
// get value
31+
text := value.(string)
32+
capitalized := strings.ToUpper(text)
33+
return next(capitalized)
34+
}
35+
36+
type TrimSpacePipe struct{}
37+
38+
func (t *TrimSpacePipe) Handle(value pipeline.PipeValue, next pipeline.PipeNext) pipeline.PipeValue {
39+
// get value
40+
text := value.(string)
41+
trimmed := strings.Trim(text, " ")
42+
return next(trimmed)
43+
}
44+
45+
func main() {
46+
text := " buki.dev "
47+
48+
pipes := []pipeline.PipeInterface{
49+
new(UpperCasePipe),
50+
new(TrimSpacePipe),
51+
}
52+
result := pipeline.Send(text).Through(pipes).ThenReturn()
53+
54+
fmt.Println(result) // BUKI.DEV
55+
}
56+
```
1957

2058
## Contributing
2159

0 commit comments

Comments
 (0)