{"id":41690695,"url":"https://github.com/konimarti/flow","last_synced_at":"2026-01-24T20:15:07.593Z","repository":{"id":57509135,"uuid":"159141137","full_name":"konimarti/flow","owner":"konimarti","description":"Create simple flows based on user-defined filters (data stream processing).","archived":false,"fork":false,"pushed_at":"2019-07-09T11:33:44.000Z","size":93,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T16:11:16.482Z","etag":null,"topics":["data-processing","filter","flow","flow-based-programming","flow-control","golang","notifications","observer","pipeline","pipelines","publish-subscribe","real-time","sensor","sensor-monitor","sensors-data-collection","stream-processing","streaming"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/konimarti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-26T09:10:46.000Z","updated_at":"2025-08-05T06:28:57.000Z","dependencies_parsed_at":"2022-09-10T15:51:34.858Z","dependency_job_id":null,"html_url":"https://github.com/konimarti/flow","commit_stats":null,"previous_names":["konimarti/pipeline","konimarti/observer"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/konimarti/flow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konimarti%2Fflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konimarti%2Fflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konimarti%2Fflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konimarti%2Fflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konimarti","download_url":"https://codeload.github.com/konimarti/flow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konimarti%2Fflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28736502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T19:23:36.361Z","status":"ssl_error","status_checked_at":"2026-01-24T19:23:28.966Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-processing","filter","flow","flow-based-programming","flow-control","golang","notifications","observer","pipeline","pipelines","publish-subscribe","real-time","sensor","sensor-monitor","sensors-data-collection","stream-processing","streaming"],"created_at":"2026-01-24T20:15:06.877Z","updated_at":"2026-01-24T20:15:07.585Z","avatar_url":"https://github.com/konimarti.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":" # Stream processing flow in Go\n\n[![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/konimarti/flow/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/konimarti/flow?status.svg)](https://godoc.org/github.com/konimarti/flow)\n[![goreportcard](https://goreportcard.com/badge/github.com/konimarti/flow)](https://goreportcard.com/report/github.com/konimarti/flow)\n\nStream processing in Golang with a modular notification behavior based on filters.\n\n```go get github.com/konimarti/flow```\n\n## Usage\n\n1. Define a data stream source: \n```go\nyourSource := flow.Func{\n\tfunc() interface{} {\n\t\treturn rand.Float64()\n\t},\n\t500 * time.Millisecond,\n}\n```\n\n2. Define the stream data processing (i.e. your filters):\n```go\nyourFilters := filters.AboveFloat64{0.5}\n```\n\n3. Create your flow and subscribe to the results:\n```go\nyourFlow := flow.New(\n\tyourFilters,\n\tyourSource,\n)\nresults := yourFlow.Subscribe()\nfor {\n\t\u003c-results.C()\n\tfmt.Println(results.Value())\n}\n```\n\n## Example\n\n* Apply a low-pass filter (exponential smoothing) to a sequence of random numbers between 0 and 1:\n\n```go\nflow := flow.New(\n\t\u0026filters.LowPass{A: 0.1}, \n\t\u0026flow.Func{ \n\t\tfunc(){ return rand.Float64() },\n\t\t500 * time.Millisecond,\n\t},\n)\n```\n\n* Generate a stream of random numbers from a standard normal, calculate moving average, print average and check if average is above or below 0.5 and -0.5, respectively. If so, then notify the subscribers.\n\n```go\n// define stream processor (flow) that returns an observer\nyourFlow := flow.New(\n\tfilters.NewChain(\n\t\t\u0026filters.MovingAverage{Window: 10},\n\t\t\u0026filters.Print{Writer: os.Stdout, Prefix: \"Moving average:\"},\n\t\tfilters.NewSwitch(\n\t\t\t\u0026filters.AboveFloat64{0.5},\n\t\t\t\u0026filters.BelowFloat64{-0.5},\n\t\t),\n\t),\n\t\u0026flow.Func{\n\t\tfunc() interface{} { return rand.NormFloat64() },\n\t\t500*time.Millisecond,\n\t},\n)\n\n// subscribe to flow and listen to events \nresults := yourFlow.Subscribe()\nfor {\n\t\u003c-results.C()\n\tfmt.Println(\"Notified:\", results.Value())\n}\n```\n\n## Description\n\nTwo types of flows are available that are suitable for different use cases:\n* Channel-based flows accept new values through a ```chan interface{}``` channel, and\n* Function-based flows collect new values in regular intervals from a ```func() interface{}``` function.\n\nChannel-based flows are useful in cases where we receive specific events. \nFunction-based flows can be used to monitor any object or state of resources \n(i.e. reading data from [OPC](http://github.com/konimarti/opc), HTTP requests, etc.).\n\n* To get a channel-based flow:\n```go\n// define channel \nch := make(chan interface{})\n\n// define your filter(s) for data processing\nfilter := filters.OnChange{}\n\n// create your flow\nyourChannelFlow := flow.New(\n\t\u0026filter, \n\t\u0026flow.Chan{ch},\n)\n\n// publish new data to channel ch\n// ch \u003c- ..\n```\n\n* To get a function-based flow:\n```go\n// define a function that returns the values\nfn := func() interface{} {\n\treturn rand.Float64()\n}\n\n// define your filter(s)\nfilter := filters.OnChange{}\n\n// create your flow\nyourFunctionFlow := flow.New(\n\t\u0026filter, \n\t\u0026flow.Func{\n\t\tfn, \n\t\t1 * time.Second,\n\t},\n)\n```\n\n* You can subscribe to a flow in order to receive the results from the filter(s):\n```go\nresults := yourFlow.Subscribe()\nfor {\n\t// wait for a result\n\t\u003c-results.C()\n\n\t// get value from the filters\n\tresults.Value()\n}\n\n```\n\n## Filters\n\nThe filters control the behavior of the observer, i.e. they determine when and what values should be sent to the subscribers.  \n\n### Available filters out-of-the-box\n\nThe following filters are currently implemented in this package:\n* Notification filters:\n  - ```None{}```: No filter is applied. All values are sent to the observers unfilitered and unprocessed.\n  - ```Sink{}```: Blocks the flow of data. No values are sent to the observers.\n  - ```Mute{Duration time.Duration}```: Mute shuts down all notifications after an event for a specific duration.\n  - ```OnChange{}```: Notifies when the value changes.\n  - ```OnRisingFlank{}```: Notifies when the value increases.\n  - ```OnValue{value float64}```: Notifies when the new value matches the defined value at initialization. \n  - ```AboveFloat64{threshold float64}```: Notifies when a new float64 is above the pre-defined float64 threshold.\n  - ```BelowFloat64{threshold float64}```: Notifies when a new float64 is below the pre-defined float64 threshold.\n  - ```Sigma{Window int, Factor float64}```: Sigma checks if the incoming value is a certain multiple (=factor) of standard deviations away from the mean.\n\n* Stream-processing filters:\n  - ```MovingAverage{Window int}```: Calculates the moving average over a certain sample size and sends the current mean to all subscribers.\n  - ```StdDev{Window int}```: Calculates the standard deviation over a certain sample size and sends the current standard deviation to all subscribers.\n  - ```LowPass{A float64}```: Performs low-pass filtering on the input data (exponential smoothing) with the smoothing factor A. \n\n### User-defined filters\n\nUser-defined filters can easily be created: Define your struct and embed the ```filters.Model```. You can then customize one or both of the interface functions. \nThe ```filters.None``` is implemented by creating an empty struct and just embedding ```filters.Model```, for example.\n\nThe following user-defined filter expects a float64 value and multiplies it with a pre-defined factor:\n```go\ntype Multiply struct {\n\tfilters.Model\n\tFactor float64\n}\n\nfunc (m *Multiply) Update(v interface{}) interface{} {\n\treturn v.(float64) * m.Factor\n}\n```\n\n### Logical structures\n\nFilters can be chained together using ```filters.NewChain(Filter1, Filter2, ...)```. \n\nTo adjust the notification behavior, the ```filters.NewSwitch``` function can be useful, especially in cases when you want \nto monitor a value that needs to remain within a certain range (\"deadband\").\n\nSee [this example](http://github.com/konimarti/flow/tree/master/example/chain.go) for more information on logical structures \n\n### A stream-processing use case: Anomaly detection \n\nAn anomaly detection example for streams with an user-defined filter based on Lytics' [Anomalyzer](http://github.com/lytics/anomalyzer) \ncan be found [here](http://github.com/konimarti/flow/tree/master/example/anomaly.go).\n\n## More examples\n\nCheck out the examples [here](http://github.com/konimarti/flow/tree/master/example).\n\n## Credits\n\nThis software package has been developed for and is in production at [Kalkfabrik Netstal](http://www.kfn.ch/en).\nThe design of the observer implementation was inspired by [go-observer](http://github.com/imkira/go-observer).\n\n## Disclaimer\n\nThis package is still work-in-progress. Interfaces might still change substantially. It is also not recommended to use it in a production environment at this point.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonimarti%2Fflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonimarti%2Fflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonimarti%2Fflow/lists"}