https://github.com/malisetti/gowire-example
Package design in Golang with wire DI
https://github.com/malisetti/gowire-example
depencyinjection golang wire
Last synced: 3 months ago
JSON representation
Package design in Golang with wire DI
- Host: GitHub
- URL: https://github.com/malisetti/gowire-example
- Owner: malisetti
- License: gpl-3.0
- Created: 2023-09-23T08:48:01.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T16:37:43.000Z (over 2 years ago)
- Last Synced: 2025-06-12T05:55:19.988Z (about 1 year ago)
- Topics: depencyinjection, golang, wire
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gowire-example
## Overview
This is a demonstration of a Go application that utilizes the Wire framework for dependency injection. The application is an HTTP server that exposes string transformations as an API. It accepts requests with parameters such as `/?transform=0&message=hello` to perform various string transformations.
## Packages
- `cmd/hello` is the main package which uses other packages and starts a http server
- `config` is the package to contain individual configs and combined together the whole app configuration
- `handlers` package contains http handlers
- `hello` package contains domain specific transform functionality
- `server` package uses available handlers, configuration to expose a http mux at different end points
- `valet` package is an example to extend the functionality from `hello` package
## Wire usage
- Wire is employed as a compile-time depenedency generation tool
- Each package contains a `wire.go` where the `injectors` are listed
- Each package contains `providers` and wire `Set`s
- Using wire, packages can be loosely coupled and easily testable
## Package design considerations
- Each type declares the interfaces that it depends on and also describes its own behaviour with an interface
- If the dependency is known, it goes as property. If it not known then as a functon argument. The type's dependencies are provided by `wire`
- Keep dependencies to only what are required
## Notes
- Consider good(simple and clear) APIs
- Prefer smaller packages
- Use composition to express clean requirements
- Recheck and verify the generated wire `injector`s
## References
- https://github.com/google/wire
- https://go.dev/blog/wire
- https://github.com/google/wire/tree/main/docs
- https://en.wikipedia.org/wiki/SOLID
## PRs are welcome
- Thank you