Slack SCIM API client for Golang
MIT License
Slack SCIM API client for Golang
client := scim.NewClient("Slack API Token")
Note that returned *http.Response.Body is closed.
ctx := context.Background()
users, resp, err := client.GetUsers(ctx, nil, "")
users, resp, err := client.GetUsers(ctx, &scim.Pagination{
Count: 5000,
StartInex: 1,
}, "")
users, resp, err := client.GetUsers(ctx, nil, `email eq "[email protected]"`)
You can customize client's behavior with methods Client.WithXXX
and Client.SetXXX
.
Client.SetXXX
changes the receiver itself.
On the other hand, Client.WithXXX
changes a shallow copy of client and returns it.
Client.WithXXX
is useful for the method chain.
client.SetParseResp(func(resp *http.Response, output interface{}) error {
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
fmt.Println(string(b))
return json.Unmarshal(b, output)
})
users, resp, err := client.WithParseErrorResp(func(resp *http.Response) error {
fmt.Println("customize")
return ParseErrorRespDefault(resp)
}).GetUsers(ctx, nil, "")
Client.GetUsers
parses response body and returns users.
On the other hand, Client.GetUsersResp
doesn't parse response body.
Returned response body is open.
resp, err := client.GetUsersResp(ctx, nil, "")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
resp, err := client.CreateUser(ctx, &scim.User{
UserName: "foo",
Emails: []scim.Email{
Value: "[email protected]",
},
})