2017-10-31 21:40:58 +00:00
|
|
|
package organizations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2017-11-01 13:49:02 +00:00
|
|
|
type contextKey string
|
|
|
|
|
|
|
|
const ContextKey = contextKey("organization")
|
2017-10-31 21:40:58 +00:00
|
|
|
|
|
|
|
func validOrganization(ctx context.Context) error {
|
|
|
|
// prevents panic in case of nil context
|
|
|
|
if ctx == nil {
|
|
|
|
return fmt.Errorf("expect non nil context")
|
|
|
|
}
|
2017-11-01 13:49:02 +00:00
|
|
|
orgID, ok := ctx.Value(ContextKey).(string)
|
2017-10-31 21:40:58 +00:00
|
|
|
// should never happen
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("expected organization key to be a string")
|
|
|
|
}
|
|
|
|
if orgID == "" {
|
|
|
|
return fmt.Errorf("expected organization key to be set")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|