https://github.com/abiosoft/injekt
Pluggable service injector
https://github.com/abiosoft/injekt
Last synced: over 1 year ago
JSON representation
Pluggable service injector
- Host: GitHub
- URL: https://github.com/abiosoft/injekt
- Owner: abiosoft
- License: apache-2.0
- Created: 2016-08-16T09:05:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-16T21:23:20.000Z (almost 10 years ago)
- Last Synced: 2025-01-23T14:51:15.353Z (over 1 year ago)
- Language: Go
- Size: 10.7 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# injekt
Pluggable service injector
[](https://godoc.org/github.com/abiosoft/injekt)
[](https://travis-ci.org/abiosoft/injekt)
[](https://goreportcard.com/report/github.com/abiosoft/injekt)
[](https://coveralls.io/github/abiosoft/injekt?branch=master)
Injekt is a pluggable service injector for any project or framework.
Injekt adds service injection support by wrapping a custom function (with services as parameters) with the required function.
### Usage (http Handler example)
Write custom function. `session` will be injected as well as specified parameters of the required function.
```go
func sessionInfo(w http.ResponseWriter, session *Session) {
if session == nil {
// show login page
}
...
}
```
Wrap custom function. This returns an `interface{}` that can be asserted to the required function type.
```go
func main(){
var h http.HandlerFunc
inj := injekt.New(h)
...
http.HandleFunc("/", inj.Wrap(sessionInfo).(http.HandlerFunc))
}
```
Register services before function is executed.
```go
session := ...
inj.Register(session)
```
Simple and useful.
Check the [docs](https://godoc.org/github.com/abiosoft/injekt) for more.
### License
Apache 2