mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-08-06 22:13:02 +02:00
feat(context): Add support for context package
This commit is contained in:
23
role.go
23
role.go
@ -1,6 +1,7 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -35,12 +36,12 @@ type ActorUser struct {
|
||||
AccountID string `json:"accountId" structs:"accountId"`
|
||||
}
|
||||
|
||||
// GetList returns a list of all available project roles
|
||||
// GetListWithContext returns a list of all available project roles
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-get
|
||||
func (s *RoleService) GetList() (*[]Role, *Response, error) {
|
||||
func (s *RoleService) GetListWithContext(ctx context.Context) (*[]Role, *Response, error) {
|
||||
apiEndpoint := "rest/api/3/role"
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -53,12 +54,17 @@ func (s *RoleService) GetList() (*[]Role, *Response, error) {
|
||||
return roles, resp, err
|
||||
}
|
||||
|
||||
// Get retreives a single Role from Jira
|
||||
// GetList wraps GetListWithContext using the background context.
|
||||
func (s *RoleService) GetList() (*[]Role, *Response, error) {
|
||||
return s.GetListWithContext(context.Background())
|
||||
}
|
||||
|
||||
// GetWithContext retreives a single Role from Jira
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-id-get
|
||||
func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
|
||||
func (s *RoleService) GetWithContext(ctx context.Context, roleID int) (*Role, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/3/role/%d", roleID)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -74,3 +80,8 @@ func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
|
||||
|
||||
return role, resp, err
|
||||
}
|
||||
|
||||
// Get wraps GetWithContext using the background context.
|
||||
func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
|
||||
return s.GetWithContext(context.Background(), roleID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user