Documentation ¶
Index ¶
- Variables
- func Generate(seeds ...*Seed) error
- func RelationshipName(name string) (string, error)
- type Definer
- type Option
- func WithData(data interface{}) Option
- func WithDefinition(definer Definer) Option
- func WithDistinctData(distinctData map[string]interface{}) Option
- func WithDistinctSubpackages(distinctSubpackages []string) Option
- func WithFormatting(opts *imports.Options) Option
- func WithFuncMap(funcMap template.FuncMap) Option
- func WithOutputDirectory(outputDirectory string) Option
- func WithPackageImports(packageImports []string) Option
- func WithPackageName(packageName string) Option
- func WithTemplateMap(templateMap map[string]*template.Template) Option
- type Properties
- type Property
- func MergeOverrideNulls(old, new Property) Property
- func MergeProperty(old, new Property) Property
- func MergePropertyDocumentation(old, new Property) Property
- func NewChildProperty(parentName string, relationshipName string) (Property, error)
- func NewParentProperty(parentName string, relationshipName string) Property
- func NewProperty(parent string, name string, dataType string, documentation string, ...) (Property, error)
- type Seed
- type Source
- type Struct
- type Structs
- func (s Structs) ConvertNillable() Structs
- func (s Structs) Dedupe(overrideNulls bool) (results Structs)
- func (s Structs) DocSize() int
- func (s Structs) Merge(s2 Structs, fn func(old, new Struct) Struct, includeDistinct bool) Structs
- func (s Structs) RemoveRelations() Structs
- func (s Structs) Sort() Structs
- func (s Structs) Valid() bool
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ( // ErrObjectDocumentationNotFound ... ErrObjectDocumentationNotFound = errors.New("documentation not found") // ErrEmptyDocumentation ... ErrEmptyDocumentation = errors.New("empty documentation table: likely a chromium rendering issue") // ErrInternalProperty ... ErrInternalProperty = errors.New("internal salesforce property do not use") // ErrPossiblyNotEnabled ... ErrPossiblyNotEnabled = errors.New("property is disabled by default") // ErrPropertyNameNotFound ... ErrPropertyNameNotFound = errors.New("property name not found") // ErrTableStructureUnknown ... ErrTableStructureUnknown = errors.New("property row table structure unknown") // ErrEmptyRow ... ErrEmptyRow = errors.New("property row is empty") )
var ( // ErrInvalidPropertyName ... ErrInvalidPropertyName = errors.New("property name contains invalid characters") // ErrPropertyKeyBlank ... ErrPropertyKeyBlank = errors.New("property name must not be empty string") )
var DefaultFuncMap = template.FuncMap{ "ToLower": strings.ToLower, "ToPlural": pluralizer.Plural, "ToCamelCase": toCamelCase, "ToLowerCamelCase": toLowerCamelCase, "ToFieldName": toFieldName, "Type": convertType, "Nullable": isNillable, }
DefaultFuncMap ...
Functions ¶
Types ¶
type Definer ¶
Definer defines options for a seed, for example to query additional data from a rest API before rendering a seed.
type Option ¶
type Option func(*Seed)
Option is a functional option used for dynamically configuring an instance of Seed
func WithDistinctData ¶
WithDistinctData ...
func WithDistinctSubpackages ¶
WithDistinctSubpackages ...
func WithOutputDirectory ¶
WithOutputDirectory ...
func WithPackageImports ¶
WithPackageImports ...
type Properties ¶
type Properties []*Property
Properties ...
func (Properties) ConvertNillable ¶
func (props Properties) ConvertNillable() (results Properties)
ConvertNillable ...
func (Properties) Merge ¶
func (props Properties) Merge(p2 Properties, fn func(old, new Property) Property, includeDistinct bool) (final Properties)
Merge ...
type Property ¶
type Property struct { // ParentName is a salesforce specific annotation used to indicate // the parent SObject in a parent:child relationship ParentName string // Name ... Name string // Documentation ... Documentation string // Type ... Type string // Tag ... Tag Tag // IsEmbedded indicated an embedded property such as // // type Foo struct { // Bar // } // // This is used to provide response types for polymorphic foreign keys IsEmbedded bool // IsNillable ... IsNillable bool }
Property represents a Field of a struct
func MergeOverrideNulls ¶
MergeOverrideNulls ...
func MergeProperty ¶
MergeProperty returns a new Property which overrides fields of oldProperty if conditions are met:
- newProperty.{{Field}} is not a zero value
- newProperty.{{Field}} != oldProperty.{{Field}}
- the case of merging a property.Tag is harder as a user may pass in a variety of values with an unknown intent for how they should be merged, for example a k,v of "": []string{} or a Tag{}. In these cases we will not override existing values with a zero value "" or []string{}
- the documentation property is concatenated if the old.Documentation != ""
func MergePropertyDocumentation ¶
MergePropertyDocumentation merges only the Documentation field of two Propeprty objects returning the remaining properties of the initial Property argument unchanged
func NewChildProperty ¶
NewChildProperty ...
func NewParentProperty ¶
NewParentProperty ...
func NewProperty ¶
func NewProperty(parent string, name string, dataType string, documentation string, tagName string, tagValues ...string) (Property, error)
NewProperty ...
func (*Property) IsRelation ¶
IsRelation returns true if this property represents a parent or child relationship
type Seed ¶
type Seed struct { // OutputDirectory ... OutputDirectory string // PackageName ... PackageName string // SubPackageName string SubPackageName string // PackageImports ... PackageImports []string // Definition ... Definition Definer // DistinctSubpackages indicates each Objects should produce // a subpackage in a directory that matches the pluralized lowercase // name of the distinct package DistinctSubpackages []string // Options ... Options []Option // Templates is map linking the absolute file path of a go template with an output filename // for its generated result // k:outputFileName: template TemplateMap map[string]*template.Template // Data is the data passed to a go template, configured via options Data interface{} // Distinct data is data but for DistinctSubpackages DistinctData map[string]interface{} // FormattingOptions *imports.Options // FuncMap template.FuncMap }
Seed contains the structures needed to generate go source code
type Source ¶
Source is the output of a generated Seed k:absoluteFilePath v:fileContents
func Render ¶
Render executes all templates in seed.TemplateMap.
If DistinctObjects is not nil or empty then each template will be executed for each distinctObject and use DistinctData[distinctObject] for the template execution instead of seed.Data. This allows us to generate subpackages for each distinct object.
type Struct ¶
type Struct struct { // DocumentationURL ... DocumentationURL string // ParentName ... ParentName string // Name ... Name string // Documentation ... Documentation string // Properties respresent a struct field Properties Properties // Dependencies are salesforce objects required by child or parent relationships of this struct Dependencies []string // IsPlolymorphicModel represents a model with two or more embeded structs representing a polymorphic relationship IsPolymorphicModel bool }
Struct contains the components to generate a golang struct definition
func FromHTML ¶
FromHTML converts the an HTML table representing a Salesforce Object to a codegen.Struct
func MergeDocumentation ¶
MergeDocumentation merges only the .Documentation property of two structs
func (*Struct) RemoveRelations ¶
RemoveRelations returns a new copy of Struct with properties representing parent or child relations removed
type Structs ¶
type Structs []*Struct
Structs allows us to define utility methods on a group of Struct objects
func FromDescribe ¶
FromDescribe converts the result of a /sobjects/{objectName}/describe request to a list of objects representing golang struct types annotated with their parent and child dependencies
func FromJSON ¶
func FromJSON(structName string, structDocumentation string, JSON []byte) (results Structs, err error)
FromJSON converts a JSON payload to its requisite Struct components. Nested objects will be separated into discrete Struct objects rather then nesting them like Matt Holt's JSON2go website. StructDocumentation refers to Struct.Documentation and will append comments above the Struct.
func (Structs) Merge ¶
Merge merges two []*Struct objects via the function fn.
This allows for merge behavior to change based on the source of the given []*Struct.
For example code derived from the reference documentation may only wish to contribute its struct.Documentation property where as code derived from the tooling/query api should contriubte its struct.Type .
func (Structs) RemoveRelations ¶
RemoveRelations returns a new set of structs with all polymorphic structs and all properties representing relationships removed