TEST REPOSITORY; DO NOT USE IT

Gontainer
Depenendency Injection container for GO inspired by Symfony.
Docs
- Documentation
- Meta
- Parameters
- Services
- Decorators
- Use cases
- Composition Root
- Contextual scope
- Examples
- Interface
Installation
TODO
TL;DR
Describe dependencies in YAML
File gontainer/gontainer.yml:
meta:
pkg: "gontainer"
constructor: "New"
parameters:
appPort: '%envInt("APP_PORT", 9090)%' # get the port from the ENV variable if it exists, otherwise, use the default one
services:
endpointHelloWorld: # sample HTTP endpoint
constructor: "http.NewHelloWorld"
serveMux:
constructor: '"net/http".NewServeMux'
calls:
- [ "Handle", [ "/hello-world", "@endpointHelloWorld" ] ]
server:
getter: "GetServer"
must_getter: true # define method MustGetServer
value: '&"net/http".Server{}'
type: '*"net/http".Server'
fields:
Addr: ":%appPort%"
Handler: "@serveMux"
Compile it
gontainer build -i gontainer/gontainer.yml -o gontainer/container.go
# it can read multiple configuration files, e.g.
# gontainer build -i gontainer/gontainer.yml -i gontainer/dev/*.yml -o gontainer/container.go
Voilà!
File main.go:
package main
import (
"github.com/user/repo/gontainer"
)
func main() {
c := gontainer.New()
s := c.MustGetServer()
err := s.ListenAndServe()
if err != nil {
panic(err)
}
}