Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ALL is a shorthand for the ALL special group ALL = []string{"ALL"} // NONE is a shorthand for the NONE special group NONE = []string{"NONE"} )
var Default = &Wave{}
Default is a Wave instance using the default InMemoryBackend.
var ( // ErrFeatureNotFound should be returned by FeatureBackend.Get if the // feature cannot be found. ErrFeatureNotFound = errors.New("feature not found") )
Functions ¶
func AddFeature ¶
AddFeature is a convenience function that calls Default.AddFeature.
func Register ¶
func Register(name string, backend FeatureBackend)
Register will register a FeatureBackend wave.
Types ¶
type Feature ¶
Feature is a specific feature and its constraints.
func NewFeatureGroups ¶
NewFeatureGroups will create a new feature name, which only allows access to users belonging to the listed groups.
func NewFeatureUsers ¶
NewFeatureUsers will create a new feature name, which only allows access to the provided users.
type FeatureBackend ¶
type FeatureBackend interface {
// Open should take in a single argument of any type that it needs to
// connect to its backend. Then it must connect to the backend or return
// and error For instance, a SQLBackend might take in a MySQL connection
// string and return connection timeout errors.
Open(string) error
// Close is called by the user to close the backend connection.
Close() error
// Get takes in a feature name string and returns the feature that
// matches that name, or it should return ErrFeatureNotFound.
Get(string) (*Feature, error)
// Set is called by a Wave instance in order to add a feature to the
// backend. The first argument is the feature name and the second is
// the feature.
Set(string, *Feature) error
}
FeatureBackend is the interface which different backends must implement in order to be used with wave.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is a FeatureBackend which simply holds the feature information in-memory. This is just a default so that it is there, this really shouldn't be used in real serious software.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates a new InMemoryBackend.
func (*InMemoryBackend) Close ¶
func (imb *InMemoryBackend) Close() error
Close wipes and clears the in-memory feature storage.
func (*InMemoryBackend) Get ¶
func (imb *InMemoryBackend) Get(name string) (*Feature, error)
Get returns a feature by name if it exists.
func (*InMemoryBackend) Open ¶
func (imb *InMemoryBackend) Open(string) error
Open literally does nothing. This is here to implement the FeatureBackend.
type User ¶
type User interface {
// ID returns the unique identitfier for the particular user.
ID() string
// Groups returns a string slice of group names to which the user belongs.
Groups() []string
}
User must be implemented by any type wishing to have feature permissions managed by wave. For instance, your application's User must implement this.
type Wave ¶
type Wave struct {
// When UndefinedAccess is false, the users will NOT be granted access
// to features of undefined names.
UndefinedAccess bool
// contains filtered or unexported fields
}
Wave manages all of the interactions between you and the FeatureBackend.
func (*Wave) AddFeature ¶
AddFeature adds a Feature to the wave instance.
func (*Wave) SetBackend ¶
SetBackend sets the FeatureBackend for this wave instance. It will panic if the named backend is not registered.