{"id":40313006,"url":"https://github.com/en-v/korn","last_synced_at":"2026-01-20T06:36:41.145Z","repository":{"id":57627480,"uuid":"403279714","full_name":"en-v/korn","owner":"en-v","description":"The reactive engine and in-memory database. Can store and restore data to/from JSON files or MongoDB. Written in Go for Go.","archived":false,"fork":false,"pushed_at":"2021-10-19T22:14:52.000Z","size":202,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T23:08:15.200Z","etag":null,"topics":["json","mongodb","reactive"],"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/en-v.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":"2021-09-05T10:34:04.000Z","updated_at":"2021-10-19T22:14:55.000Z","dependencies_parsed_at":"2022-09-17T10:40:49.026Z","dependency_job_id":null,"html_url":"https://github.com/en-v/korn","commit_stats":null,"previous_names":["en-v/reactor","en-v/kor"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/en-v/korn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-v%2Fkorn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-v%2Fkorn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-v%2Fkorn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-v%2Fkorn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/en-v","download_url":"https://codeload.github.com/en-v/korn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-v%2Fkorn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28597668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"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":["json","mongodb","reactive"],"created_at":"2026-01-20T06:36:41.094Z","updated_at":"2026-01-20T06:36:41.138Z","avatar_url":"https://github.com/en-v.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"```\n██╗░░██╗░█████╗░██████╗░███╗░░██╗\n██║░██╔╝██╔══██╗██╔══██╗████╗░██║\n█████═╝░██║░░██║██████╔╝██╔██╗██║\n██╔═██╗░██║░░██║██╔══██╗██║╚████║\n██║░╚██╗╚█████╔╝██║░░██║██║░╚███║\n╚═╝░░╚═╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚══╝\n```\n\nThe reactive engine and in-memory database.\\\nCan store and restore data to/from JSON files or MongoDB.\\\nWritten in Go for Go.\n```\nKORN = Keep + Observe + React + eNgine\n```\n# Quick Start [ 5 steps ]\n\n### 1. Defining\nDefine your own observable structure or structures.\\\nNested structures are allowed so you can feel free and have no nesting level limitations.\n```go\ntype User struct {\n    korn.Inset `korn:\"-\" bson:\",inline\"` \n    Name    string `korn:\"nameChanged\"`\n    Enabled bool   `korn:\"enabledChanged\"`\n}\n```\nUse **korn.Inset** as embedded part of the root structure. Tags `korn:\"-\" bson:\",inline\"` are necessray required.\nJust copy and paste this line ``korn.Inset `korn:\"-\" bson:\",inline\"`` into each structure you need to use with KORN.\nIf you forget **korn.Inset** or tags then your app will catch a panic. \nIf your structure has nested structures, you only need to add **korn.Inset** into the root structure.\nYou have to remember that **korn.Inset** contains **Id** and **Updated** fields.\n(**Id** field has BSON-tag \"_id\" and \"string\" type. **Updated** field contains the last commit date and time.)\n\n*Warning 1: Do NOT add your own Id and Updated fields to your structure. It will cause panic.*\\\n*Warning 2: Do NOT change Id and Updated values - it will lead to errors.*\\\n\nTag `korn` contains an action name that will invoke when the field value changes.\n\n### 2. Init Korn\nCreate basic KORN actors: Engine and Holder.\\\nBind reactions names and handlers.\\\nMake and capture observable targets.\n\n```go\nengine := korn.Engine(\"demo\")\nholder, err := engine.Holder(\"users\", User{})\n\nholder.Bind(\"add\", addHandler) \nholder.Bind(\"remove\", removeHandler) \nholder.Bind(\"update\", updateHandler) \n\nholder.Bind(\"nameChanged\", nameChangedHandler) // one regular event minimum requried\nholder.Bind(\"enabledChanged\", enabledChangedHandler)\nerr = holder.CheckBindings()\n```\nBasic actions `add` and `remove` and `update` must always be defined and bound.\nYou can use more than one holder.\\ \nHolders count is unlimited but you have to remember that name of the holder must be unique.\\\nIf you have many types of data then your scenario is \"one holder per one type\".\n\nYou can bind basic actions with single method:\n```go \nholder.BindBasic(addHandler, removeHandler, updateHandler)\n```\nIf you don't want to bind basic method you should use an empty handler:\n```go \nholder.BindBasic(addHandler, removeHandler, korn.EmptyHandler())\n```\n\n### 3. Don't forget about data storing\nAdd one of two kinds storage if you need it. The storage using is optional.\\\nYou can use NO data storage then your data will be lost after your app close (it is a useful case for temporary data).\n\n**JSF** - storage based on simle JSON files (one file per object):\n```go\nengine.Connect(\"\") \nengine.Restore() \n```\n**MDB** - MongoDB storage:\n```go\nengine.Connect(\"mongodb://localhost\") \nengine.Restore() \n```\nCall the `Restore()` method if you need to restore the last saved data from the storage.\n\n### 4. Make and capture your data\nCreate and catch some data objects.\\\nIf you are using storage then captured objects will store automatically.\n```go\nusers := map[string]*User{\n    \"root\": user(\"root\"), \n    \"bob\": user(\"bob\"), \n    \"guest\": nil,\n}\nholder.Capture(users) // capture targets \nengine.Activate() // activate the engine \u003e reactivity enabling\n```\n\n### 5. Perform\nDo something with your data.\n\n```go\nuser := holder.Get(\"bob\").(*User) // get from the holder and cast to origin type pointer\nuser.Name = \"Bob Smith\" // do something...\n...\nuser.Enabled = false // do something else...\nuser.Commit() \n```\n`Commit()` method is needed to cause reactions and save the changes.\nAlso you can catch errors from reactions.\n\n```go\nerr := user.Commit() \nif err != nil {\n    panic(err)\n}\n```\n\nFor your enjoyment you can make a wrapper for the holder and it provides your type casting easy. \\\nAs well all package methods return an error value and your code will stay clean ever :)\n\n***\n\n[Full example code](https://github.com/en-v/korn/blob/main/examples/example.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen-v%2Fkorn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fen-v%2Fkorn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen-v%2Fkorn/lists"}