{"id":23350673,"url":"https://github.com/shaching/goflux","last_synced_at":"2025-04-07T18:20:22.579Z","repository":{"id":57582869,"uuid":"168087940","full_name":"shaching/goflux","owner":"shaching","description":"A Flux Architecture in Go.","archived":false,"fork":false,"pushed_at":"2020-03-24T16:12:41.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T03:34:08.447Z","etag":null,"topics":["design-patterns","flux","flux-architecture","go","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaching.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":"2019-01-29T04:18:18.000Z","updated_at":"2023-08-20T15:49:54.000Z","dependencies_parsed_at":"2022-08-31T00:41:33.135Z","dependency_job_id":null,"html_url":"https://github.com/shaching/goflux","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaching%2Fgoflux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaching%2Fgoflux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaching%2Fgoflux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaching%2Fgoflux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaching","download_url":"https://codeload.github.com/shaching/goflux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704579,"owners_count":20982299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["design-patterns","flux","flux-architecture","go","golang"],"created_at":"2024-12-21T08:17:15.950Z","updated_at":"2025-04-07T18:20:22.543Z","avatar_url":"https://github.com/shaching.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goflux\n\u003e Callback is usually used between different objects' data transmission and it will cause callback hell. So, decoupling is must necessary and goflux can solve the problem.\n\n## What is FLUX? See Here https://facebook.github.io/flux/\n\n# Step 1. Install goflux.\n\n````\ngo get github.com/shaching/goflux\n``````\n\n# Step 2. Construct go channels.\n* The ***listener*** is must be ***chan \\*Action*** type in your type struct.\n* Notice: Remember implement ***Step 4.***\n    \n```golang\ntype earth struct {\n    address   string\n    listener  chan *goflux.Action\n}\n\ne := \u0026earth{\n    address:   \"Earth\",\n    listener:  make(chan *goflux.Action),\n}\n```\n\n```golang\ntype mars struct {\n    address   string\n    listener  chan *goflux.Action\n}\n\nm := \u0026mars{\n    address:   \"Mars\",\n    listener:  make(chan *goflux.Action),\n}\n```\n\n# Step 3. Create a action including below four parameters.\n* name: action name.\n* from: where action comes from.\n* to: where action goes to.\n* payload: data.\n\n```golang\ngoflux.Send(\"ActionCall\", \"Earth\", \"Mars\", \"Hi\", \"Mom\")\nor\ngoflux.Send(\"ActionReCall\", \"Mars\", \"Earth\", \"Hello\", \"Dad\")\n```\n\n# Step 4. Implement your flux store with goroutine listener func.\n* Notice: Register listener inner goroutine func.\n* Notice: You can filter action here.\n\n```golang\ngo e.store() \u003c-- Start goroutine.\n\nfunc (e *earth) store() {\n    goflux.Register(e.address, e.listener) \u003c-- Register Flux.\n\n    for {\n        action, ok := \u003c-e.listener\n        \n        if !ok {\n            return\n        }\n        \n        // action.Name().(string)        --\u003e ActionReCall\n        // action.From().(string)        --\u003e Mars\n        // action.To().(string)          --\u003e Earth\n        // action.Payload()[0].(string)  --\u003e Hello\n        // action.Payload()[1].(string)  --\u003e Dad\n\n        // you can handle received action here\n    }\n}\n```\n\n```golang\ngo m.store() \u003c-- Start goroutine.\n\nfunc (m *mars) store() {\n    goflux.Register(m.address, m.listener) \u003c-- Register Flux.\n    \n    for {\n        action, ok := \u003c-m.listener\n        \n        if !ok {\n            return\n        }\n        \n        // action.Name().(string)        --\u003e ActionCall\n        // action.From().(string)        --\u003e Earth\n        // action.To().(string)          --\u003e Mars\n        // action.Payload()[0].(string)  --\u003e Hi\n        // action.Payload()[1].(string)  --\u003e Mom\n        \n        // you can handle received action here\n    }\n}\n```\n\n# Step 5. Also, unregister when you wan't use.\n* Notice: DON'T manual close channel by yourself, goflux will automatic close it. \n\n```golang\ngoflux.UnRegister(e.address, e.listener)\nor\ngoflux.UnRegister(m.address, m.listener)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaching%2Fgoflux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaching%2Fgoflux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaching%2Fgoflux/lists"}