github.com/drone/runner-go@v1.12.0/manifest/lookup.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package manifest
     6  
     7  import "errors"
     8  
     9  // Lookup returns the named resource from the Manifest.
    10  func Lookup(name string, manifest *Manifest) (Resource, error) {
    11  	for _, resource := range manifest.Resources {
    12  		if isNameMatch(resource.GetName(), name) {
    13  			return resource, nil
    14  		}
    15  	}
    16  	return nil, errors.New("resource not found")
    17  }
    18  
    19  // helper function returns true if the name matches.
    20  func isNameMatch(a, b string) bool {
    21  	return a == b ||
    22  		(a == "" && b == "default") ||
    23  		(b == "" && a == "default")
    24  }