hydra-webauthn/internal/storage/service.go

42 lines
896 B
Go
Raw Permalink Normal View History

2023-11-15 20:38:25 +01:00
package storage
import (
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/service"
)
const ServiceName service.Name = "storage"
// From retrieves the storage service in the given container
func From(container *service.Container) (*Service, error) {
service, err := container.Service(ServiceName)
if err != nil {
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
}
srv, ok := service.(*Service)
if !ok {
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
}
return srv, nil
}
// Must retrieves the storage service in the given container or panic otherwise
func Must(container *service.Container) *Service {
srv, err := From(container)
if err != nil {
panic(err)
}
return srv
}
type Service struct {
userRepository UserRepository
}
func (s *Service) User() UserRepository {
return s.userRepository
}