github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/actor/v3action/application.go (about) 1 package v3action 2 3 import ( 4 "fmt" 5 "net/url" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 8 ) 9 10 // Application represents a V3 actor application. 11 type Application ccv3.Application 12 13 // ApplicationNotFoundError represents the error that occurs when the 14 // application is not found. 15 type ApplicationNotFoundError struct { 16 Name string 17 } 18 19 func (e ApplicationNotFoundError) Error() string { 20 return fmt.Sprintf("Application '%s' not found.", e.Name) 21 } 22 23 // GetApplicationByNameAndSpace returns the application with the given 24 // name in the given space. 25 func (actor Actor) GetApplicationByNameAndSpace(appName string, spaceGUID string) (Application, Warnings, error) { 26 apps, warnings, err := actor.CloudControllerClient.GetApplications(url.Values{ 27 "space_guids": []string{spaceGUID}, 28 "names": []string{appName}, 29 }) 30 if err != nil { 31 return Application{}, Warnings(warnings), err 32 } 33 34 if len(apps) == 0 { 35 return Application{}, Warnings(warnings), ApplicationNotFoundError{Name: appName} 36 } 37 38 return Application(apps[0]), Warnings(warnings), nil 39 }