Debian Codegraph @

internal/website/content/concepts/as.md

raw
1 ---
2 title: Using provider-specific APIs
3 date: 2019-05-10T11:17:09-07:00
4 weight: 3
5 ---
6
7 It is not feasible or desirable for APIs like `blob.Bucket` to encompass the
8 full functionality of every provider. Rather, we intend to provide a subset
9 of the most commonly used functionality. There will be cases where a
10 developer wants to access provider-specific functionality, such as unexposed
11 APIs or data fields, errors, or options. This can be accomplished using `As`
12 functions.
13
14 <!--more-->
15
16 ## `As` {#as}
17
18 `As` functions in the APIs provide the user a way to escape the Go CDK
19 abstraction to access provider-specific types. They might be used as an
20 interim solution until a feature request to the Go CDK is implemented. Or,
21 the Go CDK may choose not to support specific features, and the use of `As`
22 will be permanent.
23
24 Using `As` implies that the resulting code is no longer portable; the
25 provider-specific code will need to be ported in order to switch providers.
26 Therefore, it should be avoided if possible.
27
28 Each API includes examples demonstrating how to use its various `As`
29 functions, and each provider implementation documents what types it supports
30 for each.
31
32 Usage:
33
34 1. Declare a variable of the provider-specific type you want to access.
35 2. Pass a pointer to it to `As`.
36 3. If the type is supported, `As` will return `true` and copy the
37 provider-specific type into your variable. Otherwise, it will return `false`.
38
39 Provider-specific types that are intended to be mutable will be exposed
40 as a pointer to the underlying type.