Documentation
¶
Index ¶
Constants ¶
const ( PathParam = 0 QueryParam = 1 PayloadParam = 2 )
Possible param locations
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action struct { Name string // Action name, e.g. "create", "multi_terminate" MethodName string // Go method name, e.g. "Create", "MultiTerminate" Description string // Action description ResourceName string // Name of resource that contains this action PathPatterns []*PathPattern // Action path patterns Payload DataType // Payload type if any Params []*ActionParam // Action method parameters LeafParams []*ActionParam // Action parameter leaves (for command line) Return string // Type of method results, e.g. "*ServerArray" ReturnLocation bool // Whether API returns a location header PathParamNames []string // Name of path parameters if any (e.g. :id in /clouds/:id) QueryParamNames []string // Name of query string parameters if any PayloadParamNames []string // Name of payload parameter names if any (payload top level keys) }
Resource actions
func (*Action) HasOptionalParams ¶
Whether action takes optional parameters
func (*Action) MandatoryParams ¶
func (a *Action) MandatoryParams() []*ActionParam
MandatoryParams returns the list of all action mandatory parameters
type ActionParam ¶
type ActionParam struct { Name string // Name of parameter QueryName string // Query string style parameter name Description string // Description of parameter VarName string // go variable name Location int // 0 for path param, 1 for query param, 2 for payload param Type DataType // Type of parameter Mandatory bool // Whether parameter is mandatory NonBlank bool // Whether parameter must not be blank if provided (string or array) Regexp string // Regular expression string parameter must match ValidValues []interface{} // Allowed values (if not empty) Min int // Minimum value (int) Max int // Maximum value (int) }
Data structure used to render method params
func (*ActionParam) IsEquivalent ¶
func (p *ActionParam) IsEquivalent(other *ActionParam) bool
true if action params have the same name and type
func (*ActionParam) Signature ¶
func (p *ActionParam) Signature() (sig string)
Generate signature used e.g. when specifying param in function signatures
type ApiDescriptor ¶
type ApiDescriptor struct { Version string // API Version Resources map[string]*Resource // Resources indexed by name Types map[string]*ObjectDataType // Types used by resource actions indexed by name ResourceNames []string // Resource names ordered alphabetically TypeNames []string // Type names ordered alphabetically NeedTime bool // Whether generated code uses the time.Time package NeedJson bool // Whether generated code uses encoding/json package }
The api descriptor struct contains the results of the analyzer Analyze() method. This includes all the API resources, actions and types.
func (*ApiDescriptor) FinalizeTypeNames ¶
func (d *ApiDescriptor) FinalizeTypeNames(rawTypes map[string][]*ObjectDataType)
Go through all the types generated by the analyzer and generate unique names
func (*ApiDescriptor) Merge ¶
func (d *ApiDescriptor) Merge(other *ApiDescriptor) error
Merge two descriptors together, make sure there are no duplicate resource names and that common types are compatible.
type ArrayDataType ¶
type ArrayDataType struct {
ElemType *ActionParam
}
An array data type defines the type of its elements
func (*ArrayDataType) IsEquivalent ¶
func (a *ArrayDataType) IsEquivalent(other DataType) bool
true if other is also a array data type and element types of both arrays are equivalent
func (*ArrayDataType) Name ¶
func (a *ArrayDataType) Name() string
Name is name of element appended with "[]"
type Attribute ¶
type Attribute struct { Name string // Attribute name, e.g. "elasticity_params" FieldName string // Corresponding go struct field name, e.g. "ElasticityParams" FieldType string // Corresponding go struct type, e.g. "*ElasticityParams" }
Resource attributes used to generate resource type definition. There may also be a ObjectDataType describing the resource media type for example to use as action parameter. The below is solely to generate the go struct corresponding to the resource.
type BasicDataType ¶
type BasicDataType string
A basic data type only has a name, i.e. "int" or "string"
func (*BasicDataType) IsEquivalent ¶
func (b *BasicDataType) IsEquivalent(other DataType) bool
true if both b and other represent the same type
type DataType ¶
type DataType interface { IsEquivalent(other DataType) bool // true if datatype and other represent the same data structure Name() string // Type name }
Data type interface
type EnumerableDataType ¶
type EnumerableDataType int
An enumerable is just a map
func (*EnumerableDataType) IsEquivalent ¶
func (e *EnumerableDataType) IsEquivalent(other DataType) bool
true if other is also an enumerable data type
type ObjectDataType ¶
type ObjectDataType struct { TypeName string Fields []*ActionParam }
An object data type has a name and fields
func (*ObjectDataType) IsEquivalent ¶
func (o *ObjectDataType) IsEquivalent(other DataType) bool
true if other is a object data type and each field is equivalent recursively
type PathPattern ¶
type PathPattern struct { HttpMethod string // Action HTTP method, e.g. "GET", "POST" Path string // Path as it appears in metadata Pattern string // Actual pattern, e.g. "/clouds/%s/instances/%s" Variables []string // Pattern variable names in order of appearance in pattern, e.g. "cloud_id", "id" Regexp string // Regular expression used to match href }
A path pattern represents a possible path for a given action.
type Resource ¶
type Resource struct { Name string // Resource name, e.g. "ServerArray" ClientName string // Name of go client struct, e.g. "Api" Description string // Resource description Attributes []*Attribute // Resource attributes Actions []*Action // Resource actions, e.g. "index", "show", "update" ... }
Data structure used to describe API resources.