Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coc1961/flow
Simple Golang Flow Framework
https://github.com/coc1961/flow
flow framwework go golang
Last synced: about 1 month ago
JSON representation
Simple Golang Flow Framework
- Host: GitHub
- URL: https://github.com/coc1961/flow
- Owner: coc1961
- Created: 2019-11-27T16:00:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-29T00:30:49.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T15:04:23.271Z (6 months ago)
- Topics: flow, framwework, go, golang
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flow
Simple framework to design workflows based on processes connected through channels.
> Each process has an input channel and an output channel,the output channel is the input channel of the next process.
> Each process is responsible for closing the output channel when no more information will be sent.
> Each process will process the data received from its input channel until the end of the data.
> Each created process can be reused in other flows
Creating a Process:
```go
type Summarizer struct {
}func (p Summarizer) Process(input flow.Chan, output flow.Chan, ctx flow.Context) {
//Cast input and output channels
in := input.(chan int)
out := output.(chan int)//I close the output channel, when no more data to send
defer close(out)//I add the input values and accumulate the total
tot:=0
for {
num, ok := <-in
if !ok {
break
}
tot += nuk
}//Send the total to the output channel
out <- tot}
```Creating a Flow
```go
// I create the flow with an instance of Process.
// The input channel of the flow.
// The output channel of the flow
fl := flow.New(Summarizer{}, make(chan int, 0))// I create the flow data input channel
input := make(chan string, 1)ctx := flow.Context{}
//Start the flow
outChan := fl.Start(input, ctx)
```Using the Flow
```go
//Send data to the flow
input <- 10
input <- 20
input <- 30
input <- 40//No more data to send, I close the channel
close(input)//Cast the flow outflow and get the result
out := outChan.(chan int)
total := <-out
fmt.Println(total)//Printed Result is
100
```Adding Processes to the Flow
```go
// I create the flow with an instance of Process.
// The input channel of the flow.
// The output channel of the flow
fl := flow.New(Summarizer{}, input, make(chan int, 0))// I add a new process to the flow ToString
// This process has as input channel the output channel of Summarizer
// The output channel of the ToString process is of type string
// This process takes the Summarize total and transforms it into a string
fl.Add(ToString{}, make(chan string, 0))// I create the flow data input channel
input := make(chan string, 1)ctx := flow.Context{}
//Start the flow
outChan := fl.Start(input, ctx)// I execute the flow and now the total 100 number is transformed into a string as shown below
//Cast the flow outflow and get the result
out := outChan.(chan string)
total := <-out
fmt.Println(total)//Printed Result is
"The Total is : 100"```