AWS SDK for Go
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Listing Users

The following example lists the names of all users, or lists additional details about a user if a user 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 ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/workdocs" "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.

// credentials from the shared credentials file ~/.aws/credentials. sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, ) // Create a Workdocs service client.

Create the input arguments for the DescribeUsers method and add your organization ID.

input := new(workdocs.DescribeUsersInput) // Replace with your organization ID org_id := "d-123456789c"

If we have a user name, add that to the input arguments so we only get information about 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("Getting info about all users") } else { fmt.Println("Getting info about user " + *user_ptr) input.Query = user_ptr

Run the DescribeUsers method and display the information for the user or all users.

result, err := svc.DescribeUsers(input) if err != nil { fmt.Println("Error getting user info", err) return } if *user_ptr == "" { fmt.Println("Found", *result.TotalNumberOfUsers, "users") fmt.Println("") } for _, user := range result.Users { fmt.Println("Username: " + *user.Username) if *user_ptr != "" { fmt.Println("Firstname: " + *user.GivenName) fmt.Println("Lastname: " + *user.Surname) fmt.Println("Email: " + *user.EmailAddress) fmt.Println("Root folder " + *user.RootFolderId) } fmt.Println("")

See the complete example on GitHub.