Skip to content

Development Patterns

G. Hussain Chinoy edited this page Jan 28, 2018 · 5 revisions

Some notes on evolving development patterns

Separation of command from implementation of command

  • the cmd package contains all the commands - these should just be CLI interface behavior (although there are still some that have CLI and implementation mixed in)
  • the ce-go/ce package/library has all the implementations of calling CE Platform APIs as well as helper functions (including output helper functions)

Creating a method to call a Platform API

To make a call to a CE Platform API from a command, this is the method signature to use:

// Get element instances
bodybytes, statuscode, curlcmd, err := ce.GetElementInstances(profilemap["base"], profilemap["auth"], args[0])

The Platform API implementation (in ce-go/ce repo) takes in information to create an HTTP call - the base URL + the Authorization Header, and any args necessary.

It returns the undecoded bytes of the HTTP call, the status code, the string that is the curl command, and any errors.

The cmd (in this repository) will do the unmarshaling of the raw bytes, using the status code to determine whether to show an error or continue output processing.

Implementing a new CE API

Implementing the API should be done in the ce-go/ce repo. Please also add a _test.go file or a test method to the existing file. Once implemented and committed, then the API method can be used within this repo.

To use the API in this cli repo, update the dependencies via dep to keep the external dependencies in sync: dep ensure -update

Changelog

Use dep-style changelog as an example for adding to changelog, i.e. refer to issue or pr and categorize addition as a New Feature, Bug Fix, or Improvement

Clone this wiki locally