Get some values only with slice variables

hi i’m new user of go.
I’ve succeded to use this library : GitHub - Nerzal/gocloak: golang keycloak client
to connect to keycloak , i need to list usernames only
for now, i can only have all attributes …

There is a param struct ;

type GetUsersParams struct {
    BriefRepresentation *bool   `json:"briefRepresentation,string,omitempty"`
    Email               *string `json:"email,omitempty"`
    EmailVerified       *bool   `json:"emailVerified,string,omitempty"`
    Enabled             *bool   `json:"enabled,string,omitempty"`
    Exact               *bool   `json:"exact,string,omitempty"`
    First               *int    `json:"first,string,omitempty"`
    FirstName           *string `json:"firstName,omitempty"`
    IDPAlias            *string `json:"idpAlias,omitempty"`
    IDPUserID           *string `json:"idpUserId,omitempty"`
    LastName            *string `json:"lastName,omitempty"`
    Max                 *int    `json:"max,string,omitempty"`
    Q                   *string `json:"q,omitempty"`
    Search              *string `json:"search,omitempty"`
    Username            *string `json:"username,omitempty"`
}

there is this function :

func (client *gocloak) GetUsers(ctx context.Context, token, realm string, params GetUsersParams) ([]*User, error) {
    const errMessage = "could not get users"

    var result []*User
    queryParams, err := GetQueryParams(params)
    if err != nil {
        return nil, errors.Wrap(err, errMessage)
    }

    resp, err := client.getRequestWithBearerAuth(ctx, token).
        SetResult(&result).
        SetQueryParams(queryParams).
        Get(client.getAdminRealmURL(realm, "users"))

    if err := checkForError(resp, err, errMessage); err != nil {
        return nil, err
    }

    return result, nil
}

When calling this function like this, it works
userlist, err := client.GetUsers(ctx, token.AccessToken, "testrealm", gocloak.GetUsersParams{})
i’d like only get the Username by passing value in GetUsersParams, i tried but i cannot find, can someone help me?

hi
i’ve found, they are pointer so i have to bypass like that
for _, toto := range totos {
fmt.Printf(“%+v\n”, *(toto.Username))
//fmt.Printf(“%+v”, *(toto.Email))
//fmt.Printf(“%+v”, *(toto.FirstName))

}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.