William Petit
3ef495445a
serveur - Création d'un service d'autorisation dynamique basé sur des "voter" (à la Symfony) - Mise en place des autorisations sur les principales queries/mutations de l'API GraphQL
34 lines
764 B
Go
34 lines
764 B
Go
package voter
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"gitlab.com/wpetit/goweb/service"
|
|
)
|
|
|
|
const ServiceName service.Name = "voter"
|
|
|
|
// From retrieves the voter service in the given container.
|
|
func From(container *service.Container) (*Manager, error) {
|
|
service, err := container.Service(ServiceName)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
|
}
|
|
|
|
srv, ok := service.(*Manager)
|
|
if !ok {
|
|
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
|
}
|
|
|
|
return srv, nil
|
|
}
|
|
|
|
// Must retrieves the voter service in the given container or panic otherwise.
|
|
func Must(container *service.Container) *Manager {
|
|
srv, err := From(container)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return srv
|
|
}
|