fake-smtp/internal/storm/service.go

35 lines
795 B
Go
Raw Permalink Normal View History

2020-04-17 17:53:01 +02:00
package storm
import (
"github.com/asdine/storm/v3"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/service"
)
const ServiceName service.Name = "storm"
// From retrieves the storm service in the given container
func From(container *service.Container) (*storm.DB, error) {
service, err := container.Service(ServiceName)
if err != nil {
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
}
srv, ok := service.(*storm.DB)
if !ok {
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
}
return srv, nil
}
// Must retrieves the storm service in the given container or panic otherwise
func Must(container *service.Container) *storm.DB {
srv, err := From(container)
if err != nil {
panic(err)
}
return srv
}