Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pior/mikado
Service manager with dependency injection for Golang
https://github.com/pior/mikado
Last synced: 2 days ago
JSON representation
Service manager with dependency injection for Golang
- Host: GitHub
- URL: https://github.com/pior/mikado
- Owner: pior
- Created: 2021-03-07T21:39:36.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-07T23:33:13.000Z (almost 4 years ago)
- Last Synced: 2023-04-13T23:12:19.895Z (almost 2 years ago)
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mikado
**This is a work in progress**
- Automatic dependency injection (reflection based)
- Service management based on the [pior/runnable] interface
- Service lifecycle depends on dependencies
- Start after the dependencies, stop before them
- Concurrent service start and stopLimitations:
- Variadic parameters are not supported in constructors### Example:
```go
package mainimport (
"context""github.com/pior/runnable"
)type Config struct {
DatabaseHost string
}func BuildConfig(cliOption *CLIOption) *Config {
return &Config{DatabaseHost: "127.0.0.1"}
}type Database struct{}
func NewDatabase(cfg *Config) *Database {
return &Database{}
}func (d *Database) Run(ctx context.Context) error {
// database has started
<-ctx.Done()
// database has stopped
return nil
}type Server struct{}
func NewServer(cfg *Config, cli *CLIOption, db *Database) *Server {
return &Server{}
}func NewServerBase() *Server {
return &Server{}
}func (s *Server) Run(ctx context.Context) error {
// server is doing something
<-ctx.Done()
// server has stopped
return nil
}func Main() {
a := mikado.New()a.AddProvider(BuildConfig)
a.AddRunnable(NewDatabase)
a.AddRunnable(NewServer)runnable.Run(a) // err := a.Run(context.Background())
}
```