github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv3/client.go (about)

     1  // Package ccv3 represents a Cloud Controller V3 client.
     2  //
     3  // These sets of packages are still under development/pre-pre-pre...alpha. Use
     4  // at your own risk! Functionality and design may change without warning.
     5  //
     6  // It is currently designed to support Cloud Controller API 3.0.0. However, it
     7  // may include features and endpoints of later API versions.
     8  //
     9  // For more information on the Cloud Controller API see
    10  // https://apidocs.cloudfoundry.org/
    11  //
    12  // Method Naming Conventions
    13  //
    14  // The client takes a '<Action Name><Top Level Endpoint><Return Value>'
    15  // approach to method names.  If the <Top Level Endpoint> and <Return Value>
    16  // are similar, they do not need to be repeated. If a GUID is required for the
    17  // <Top Level Endpoint>, the pluralization is removed from said endpoint in the
    18  // method name.
    19  //
    20  // For Example:
    21  //   Method Name: GetApplication
    22  //   Endpoint: /v3/applications/:guid
    23  //   Action Name: Get
    24  //   Top Level Endpoint: applications
    25  //   Return Value: Application
    26  //
    27  //   Method Name: GetServiceInstances
    28  //   Endpoint: /v3/service_instances
    29  //   Action Name: Get
    30  //   Top Level Endpoint: service_instances
    31  //   Return Value: []ServiceInstance
    32  //
    33  //   Method Name: GetSpaceServiceInstances
    34  //   Endpoint: /v3/spaces/:guid/service_instances
    35  //   Action Name: Get
    36  //   Top Level Endpoint: spaces
    37  //   Return Value: []ServiceInstance
    38  //
    39  // Use the following table to determine which HTTP Command equates to which
    40  // Action Name:
    41  //   HTTP Command -> Action Name
    42  //   POST -> New
    43  //   GET -> Get
    44  //   PUT -> Update
    45  //   DELETE -> Delete
    46  //
    47  // Method Locations
    48  //
    49  // Methods exist in the same file as their return type, regardless of which
    50  // endpoint they use.
    51  //
    52  // Error Handling
    53  //
    54  // All error handling that requires parsing the error_code/code returned back
    55  // from the Cloud Controller should be placed in the errorWrapper. Everything
    56  // else can be handled in the individual operations. All parsed cloud
    57  // controller errors should exist in errors.go, all generic HTTP errors should
    58  // exist in the cloudcontroller's errors.go. Errors related to the individaul
    59  // operation should exist at the top of that operation's file.
    60  package ccv3
    61  
    62  import (
    63  	"fmt"
    64  	"runtime"
    65  
    66  	"code.cloudfoundry.org/cli/api/cloudcontroller"
    67  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
    68  )
    69  
    70  // Warnings are a collection of warnings that the Cloud Controller can return
    71  // back from an API request.
    72  type Warnings []string
    73  
    74  // Client can be used to talk to a Cloud Controller's V3 Endpoints.
    75  type Client struct {
    76  	APIInfo
    77  	cloudControllerURL string
    78  
    79  	connection cloudcontroller.Connection
    80  	router     *internal.Router
    81  	userAgent  string
    82  }
    83  
    84  // NewClient returns a new Client.
    85  func NewClient(appName string, appVersion string) *Client {
    86  	userAgent := fmt.Sprintf("%s/%s (%s; %s %s)", appName, appVersion, runtime.Version(), runtime.GOARCH, runtime.GOOS)
    87  	return &Client{
    88  		userAgent: userAgent,
    89  	}
    90  }