2020-04-27 22:43:42 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/service"
|
|
|
|
)
|
|
|
|
|
2020-06-15 21:05:28 +02:00
|
|
|
// ServiceName defines the project's service
|
2020-04-27 22:43:42 +02:00
|
|
|
const ServiceName service.Name = "config"
|
|
|
|
|
|
|
|
// From retrieves the config service in the given container
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must retrieves the config service in the given container or panic otherwise
|
|
|
|
func Must(container *service.Container) *Config {
|
|
|
|
srv, err := From(container)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return srv
|
|
|
|
}
|