You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
660 B
Go
25 lines
660 B
Go
5 years ago
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||
|
// Use of this source code is governed by the Polyform License
|
||
|
// that can be found in the LICENSE file.
|
||
|
|
||
|
package manifest
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
// Lookup returns the named resource from the Manifest.
|
||
|
func Lookup(name string, manifest *Manifest) (Resource, error) {
|
||
|
for _, resource := range manifest.Resources {
|
||
|
if isNameMatch(resource.GetName(), name) {
|
||
|
return resource, nil
|
||
|
}
|
||
|
}
|
||
|
return nil, errors.New("resource not found")
|
||
|
}
|
||
|
|
||
|
// helper function returns true if the name matches.
|
||
|
func isNameMatch(a, b string) bool {
|
||
|
return a == b ||
|
||
|
(a == "" && b == "default") ||
|
||
|
(b == "" && a == "default")
|
||
|
}
|