MCPcopy Index your code
hub / github.com/coder/coder / Groups

Method Groups

codersdk/groups.go:88–119  ·  view source on GitHub ↗
(ctx context.Context, args GroupArguments)

Source from the content-addressed store, hash-verified

86}
87
88func (c *Client) Groups(ctx context.Context, args GroupArguments) ([]Group, error) {
89 qp := url.Values{}
90 if args.Organization != "" {
91 qp.Set("organization", args.Organization)
92 }
93 if args.HasMember != "" {
94 qp.Set("has_member", args.HasMember)
95 }
96 if len(args.GroupIDs) > 0 {
97 idStrs := make([]string, 0, len(args.GroupIDs))
98 for _, id := range args.GroupIDs {
99 idStrs = append(idStrs, id.String())
100 }
101 qp.Set("group_ids", strings.Join(idStrs, ","))
102 }
103
104 res, err := c.Request(ctx, http.MethodGet,
105 fmt.Sprintf("/api/v2/groups?%s", qp.Encode()),
106 nil,
107 )
108 if err != nil {
109 return nil, xerrors.Errorf("make request: %w", err)
110 }
111 defer res.Body.Close()
112
113 if res.StatusCode != http.StatusOK {
114 return nil, ReadBodyAsError(res)
115 }
116
117 var groups []Group
118 return groups, json.NewDecoder(res.Body).Decode(&groups)
119}
120
121func (c *Client) GroupByOrgAndName(ctx context.Context, orgID uuid.UUID, name string) (Group, error) {
122 res, err := c.Request(ctx, http.MethodGet,

Callers 1

GroupsByOrganizationMethod · 0.95

Calls 7

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
EncodeMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected