Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc_source/common-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ are set). For more information, see :doc:`setting-up` and :doc:`configuring-sdk`
:local:
:depth: 1

.. _examples-requests:

|SDK Requests|
==============

Using context.Context with SDK Requests
---------------------------------------

With Go 1.7 the ``context.Context`` type was added to ``http.Request``. This type provides a easy way to implement deadlines, and cancelations on requests.

To use this pattern with the SDK all you need to do is call the ``WithContext`` on the ``HTTPRequest`` field of the SDK's ``request.Request`` type, providing your Context value. The following example highlights this process with a timeout on a SQS ReceiveMessage API call.

.. literalinclude:: example_code/extending_sdk/request_context.go
:dedent: 4
:lines: 15-

.. _examples-ec2:

|EC2|
Expand Down