-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Description
I propose to add a GetAs
method that wraps Client.Get
but adds the json.Unmarshal
step. That method will be convenient for users as well as allow to simplify the internal implementation of all the API wrappers.
Here is the full implementation (that I will submit as PR if this is accepted):
func (z *Client) GetAs(ctx context.Context, target any) error {
b, err := z.Get(ctx, "/users/me.json")
if err != nil {
return err
}
return json.Unmarshal(b, target)
}
Here is a usage example:
func GetMe(ctx context.Context, client *zendesk.Client) (*zendesk.User, error) {
var body struct {
User *zendesk.User `json:"user"`
}
err := client.GetAs(ctx, "/users/me.json", &body)
if err != nil {
return nil, err
}
return body.User, nil
}
Metadata
Metadata
Assignees
Labels
No labels