This patch removes the nested if's in the Get function
and makes the code more readable.
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
| ... | ... |
@@ -111,14 +111,9 @@ func (ps *Store) Remove(p *v2.Plugin) {
|
| 111 | 111 |
|
| 112 | 112 |
// Get returns an enabled plugin matching the given name and capability. |
| 113 | 113 |
func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlugin, error) {
|
| 114 |
- var ( |
|
| 115 |
- p *v2.Plugin |
|
| 116 |
- err error |
|
| 117 |
- ) |
|
| 118 |
- |
|
| 119 | 114 |
// Lookup using new model. |
| 120 | 115 |
if ps != nil {
|
| 121 |
- p, err = ps.GetV2Plugin(name) |
|
| 116 |
+ p, err := ps.GetV2Plugin(name) |
|
| 122 | 117 |
if err == nil {
|
| 123 | 118 |
p.AddRefCount(mode) |
| 124 | 119 |
if p.IsEnabled() {
|
| ... | ... |
@@ -133,19 +128,18 @@ func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlug |
| 133 | 133 |
} |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 |
- // Lookup using legacy model. |
|
| 137 |
- if allowV1PluginsFallback {
|
|
| 138 |
- p, err := plugins.Get(name, capability) |
|
| 139 |
- if err != nil {
|
|
| 140 |
- if errors.Cause(err) == plugins.ErrNotFound {
|
|
| 141 |
- return nil, errNotFound(name) |
|
| 142 |
- } |
|
| 143 |
- return nil, errors.Wrap(systemError{err}, "legacy plugin")
|
|
| 144 |
- } |
|
| 145 |
- return p, nil |
|
| 136 |
+ if !allowV1PluginsFallback {
|
|
| 137 |
+ return nil, errNotFound(name) |
|
| 146 | 138 |
} |
| 147 | 139 |
|
| 148 |
- return nil, err |
|
| 140 |
+ p, err := plugins.Get(name, capability) |
|
| 141 |
+ if err == nil {
|
|
| 142 |
+ return p, nil |
|
| 143 |
+ } |
|
| 144 |
+ if errors.Cause(err) == plugins.ErrNotFound {
|
|
| 145 |
+ return nil, errNotFound(name) |
|
| 146 |
+ } |
|
| 147 |
+ return nil, errors.Wrap(systemError{err}, "legacy plugin")
|
|
| 149 | 148 |
} |
| 150 | 149 |
|
| 151 | 150 |
// GetAllManagedPluginsByCap returns a list of managed plugins matching the given capability. |