forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListProjects.go
57 lines (49 loc) · 1.79 KB
/
ListProjects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[codebuild.go.list_projects]
package main
// snippet-start:[codebuild.go.list_projects.imports]
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codebuild"
)
// snippet-end:[codebuild.go.list_projects.imports]
// GetProjects retrieves a list of your AWS CodeBuild projects
// Inputs:
// sess is the current session, which provides configuration for the SDK's service clients
// Output:
// If success, the list of the projects and nil
// Otherwise, nil and an error from the call to ListProjects
func GetProjects(sess *session.Session) (*codebuild.ListProjectsOutput, error) {
// snippet-start:[codebuild.go.list_projects.call]
svc := codebuild.New(sess)
// Get the list of projects
result, err := svc.ListProjects(
&codebuild.ListProjectsInput{
SortBy: aws.String("NAME"),
SortOrder: aws.String("ASCENDING"),
})
// snippet-end:[codebuild.go.list_projects.call]
return result, err
}
func main() {
// snippet-start:[codebuild.go.list_projects.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
// snippet-end:[codebuild.go.list_projects.session]
result, err := GetProjects(sess)
if err != nil {
fmt.Println("Got an error listing projects:")
fmt.Println(err)
return
}
// snippet-start:[codebuild.go.list_projects.display]
for _, p := range result.Projects {
fmt.Println(*p)
}
// snippet-end:[codebuild.go.list_projects.display]
}
// snippet-end:[codebuild.go.list_projects]