Samuel A. Falvo II | fd78c30 | 2013-06-25 16:35:32 -0700 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import ( |
| 4 | ) |
| 5 | |
| 6 | type Provider struct { |
Samuel A. Falvo II | 5d0d74c | 2013-06-25 17:23:18 -0700 | [diff] [blame^] | 7 | AuthEndpoint string |
Samuel A. Falvo II | fd78c30 | 2013-06-25 16:35:32 -0700 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | var providerMap = make(map[string]*Provider) |
| 11 | |
| 12 | func (c *Context) RegisterProvider(name string, p *Provider) error { |
Samuel A. Falvo II | 5d0d74c | 2013-06-25 17:23:18 -0700 | [diff] [blame^] | 13 | if p.AuthEndpoint == "" { |
| 14 | return ErrConfiguration |
| 15 | } |
| 16 | |
Samuel A. Falvo II | fd78c30 | 2013-06-25 16:35:32 -0700 | [diff] [blame] | 17 | c.providerMap[name] = p |
| 18 | return nil |
| 19 | } |
| 20 | |
| 21 | func (c *Context) ProviderByName(name string) (p *Provider, err error) { |
| 22 | for provider, descriptor := range c.providerMap { |
| 23 | if name == provider { |
| 24 | return descriptor, nil |
| 25 | } |
| 26 | } |
| 27 | return nil, ErrProvider |
| 28 | } |