Documentation ¶
Overview ¶
Package gomsgraph is the Microsoft Graph API client for Go.
Index ¶
- func AddOptions(urlBase string, opts interface{}) (string, error)
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func GetOAuth2Client(ctx context.Context, tenantID string, clientID string, clientSecret string) *http.Client
- func Int(v int) *int
- func Int64(v int64) *int64
- func NewOAuth2ClientFromEnvsOrFail(ctx context.Context) *http.Client
- func String(v string) *string
- func URL(resourceName UrlPart, resourceID ...string) *urlStrBuilder
- type BaseClient
- type ErrorResponse
- type Response
- type UrlPart
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddOptions ¶
AddOptions adds the parameters in opts as URL query parameters to urlBase. opts must be a struct whose fields may contain "url" tags.
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func CheckResponse ¶
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.
The error type will be *RateLimitError for rate limit exceeded errors, *AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.
func GetOAuth2Client ¶
func Int ¶
Int is a helper routine that allocates a new int value to store v and returns a pointer to it.
func Int64 ¶
Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.
func NewOAuth2ClientFromEnvsOrFail ¶
NewOAuth2ClientFromEnvsOrFail create oauth2 client from environment variables. Fails if envs are not provided.
Types ¶
type BaseClient ¶
type BaseClient struct { // HTTP client used to communicate with the API. Client *http.Client // Base URL for API requests with a trailing slash. BaseURL *url.URL // User agent used when communicating with the MS Graph API. UserAgent string }
A BaseClient manages communication with the MS Graph API.
func (*BaseClient) BareDo ¶
BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body. If rate limit is exceeded and reset time is in the future, BareDo returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
func (*BaseClient) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error happens, the response is returned as is. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
func (*BaseClient) NewRequest ¶
func (c *BaseClient) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)
NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response // HTTP response that caused this error Err *struct { Message string `json:"message"` // error message Code string `json:"code"` // error code InnerError *struct { Date string `json:"date,omitempty"` RequestID string `json:"request-id,omitempty"` ClientRequestID string `json:"client-request-id,omitempty"` } `json:"innerError,omitempty"` } `json:"error"` }
An ErrorResponse reports one or more errors caused by an API request.
Example:
{ "error": { "code": "BadRequest", "message": "Invalid version.", "innerError": { "date": "2021-04-02T10:39:31", "request-id": "d856e698-27f5-4242-9529-555bff83ca4e", "client-request-id": "d856e698-27f5-4242-9529-555bff83ca4e" } } }
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string