Documentation ¶
Index ¶
- Constants
- func ContextInterface(pkg Package) *codegen.Interface
- func GenRootPackageComment(pkgName string) string
- func GenerateConstants(types []*TypeGenerator, props []*PropertyGenerator) (c []jen.Code)
- func PrivateFlatPackageComment(pkgName, vocabName string) string
- func PrivateIndividualPropertyPackageComment(pkgName, propertyName string) string
- func PrivateIndividualTypePackageComment(pkgName, typeName string) string
- func TypeInterface(pkg Package) *codegen.Interface
- func VocabPackageComment(pkgName, vocabName string) string
- type FunctionalPropertyGenerator
- type Identifier
- type Kind
- type ManagerGenerator
- type NonFunctionalPropertyGenerator
- type Package
- type PackageGenerator
- func (t *PackageGenerator) InitDefinitions(pkg Package, tgs []*TypeGenerator, pgs []*PropertyGenerator) (globalManager *jen.Statement, init *codegen.Function)
- func (t *PackageGenerator) PrivateDefinitions(tgs []*TypeGenerator, pgs []*PropertyGenerator) ([]*jen.Statement, []*codegen.Interface, []*codegen.Function)
- func (t *PackageGenerator) PublicDefinitions(tgs []*TypeGenerator) *codegen.Interface
- func (t *PackageGenerator) RootDefinitions(vocabName string, tgs []*TypeGenerator, pgs []*PropertyGenerator) (typeCtors, propCtors, ext, disj, extBy, isA []*codegen.Function)
- type PackageManager
- type Property
- type PropertyGenerator
- func (p *PropertyGenerator) Comments() string
- func (p *PropertyGenerator) ConstructorFn() *codegen.Function
- func (p *PropertyGenerator) DeserializeFnName() string
- func (p *PropertyGenerator) GetKinds() []Kind
- func (p *PropertyGenerator) GetPrivatePackage() Package
- func (p *PropertyGenerator) GetPublicPackage() Package
- func (p *PropertyGenerator) HasNaturalLanguageMap() bool
- func (p *PropertyGenerator) InterfaceName() string
- func (p *PropertyGenerator) PropertyName() string
- func (p *PropertyGenerator) SetKindFns(docName, idName, vocab string, qualKind *jen.Statement, deser *codegen.Method) error
- func (p *PropertyGenerator) StructName() string
- func (p *PropertyGenerator) VocabName() string
- type PropertyPackageGenerator
- type ResolverGenerator
- type TypeGenerator
- func (t *TypeGenerator) AddPropertyGenerator(property Property) error
- func (t *TypeGenerator) AddRangeProperty(property Property)
- func (t *TypeGenerator) Comments() string
- func (t *TypeGenerator) Definition() *codegen.Struct
- func (t *TypeGenerator) Disjoint() []*TypeGenerator
- func (t *TypeGenerator) ExtendedBy() []*TypeGenerator
- func (t *TypeGenerator) Extends() []*TypeGenerator
- func (t *TypeGenerator) InterfaceDefinition(pkg Package) *codegen.Interface
- func (t *TypeGenerator) InterfaceName() string
- func (t *TypeGenerator) PrivatePackage() Package
- func (t *TypeGenerator) Properties() map[string]Property
- func (t *TypeGenerator) PublicPackage() Package
- func (t *TypeGenerator) StructName() string
- func (t *TypeGenerator) TypeName() string
- func (t *TypeGenerator) VocabName() string
- func (t *TypeGenerator) WithoutProperties() map[string]Property
- type TypePackageGenerator
Constants ¶
const ( JSONLDVocabName = "JSONLD" JSONLDIdName = "id" JSONLDTypeName = "type" )
Variables ¶
This section is empty.
Functions ¶
func ContextInterface ¶
ContextInterface returns a jsonldContexter interface that is needed for ActivityStream types to recursively determine what context strings need to exist in a JSON-LD @context value for linked-data peers to parse.
It is a private interface to make the implementation easier, not needed by anything outside the package this implementation is in.
func GenRootPackageComment ¶
func GenerateConstants ¶
func GenerateConstants(types []*TypeGenerator, props []*PropertyGenerator) (c []jen.Code)
GenerateConstants generates string constants for the type and property names. Note that the properties that could be maps have an additional constant generatred.
func TypeInterface ¶
TypeInterface returns the Type Interface that is needed for ActivityStream types to compile for methods dealing with extending, in the inheritance sense.
func VocabPackageComment ¶
Types ¶
type FunctionalPropertyGenerator ¶
type FunctionalPropertyGenerator struct { PropertyGenerator // contains filtered or unexported fields }
FunctionalPropertyGenerator produces Go code for properties that can have only one value. The resulting property is a struct type that can have one value that could be from multiple Kinds of values. If there is only one allowed Kind, then a smaller API is generated as a special case.
func NewFunctionalPropertyGenerator ¶
func NewFunctionalPropertyGenerator(vocabName string, vocabURI *url.URL, vocabAlias string, pm *PackageManager, name Identifier, comment string, kinds []Kind, hasNaturalLanguageMap bool) (*FunctionalPropertyGenerator, error)
NewFunctionalPropertyGenerator is a convenience constructor to create FunctionalPropertyGenerators.
PropertyGenerators shoulf be in the first pass to construct, before types and other generators are constructed.
func NewIdProperty ¶
func NewIdProperty(pm *PackageManager, xsdAnyUri Kind) (*FunctionalPropertyGenerator, error)
NewIdPropety returns the functional property for the JSON-LD "@id" property.
func (*FunctionalPropertyGenerator) Definition ¶
func (p *FunctionalPropertyGenerator) Definition() *codegen.Struct
Definition produces the Go Struct code definition, which can generate its Go implementations.
The TypeGenerator apply must be called for all types before Definition is called.
func (*FunctionalPropertyGenerator) InterfaceDefinition ¶
func (p *FunctionalPropertyGenerator) InterfaceDefinition(pkg Package) *codegen.Interface
InterfaceDefinition creates an interface definition in the provided package.
type Identifier ¶
type Identifier struct { // LowerName is the typical name used in documentation. LowerName string // CamelName is the typical name used in identifiers in code. CamelName string }
Identifier determines how a name will appear in documentation and Go code.
type Kind ¶
type Kind struct { Name Identifier Vocab string // ConcreteKind is expected to be properly qualified. ConcreteKind *jen.Statement Nilable bool IsURI bool // These <FuncName>Fn types are for qualified names of the functions. // Expected to always be non-nil: a function is needed to deserialize. DeserializeFn *jen.Statement // If any of these are nil at generation time, assume to call the method // on the object directly (instead of a qualified function). SerializeFn *jen.Statement LessFn *jen.Statement // The following are only used for values, not types, as actual implementations SerializeDef *codegen.Function DeserializeDef *codegen.Function LessDef *codegen.Function }
Kind is data that describes a concrete Go type, how to serialize and deserialize such types, compare the types, and other meta-information to use during Go code generation.
Only represents values and other types.
func NewKindForType ¶
NewKindForType creates a Kind for an ActivitySteams type.
type ManagerGenerator ¶
type ManagerGenerator struct {
// contains filtered or unexported fields
}
Generates the ActivityStreamManager that handles the creation of ActivityStream Core, Extended, and any extension types.
This is implicitly used by Application code, but Application code usually won't need to manually use this Manager.
This also provides interfaces to break the recursive/cyclic dependencies between properties and types. The previous version of this tool did not attempt to solve this problem, and instead just created one big and bloated library in order to avoid having to break the dependence. This version of the tool instead will generate interfaces for all of the required types.
This means that developers will only ever need to interact with these interfaces, and could switch out using this implementation for another one of their own choosing.
Also note that the manager links against all the implementations to generate a comprehensive registry. So while individual properties and types are able to be compiled separately, this generated output will link against all of these libraries.
TODO: Improve the code generation to examine specific Golang code to determine which types to actually generate, and prune the unneeded types. This would cut down on the bloat on a per-program basis.
func NewManagerGenerator ¶
func NewManagerGenerator(pkg Package, tg []*TypeGenerator, fp []*FunctionalPropertyGenerator, nfp []*NonFunctionalPropertyGenerator) (*ManagerGenerator, error)
NewManagerGenerator creates a new manager system.
This generator should be constructed in the third pass, after types and property generators are all constructed.
func (*ManagerGenerator) Definition ¶
func (m *ManagerGenerator) Definition() *codegen.Struct
Definition creates a manager implementation that works with the interface types required by the other PropertyGenerators and TypeGenerators for serializing and deserializing.
Applications will implicitly use this manager and be isolated from the underlying specific go-fed implementation. If another alternative to go-fed were to be created, it could target those interfaces and be a drop-in replacement for an application.
It is necessary to have this to acheive isolation without cyclic dependencies: types and properties can each belong in their own package (if desired) to minimize binary bloat.
type NonFunctionalPropertyGenerator ¶
type NonFunctionalPropertyGenerator struct { PropertyGenerator // contains filtered or unexported fields }
NonFunctionalPropertyGenerator produces Go code for properties that can have more than one value. The resulting property is a type that is a list of iterators; each iterator is a concrete struct type. The property can be sorted and iterated over so individual elements can be inspected.
func NewNonFunctionalPropertyGenerator ¶
func NewNonFunctionalPropertyGenerator(vocabName string, vocabURI *url.URL, vocabAlias string, pm *PackageManager, name Identifier, comment string, kinds []Kind, hasNaturalLanguageMap bool) (*NonFunctionalPropertyGenerator, error)
NewNonFunctionalPropertyGenerator is a convenience constructor to create NonFunctionalPropertyGenerators.
PropertyGenerators shoulf be in the first pass to construct, before types and other generators are constructed.
func NewTypeProperty ¶
func NewTypeProperty(pm *PackageManager, xsdAnyUri, xsdString Kind) (*NonFunctionalPropertyGenerator, error)
NewTypeProperty returns the non-functional property for the JSON-LD "@type" property.
func (*NonFunctionalPropertyGenerator) Definitions ¶
func (p *NonFunctionalPropertyGenerator) Definitions() (*codegen.Struct, *codegen.Struct)
Definitions produces the Go code definitions, which can generate their Go implementations. The struct is the iterator for various values of the property, which is defined by the type definition.
The TypeGenerator apply must be called for all types before Definition is called.
func (*NonFunctionalPropertyGenerator) InterfaceDefinitions ¶
func (p *NonFunctionalPropertyGenerator) InterfaceDefinitions(pkg Package) []*codegen.Interface
InterfaceDefinitions creates interface definitions in the provided package.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a Golang package.
func (Package) IsPublic ¶
IsPublic returns whether this package is intended to house public files for application developer use.
func (Package) Parent ¶
func (p Package) Parent() *PackageManager
Parent returns the PackageManager managing this Package.
type PackageGenerator ¶
type PackageGenerator struct {
// contains filtered or unexported fields
}
PackageGenerator maanges generating one-time files needed for both type and property implementations.
func NewPackageGenerator ¶
func NewPackageGenerator(typeVocabName string, m *ManagerGenerator, typeProperty *NonFunctionalPropertyGenerator) *PackageGenerator
NewPackageGenerator creates a new PackageGenerator.
func (*PackageGenerator) InitDefinitions ¶
func (t *PackageGenerator) InitDefinitions(pkg Package, tgs []*TypeGenerator, pgs []*PropertyGenerator) (globalManager *jen.Statement, init *codegen.Function)
InitDefinitions returns the root init function needed to inject proper global package-private variables needed at runtime. This is the dependency injection into the implementation.
func (*PackageGenerator) PrivateDefinitions ¶
func (t *PackageGenerator) PrivateDefinitions(tgs []*TypeGenerator, pgs []*PropertyGenerator) ([]*jen.Statement, []*codegen.Interface, []*codegen.Function)
PrivateDefinitions creates the private code generated definitions needed once per package.
Precondition: The passed-in generators are the complete set of type generators within a package. One of tgs or pgs has at least one value.
func (*PackageGenerator) PublicDefinitions ¶
func (t *PackageGenerator) PublicDefinitions(tgs []*TypeGenerator) *codegen.Interface
PublicDefinitions creates the public-facing code generated definitions needed once per package.
Precondition: The passed-in generators are the complete set of type generators within a package.
func (*PackageGenerator) RootDefinitions ¶
func (t *PackageGenerator) RootDefinitions(vocabName string, tgs []*TypeGenerator, pgs []*PropertyGenerator) (typeCtors, propCtors, ext, disj, extBy, isA []*codegen.Function)
RootDefinitions creates functions needed at the root level of the package declarations.
type PackageManager ¶
type PackageManager struct {
// contains filtered or unexported fields
}
PackageManager manages the path and names of a package consisting of a public and a private portion.
func NewPackageManager ¶
func NewPackageManager(prefix, root string) *PackageManager
NewPackageManager creates a package manager whose private implementation is in an "impl" subdirectory.
func (*PackageManager) PrivatePackage ¶
func (p *PackageManager) PrivatePackage() Package
PrivatePackage returns the private package.
func (*PackageManager) PublicPackage ¶
func (p *PackageManager) PublicPackage() Package
PublicPackage returns the public package.
func (*PackageManager) Sub ¶
func (p *PackageManager) Sub(name string) *PackageManager
Sub creates a PackageManager clone that manages a subdirectory.
func (*PackageManager) SubPrivate ¶
func (p *PackageManager) SubPrivate(name string) *PackageManager
SubPrivate creates a PackageManager clone where the private package is one subdirectory further.
func (*PackageManager) SubPublic ¶
func (p *PackageManager) SubPublic(name string) *PackageManager
SubPublic creates a PackageManager clone where the public package is one subdirectory further.
type Property ¶
type Property interface { VocabName() string GetPublicPackage() Package PropertyName() string StructName() string InterfaceName() string SetKindFns(docName, idName, vocab string, kind *jen.Statement, deser *codegen.Method) error DeserializeFnName() string HasNaturalLanguageMap() bool }
Property represents a property of an ActivityStreams type.
type PropertyGenerator ¶
type PropertyGenerator struct {
// contains filtered or unexported fields
}
PropertyGenerator is a common base struct used in both Functional and NonFunctional ActivityStreams properties. It provides common naming patterns, logic, and common Go code to be generated.
It also properly handles the concept of generating Go code for property iterators, which are needed for NonFunctional properties.
func (*PropertyGenerator) Comments ¶
func (p *PropertyGenerator) Comments() string
Comments returns the comment for this property.
func (*PropertyGenerator) ConstructorFn ¶
func (p *PropertyGenerator) ConstructorFn() *codegen.Function
ConstructorFn creates a constructor function with a default vocabulary alias.
func (*PropertyGenerator) DeserializeFnName ¶
func (p *PropertyGenerator) DeserializeFnName() string
DeserializeFnName returns the identifier of the function that deserializes raw JSON into the generated Go type.
func (*PropertyGenerator) GetKinds ¶
func (p *PropertyGenerator) GetKinds() []Kind
GetKinds gets this property's kinds.
func (*PropertyGenerator) GetPrivatePackage ¶
func (p *PropertyGenerator) GetPrivatePackage() Package
GetPrivatePackage gets this property's private Package.
func (*PropertyGenerator) GetPublicPackage ¶
func (p *PropertyGenerator) GetPublicPackage() Package
GetPublicPackage gets this property's public Package.
func (*PropertyGenerator) HasNaturalLanguageMap ¶
func (p *PropertyGenerator) HasNaturalLanguageMap() bool
HasNaturalLanguageMap returns whether this property has a natural language map.
func (*PropertyGenerator) InterfaceName ¶
func (p *PropertyGenerator) InterfaceName() string
InterfaceName returns the interface name of the property type.
func (*PropertyGenerator) PropertyName ¶
func (p *PropertyGenerator) PropertyName() string
PropertyName returns the name of this property, as defined in specifications. It is not suitable for use in generated code function identifiers.
func (*PropertyGenerator) SetKindFns ¶
func (p *PropertyGenerator) SetKindFns(docName, idName, vocab string, qualKind *jen.Statement, deser *codegen.Method) error
SetKindFns allows TypeGenerators to later notify this Property what functions to use when generating the serialization code.
The name parameter must match the LowerName of an Identifier.
This feels very hacky.
func (*PropertyGenerator) StructName ¶
func (p *PropertyGenerator) StructName() string
StructName returns the name of the type, which may or may not be a struct, to generate.
func (*PropertyGenerator) VocabName ¶
func (p *PropertyGenerator) VocabName() string
VocabName returns this property's vocabulary name.
type PropertyPackageGenerator ¶
type PropertyPackageGenerator struct{}
PropertyPackageGenerator manages generating one-time files needed for properties.
func NewPropertyPackageGenerator ¶
func NewPropertyPackageGenerator() *PropertyPackageGenerator
NewPropertyPackageGenerator creates a new PropertyPackageGenerator.
func (*PropertyPackageGenerator) PrivateDefinitions ¶
func (p *PropertyPackageGenerator) PrivateDefinitions(pgs []*PropertyGenerator) (*jen.Statement, *codegen.Interface, *codegen.Function)
PrivateDefinitions creates the private code generated definitions needed once per package.
Precondition: The passed-in generators are the complete set of type generators within a package. len(pgs) > 0
type ResolverGenerator ¶
type ResolverGenerator struct {
// contains filtered or unexported fields
}
ResolverGenerator generates the code required for the TypeResolver and the PredicateTypeResolver.
func NewResolverGenerator ¶
func NewResolverGenerator( tgs []*TypeGenerator, m *ManagerGenerator, pkg Package) *ResolverGenerator
Creates a new ResolverGenerator for generating all the methods, functions, errors, interface, and struct types needed for them.
Must be constructed after all TypeGenerators.
func (*ResolverGenerator) Definition ¶
func (r *ResolverGenerator) Definition() (jsonRes, typeRes, typePredRes *codegen.Struct, errs []jen.Code, fns []*codegen.Function, iFaces []*codegen.Interface)
Definition returns the TypeResolver and PredicateTypeResolver.
This function signature is pure garbage and yet I keep heaping it on.
type TypeGenerator ¶
type TypeGenerator struct {
// contains filtered or unexported fields
}
TypeGenerator represents an ActivityStream type definition to generate in Go.
func NewTypeGenerator ¶
func NewTypeGenerator(vocabName string, vocabURI *url.URL, vocabAlias string, pm *PackageManager, typeName, comment string, properties, withoutProperties, rangeProperties []Property, extends, disjoint []*TypeGenerator, typeless bool) (*TypeGenerator, error)
NewTypeGenerator creates a new generator for a specific ActivityStreams Core or extension type. It will return an error if there are multiple properties have the same Name.
The TypeGenerator should be in the second pass to construct, relying on the fact that properties have already been constructed.
The extends and disjoint parameters are allowed to be nil. These lists must also have unique (non-duplicated) elements. Note that the disjoint entries will be set up bi-directionally properly; no need to go back to an existing TypeGenerator to set up the link correctly.
The rangeProperties list is allowed to be nil. Any passed in will properly have their SetKindFns bookkeeping done.
All TypeGenerators must be created before the Definition method is called, to ensure that type extension, in the inheritence sense, is properly set up.
A ManagerGenerator must be created with this type before Definition is called, to ensure that the serialization functions are properly set up.
func (*TypeGenerator) AddPropertyGenerator ¶
func (t *TypeGenerator) AddPropertyGenerator(property Property) error
AddPropertyGenerator adds a property generator to this type. It must be called before Definition is called.
func (*TypeGenerator) AddRangeProperty ¶
func (t *TypeGenerator) AddRangeProperty(property Property)
AddRangeProperty adds another property as having this type as a value. Must be called before Definition is called.
func (*TypeGenerator) Comments ¶
func (t *TypeGenerator) Comments() string
Comment returns the comment for this type.
func (*TypeGenerator) Definition ¶
func (t *TypeGenerator) Definition() *codegen.Struct
Definition generates the golang code for this ActivityStreams type.
func (*TypeGenerator) Disjoint ¶
func (t *TypeGenerator) Disjoint() []*TypeGenerator
Disjoint returns the generators of types that this ActivityStreams type is disjoint to.
func (*TypeGenerator) ExtendedBy ¶
func (t *TypeGenerator) ExtendedBy() []*TypeGenerator
ExtendedBy returns the generators of types that extend from this ActivityStreams type.
func (*TypeGenerator) Extends ¶
func (t *TypeGenerator) Extends() []*TypeGenerator
Extends returns the generators of types that this ActivityStreams type extends from.
func (*TypeGenerator) InterfaceDefinition ¶
func (t *TypeGenerator) InterfaceDefinition(pkg Package) *codegen.Interface
InterfaceDefinition creates the interface of this type in the specified package.
Requires ManagerGenerator to have been created.
func (*TypeGenerator) InterfaceName ¶
func (t *TypeGenerator) InterfaceName() string
InterfaceName returns the interface name for this type.
func (*TypeGenerator) PrivatePackage ¶
func (t *TypeGenerator) PrivatePackage() Package
Package gets this TypeGenerator's Private Package.
func (*TypeGenerator) Properties ¶
func (t *TypeGenerator) Properties() map[string]Property
Properties returns the Properties of this type, mapped by their property name.
func (*TypeGenerator) PublicPackage ¶
func (t *TypeGenerator) PublicPackage() Package
Package gets this TypeGenerator's Public Package.
func (*TypeGenerator) StructName ¶
func (t *TypeGenerator) StructName() string
StructName returns the Go name for this type.
func (*TypeGenerator) TypeName ¶
func (t *TypeGenerator) TypeName() string
TypeName returns the ActivityStreams name for this type.
func (*TypeGenerator) VocabName ¶
func (t *TypeGenerator) VocabName() string
VocabName returns this TypeGenerator's vocabulary name.
func (*TypeGenerator) WithoutProperties ¶
func (t *TypeGenerator) WithoutProperties() map[string]Property
WithoutProperties returns the properties that do not apply to this type, mapped by their property name.
type TypePackageGenerator ¶
type TypePackageGenerator struct {
// contains filtered or unexported fields
}
TypePackageGenerator manages generating one-time files needed for types.
func NewTypePackageGenerator ¶
func NewTypePackageGenerator( typeVocabName string, m *ManagerGenerator, typeProperty *NonFunctionalPropertyGenerator) *TypePackageGenerator
NewTypePackageGenerator creates a new TypePackageGenerator.
func (*TypePackageGenerator) PrivateDefinitions ¶
func (t *TypePackageGenerator) PrivateDefinitions(tgs []*TypeGenerator) ([]*jen.Statement, []*codegen.Interface, []*codegen.Function)
PrivateDefinitions creates the private code generated definitions needed once per package.
Precondition: The passed-in generators are the complete set of type generators within a package. len(tgs) > 0
func (*TypePackageGenerator) PublicDefinitions ¶
func (t *TypePackageGenerator) PublicDefinitions(tgs []*TypeGenerator) (typeI *codegen.Interface)
PublicDefinitions creates the public-facing code generated definitions needed once per package.
Precondition: The passed-in generators are the complete set of type generators within a package. Must satisfy: len(tgs) > 0.