AWS SDK for Go
Developer Guide

Listing User Docs

The following example lists the documents for the user whose name is specified on the command line. Choose Copy to save the code locally, or see the link to the complete example at the end of this topic.

Import the following Go packages.

import ( "flag" "fmt" "" "" )
  • flag is for getting user input, in this case the name of the user

  • fmt is for formatting output

  • session is for creating a session

  • workdocs is for using the WorkDocs APIs

Create a session and Amazon WorkDocs client.

sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, ) // Create a Workdocs service client. svc := workdocs.New(sess)

Check that we have a user name, and get the root folder for that user.

user_ptr := flag.String("u", "", "User for whom info is retrieved") flag.Parse() // Show all users if we don't get a user name if *user_ptr == "" { fmt.Println("You must supply a user name") return } // Replace with your organization ID org_id := "d-123456789c" input := new(workdocs.DescribeUsersInput) input.OrganizationId = &org_id input.Query = user_ptr result, err := svc.DescribeUsers(input) if err != nil { fmt.Println("Error getting user info", err) return } var folder_id = "" if *result.TotalNumberOfUsers == 1 { for _, user := range result.Users { folder_id = *user.RootFolderId }

Run the DescribeFolderContents method and display the name, size, and last modified information for each document.

result, err := svc.DescribeFolderContents(&workdocs.DescribeFolderContentsInput{FolderId: &folder_id}) if err != nil { fmt.Println("Error getting docs for user", err) return } fmt.Println(*user_ptr + " docs:") fmt.Println("") for _, doc := range result.Documents { fmt.Println(*doc.LatestVersionMetadata.Name) fmt.Println(" Size: ", *doc.LatestVersionMetadata.Size, "(bytes)") fmt.Println(" Last modified:", *doc.LatestVersionMetadata.ModifiedTimestamp) fmt.Println("") }

See the complete example on GitHub.