Skip to content

Commit b269b5e

Browse files
doc(deis): Add godocs for the deis package (#21)
1 parent 525b9e4 commit b269b5e

3 files changed

Lines changed: 71 additions & 7 deletions

File tree

deis.go

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
// Package deis offers a SDK for interacting with the Deis controller API.
2+
//
3+
// This package works by creating a client, which contains session information,
4+
// such as the controller url and user token. The client is then passed to api methods,
5+
// which use it to make requests.
6+
//
7+
// Basic Example
8+
//
9+
// This example creates a client and then lists the apps that the user has access to:
10+
//
11+
// import (
12+
// deis "github.com/deis/controller-sdk-go"
13+
// "github.com/deis/controller-sdk-go/apps"
14+
// )
15+
//
16+
// // Verify SSL, Controller URL, API Token
17+
// client, err := deis.New(true, "deis.test.io", "abc123")
18+
// if err != nil {
19+
// log.Fatal(err)
20+
// }
21+
// apps, _, err := apps.List(client, 100)
22+
// if err != nil {
23+
// log.Fatal(err)
24+
// }
25+
//
26+
// Authentication
27+
//
28+
// If you don't already have a token for a user, you can retrieve one with a
29+
// username and password.
30+
//
31+
// import (
32+
// deis "github.com/deis/controller-sdk-go"
33+
// "github.com/deis/controller-sdk-go/apps"
34+
// )
35+
//
36+
// // Create a client with a blank token to pass to login.
37+
// client, err := deis.New(true, "deis.test.io", "")
38+
// if err != nil {
39+
// log.Fatal(err)
40+
// }
41+
// token, err := auth.Login(client, "user", "password")
42+
// if err != nil {
43+
// log.Fatal(err)
44+
// }
45+
// // Set the client to use the retrieved token
46+
// client.Token = token
47+
//
48+
// Learning More
49+
//
50+
// See the godoc for the SDK's subpackages to learn more about specific SDK actions.
151
package deis
252

353
import (
@@ -11,26 +61,34 @@ import (
1161

1262
// Client oversees the interaction between the deis and controller
1363
type Client struct {
14-
// HTTP deis used to communicate with the API.
64+
// HTTPClient is the transport that is used to communicate with the API.
1565
HTTPClient *http.Client
1666

1767
// VerifySSL determines whether or not to verify SSL connections.
68+
// This should be true unless you know the controller is using untrusted SSL keys.
1869
VerifySSL bool
1970

20-
// URL used to communicate with the controller.
71+
// ControllerURL is the URL used to communicate with the controller.
2172
ControllerURL *url.URL
2273

23-
//UserAgent is the user agent used when making requests
74+
// UserAgent is the user agent used when making requests.
2475
UserAgent string
2576

26-
//API Version used by the controller, set after a http request.
77+
// API Version used by the controller, set after a http request.
2778
ControllerAPIVersion string
2879

2980
// Token is used to authenticate the request against the API.
3081
Token string
3182
}
3283

33-
// APIVersion is the api version the sdk is compatible with.
84+
// APIVersion is the api version compatible with the SDK.
85+
//
86+
// In general, using an SDK that is a minor version out of date with the target controller
87+
// is probably safe, as the deis controller api follows semantic versioning and is backward
88+
// compatible. However, using a SDK that is newer or a major version different than the
89+
// controller is unsafe.
90+
//
91+
// If the SDK detects an API version mismatch, it will return ErrAPIMismatch.
3492
const APIVersion = "2.1"
3593

3694
var (
@@ -41,7 +99,10 @@ var (
4199
DefaultUserAgent = fmt.Sprintf("Deis Go SDK V%s", APIVersion)
42100
)
43101

44-
// New creates a new deis to communicate with the api.
102+
// New creates a new client to communicate with the api.
103+
// The controllerURL is the url of the controller component, by default deis.<cluster url>.com
104+
// verifySSL determines whether or not to verify SSL connections.
105+
// This should be true unless you know the controller is using untrusted SSL keys.
45106
func New(verifySSL bool, controllerURL string, token string) (*Client, error) {
46107
// urlx, unlike the native url library, uses sane defaults when URL parsing,
47108
// preventing issues like missing schemes.

errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080
ErrUnprocessable = errors.New("Unable to process your request.")
8181
)
8282

83+
// checkForErrors tries to match up an API error with an predefined error in the SDK.
8384
func checkForErrors(res *http.Response) error {
8485
if res.StatusCode >= 200 && res.StatusCode < 400 {
8586
return nil

http.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func createHTTPClient(sslVerify bool) *http.Client {
2121
return &http.Client{Transport: tr}
2222
}
2323

24-
// Request makes a HTTP request on the controller.
24+
// Request makes a HTTP request with the given method, relative URL, and body on the controller.
25+
// It also sets the Authorization and Content-Type headers to properly authenticate and communicate
26+
// API. This is primarily intended to use be used by the SDK itself, but could potentially be used elsewhere.
2527
func (c *Client) Request(method string, path string, body []byte) (*http.Response, error) {
2628
url := *c.ControllerURL
2729

0 commit comments

Comments
 (0)