You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://twil.io/learn-open-source)
5
+
3
6
## Documentation
4
7
5
8
The documentation for the Twilio API can be found [here][apidocs].
We suggest storing your credentials as environment variables and then use it in your code. Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public.
44
+
45
+
```go
46
+
import (
47
+
"github.com/twilio/twilio-go/twilio"
48
+
"os"
49
+
)
50
+
51
+
accountSid:= os.Getenv("TWILIO_ACCOUNT_SID")
52
+
authToken:= os.Getenv("TWILIO_AUTH_TOKEN")
53
+
client:= twilio.NewClient(accountSid, authToken)
37
54
```
38
55
39
56
### Buy a phone number
@@ -42,19 +59,28 @@ client := twilio.NewClient(s, a)
In general each service's client is implemented in a namesake file (e.g. [Chat Service](https://www.twilio.com/docs/chat/rest/service-resource) is in **chat_service.go**)
189
-
Large services are split between files and will share the same prefix (e.g. **taskrouter_activity.go** and **taskrouter_taskqueue.go**).
190
-
Files for testing are appended with `_test` (e.g. **sync_service_test.go**).
191
-
**twilio.go** ties the library together by defining the `Twilio` struct and the `Client` constructor `NewClient`.
192
-
The `Client` structure promotes memory reuse between service clients, and provides the `baseURL` to service clients to allow redirecting requests to non-production domains.
193
-
194
-
Under the hood the Twilio Client relies on the private functionality within **internal/twilio.go**.
195
-
The main functionality is captured by `SendRequest` and `doWithErr`.
196
-
`SendRequest` and `doWithErr` facilitate network requests and allow the library to provide an `http.Response` and `error` object.
197
-
`SendRequest` performs the required encoding and request configuration to comply with Twilio's HTTP standards.
198
-
Go's built in struct marshalling is not compatible with Twilio's requirements for form encoding so encoding is performed by the `form` package forked from https://github.com/ajg/form.
199
-
`doWithErr` executes the request from `SendRequest`, parses the error (if any), and returns the result.
200
-
The `error` returned by `doWithErr` may be the `TwilioRestError` object, which is meant to parse Twilio-specific error messages from the body of responses to failed requests.
201
-
202
-
### Creating and Updating Resources ###
203
-
204
-
All structs for Twilio resources use pointer values for all non-repeated fields.
205
-
Pointer values allow users to distinguish between unset fields (`null`) and those set to a zero-value.
206
-
`twilio-go` provides helper functions that easily create these pointers for string,
Users who have worked with protocol buffers should find this pattern familiar.
217
-
218
-
### Inspirations and References ###
219
-
While the overall code structure and client interface is modeled after existing Twilio SDKs, we found additional inspiration in some of the following Go SDKs:
These existing SDKs influenced things like our module pattern (using one module instead of breaking everything into separate resource modules) and unit testing strategy.
225
-
226
-
### Behavioral Notes and Future Improvements
227
-
Things that we wanted to address had we been given more time:
228
-
-[ ]**Parameter Validation** - *twilio-go* provides no built-in parameter validation.
229
-
-[ ]**Enums**- Properties that are of an enumberable type are defaulted to a string
230
-
-[ ]**Retry functionality** - There is a 10 second timeout for requests with no retry functionality.
231
-
232
-
### Code Style
233
-
The code is styled with `go fmt` and adheres to [Go's Style Guide](https://github.com/golang/go/wiki/CodeReviewComments) wherever possible.
234
-
We use `golangci-lint` for linting locally and as part of the PR process (this will catch most violations of the above guidelines).
207
+
If you need help installing or using the library, please check the [Twilio Support Help Center](https://support.twilio.com) first, and [file a support ticket](https://twilio.com/help/contact) if you don't find an answer to your question.
235
208
209
+
All the code [here](twilio/rest) was generated by [twilio-oai-generator](https://github.com/twilio/twilio-oai-generator) by leveraging [openapi-generator](https://github.com/OpenAPITools/openapi-generator) and [twilio-oai](https://github.com/twilio/twilio-oai). If you find an issue with the generation or the openapi specs, please go ahead and open an issue or a PR against the relevant repositories.
0 commit comments