{"id":13413437,"url":"https://github.com/boot-go/boot","last_synced_at":"2025-03-14T19:32:11.684Z","repository":{"id":46807564,"uuid":"391620768","full_name":"boot-go/boot","owner":"boot-go","description":"Configuration and dependency injection","archived":false,"fork":false,"pushed_at":"2024-01-29T00:43:43.000Z","size":84,"stargazers_count":30,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T20:07:46.421Z","etag":null,"topics":["dependency-injection","go","golang","microservices"],"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/boot-go.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-01T12:26:55.000Z","updated_at":"2024-04-29T15:02:18.049Z","dependencies_parsed_at":"2024-04-29T15:02:16.785Z","dependency_job_id":"8c52d105-e2a6-4916-89ec-0a7182fd886b","html_url":"https://github.com/boot-go/boot","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boot-go%2Fboot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boot-go%2Fboot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boot-go%2Fboot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boot-go%2Fboot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boot-go","download_url":"https://codeload.github.com/boot-go/boot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635422,"owners_count":20322935,"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":["dependency-injection","go","golang","microservices"],"created_at":"2024-07-30T20:01:40.369Z","updated_at":"2025-03-14T19:32:11.376Z","avatar_url":"https://github.com/boot-go.png","language":"Go","readme":"\u003cdiv\u003e\n    \u003cdiv align=\"center\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/80048065?s=200\u0026u=a95ef12cecad462ed24df9418a8464241301cc16\"/\u003e\u003c/div\u003e\n    \u003cdiv align=\"center\"\u003e\n        \u003ca href=\"https://github.com/boot-go/boot/tags\"\u003e\u003cimg alt=\"Commit tag\" src=\"https://img.shields.io/github/v/tag/boot-go/boot\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://github.com/boot-go/boot/actions/workflows/action.yml\"\u003e\u003cimg src=\"https://github.com/boot-go/boot/actions/workflows/action.yml/badge.svg?branch=main\" alt=\"github action\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://htmlpreview.github.io/?https://gist.githubusercontent.com/boot-go/c77b22000b3e249510dfb4542847c708/raw/ae9b2e83e9a4adafed6da2160e40855f86ca58a8/cover.html\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/boot-go/c77b22000b3e249510dfb4542847c708/raw/test_coverage.json\" alt=\"test coverage\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://goreportcard.com/report/github.com/boot-go/boot\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/boot-go/boot\" alt=\"go report\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://pkg.go.dev/github.com/boot-go/boot\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/boot-go/boot.svg\" alt=\"Go Reference\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"License: MIT\"\u003e\u003c/a\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n\n**boot-go** accentuate [component-based development](https://en.wikipedia.org/wiki/Component-based_software_engineering) (CBD).\n\nThis is an opinionated view of writing modular and cohesive [Go](https://github.com/golang/go) code. It emphasizes the separation of concerns by loosely coupled components, which communicate with each other via methods and events. The goal is to support writing maintainable code on the long run by leveraging the well-defined standard library.\n\n**boot-go** provided key features are:\n- dependency injection\n- configuration handling\n- code decoupling\n\n### Development characteristic\n**boot-go** supports two different development characteristic. For simplicity reason, use the functions ```Register```, ```RegisterName```, ```Override```, ```OverrideName```, ```Shutdown``` and ```Go``` to register components and start **boot-go**. This is the recommended way, despite the fact that one global session is used.\n\nBut **boot-go** supports also creating new sessions, so that no global variable is required. In this case, the methods ```Register```, ```RegisterName```, ```Override```, ```OverrideName```, ```Shutdown``` and ```Go``` are provided to register components and start **boot-go**.\n\n### Simple Example\nThe **hello** component is a very basic example. It contains no fields or provides any interface to interact with other components. The component will just print the _'Hello World'_ message to the console.\n```go\npackage main\n\nimport (\n\t\"github.com/boot-go/boot\"\n\t\"log\"\n)\n\n// init() registers a factory method, which creates a hello component.\nfunc init() {\n\tboot.Register(func() boot.Component {\n\t\treturn \u0026hello{}\n\t})\n}\n\n// hello is the simplest component.\ntype hello struct{}\n\n// Init is the initializer of the component.\nfunc (c *hello) Init() error {\n\tlog.Printf(\"boot-go says \u003e 'Hello World'\\n\")\n\treturn nil\n}\n\n// Start the example and exit after the component was completed.\nfunc main() {\n\tboot.Go()\n}\n```\n\nThe same example using a new session, which don't need any global variables.\n```Go\npackage main\n\nimport (\n\t\"github.com/boot-go/boot\"\n\t\"log\"\n)\n\n// hello is the simplest component.\ntype hello struct{}\n\n// Init is the initializer of the component.\nfunc (c *hello) Init() error {\n\tlog.Printf(\"boot-go says \u003e 'Hello World'\\n\")\n\treturn nil\n}\n\n// Start the example and exit after the component was completed.\nfunc main() {\n\ts := boot.NewSession()\n\ts.Register(func() boot.Component {\n\t\treturn \u0026hello{}\n\t})\n\ts.Go()\n}\n```\n\n### Component wiring\nThis example shows how components get wired automatically with dependency injection. The server component starts at ```:8080``` by default, but the port is configurable by setting the environment variable ```HTTP_SERVER_PORT```. \n```go\npackage main\n\nimport (\n\t\"github.com/boot-go/boot\"\n\t\"github.com/boot-go/stack/server/httpcmp\"\n\t\"io\"\n\t\"net/http\"\n)\n\n// init() registers a factory method, which creates a hello component\nfunc init() {\n\tboot.Register(func() boot.Component {\n\t\treturn \u0026hello{}\n\t})\n}\n\n// hello is a very simple http server example.\n// It requires the Eventbus and the chi.Server component. Both components\n// are injected by the boot framework automatically\ntype hello struct {\n\tEventbus boot.EventBus  `boot:\"wire\"`\n\tServer   httpcmp.Server `boot:\"wire\"`\n}\n\n// Init is the constructor of the component. The handler registration takes place here.\nfunc (h *hello) Init() error {\n\t// Subscribe to the registration event\n\th.Eventbus.Subscribe(func(event httpcmp.InitializedEvent) {\n\t\th.Server.HandleFunc(\"/\", func(writer http.ResponseWriter, request *http.Request) {\n\t\t\tio.WriteString(writer, \"boot-go says: 'Hello World'\\n\")\n\t\t})\n\t})\n\treturn nil\n}\n\n// Start the example and test with 'curl localhost:8080'\nfunc main() {\n\tboot.Go()\n}\n```\n\n### Component\nEverything in **boot-go** starts with a component. They are key fundamental in the development and can be considered as an elementary build block. The essential concept is to get all the necessary components functioning with as less effort as possible. Therefore, components must always provide a default configuration, which uses the most common settings. As an example, a **http server** should always start using port **8080**, unless the developer specifies it. Or a postgres component should try to connect to **localhost:5432** when there is no database url provided.\n\nA component should be _fail tolerant_, _recoverable_, _agnostic_ and _decent_.\n\n| Facet           | Meaning                                       | Example                                                                                                                                                                         |\n|-----------------|-----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| _fail tolerant_ | Don't stop processing on errors.              | A http request can still be processed, even when the metrics server is not available anymore.                                                                                   |\n| _recoverable_   | Try to recover from errors.                   | A database component should try to reconnect after losing the connection.                                                                                                       |\n| _agnostic_      | Behave the same in any environment.           | A key-value store component should work on a local development machine the same way as in a containerized environment.                                                          |\n| _decent_        | Don't overload the developer with complexity. | Keep the interface and events as simple as possible. It's better to build three smaller but specific components then one general with increased complexity. Less is often more. |\n\n### Configuration\nConfiguration values can also be automatically injected with arguments or environment variables at start time. The value from ```USER``` will be used in this example. If the argument ```--USER madpax``` is not set and the environment variable is not defined, it is possible to specify the reaction whether the execution should stop with a panic or continue with a warning.\n```go\npackage main\n\nimport (\n\t\"github.com/boot-go/boot\"\n\t\"log\"\n)\n\n// hello is still a simple component.\ntype hello struct{\n\tOut string `boot:\"config,key:USER,default:madjax\"` // get the value from the argument list or environment variable. If no value could be determined, then use the default value `madjax`.\n}\n\n// init() registers a factory method, which creates a hello component and returns a reference to it.\nfunc init() {\n\tboot.Register(func() boot.Component {\n\t\treturn \u0026hello{}\n\t})\n}\n\n// Init is the initializer of the component.\nfunc (c *hello) Init() error {\n\tlog.Printf(\"boot-go says \u003e 'Hello %s'\\n\", c.Out)\n\treturn nil\n}\n\n// Start the example and exit after the component was completed\nfunc main() {\n\tboot.Go()\n}\n\n```\n\n\n### boot stack\n**boot-go** was primarily designed to build opinionated frameworks and bundle them as a stack. So every developer or company can choose to use the [default stack](https://github.com/boot-go/stack), a shared stack or rather create a new one. Stacks should be build with one specific purpose in mind for building a **microservice**, **ui application**, **web application**, **data analytics application** and so on. As an example, a **web application boot stack** could contain a http server component, a sql database component, a logging and a web application framework.\n\n\n### Examples\nMore examples can be found in the [tutorial repository](https://github.com/boot-go/tutorial).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboot-go%2Fboot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboot-go%2Fboot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboot-go%2Fboot/lists"}