39 lines
758 B
Go
39 lines
758 B
Go
package config
|
|
|
|
import (
|
|
"arno/skeletor/service"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const ServiceName service.Name = "config"
|
|
|
|
func ServiceProvider(config *Config) service.Provider {
|
|
return func(ctn *service.Container) (interface{}, error) {
|
|
return config, nil
|
|
}
|
|
}
|
|
|
|
func From(container *service.Container) (*Config, error) {
|
|
service, err := container.Service(ServiceName)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
|
}
|
|
|
|
srv, ok := service.(*Config)
|
|
if !ok {
|
|
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
|
}
|
|
|
|
return srv, nil
|
|
}
|
|
|
|
func Must(container *service.Container) *Config {
|
|
srv, err := From(container)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return srv
|
|
}
|