Documentation ¶
Overview ¶
IDL files describe models and web services in a format usable by the Babel tools. The idl package defines types for the parse tree - the representation of parsed IDL.
For more information, see the README.md file.
Index ¶
- Variables
- type Attribute
- type Const
- type Enum
- type Error
- type Field
- type Idl
- func (idl *Idl) AddConst(name string) (*Const, error)
- func (idl *Idl) AddDefaultNamespace(domain, ns string) error
- func (idl *Idl) AddEnum(name string) (*Enum, error)
- func (idl *Idl) AddImport(fpath string) (*Idl, error)
- func (idl *Idl) AddNamespace(language, ns string) error
- func (idl *Idl) AddService(name string) (*Service, error)
- func (idl *Idl) AddStruct(name string) (*Struct, error)
- func (idl *Idl) FindConst(name string) *Const
- func (idl *Idl) FindEnum(name string) *Enum
- func (idl *Idl) FindService(name string) *Service
- func (idl *Idl) FindStruct(name string) *Struct
- func (idl *Idl) Init()
- func (idl *Idl) NamespaceOf(name, lang string) string
- func (idl *Idl) UniqueImports() []*Idl
- func (idl *Idl) UniqueNamespaces(lang string) []string
- func (idl *Idl) UniqueTypes() ([]string, []string)
- func (idl *Idl) Validate(lang string) error
- type Method
- type Pair
- type Service
- type Struct
- type Type
- func (t *Type) Check(idl *Idl) error
- func (t *Type) IsAbstract(idl *Idl) bool
- func (t *Type) IsBinary() bool
- func (t *Type) IsBool() bool
- func (t *Type) IsByte() bool
- func (t *Type) IsChar() bool
- func (t *Type) IsCollection() bool
- func (t *Type) IsDatetime() bool
- func (t *Type) IsDecimal() bool
- func (t *Type) IsEnum(idl *Idl) bool
- func (t *Type) IsFloat() bool
- func (t *Type) IsInt() bool
- func (t *Type) IsList() bool
- func (t *Type) IsMap() bool
- func (t *Type) IsPrimitive() bool
- func (t *Type) IsString() bool
- func (t *Type) IsStruct(idl *Idl) bool
- func (t *Type) IsUserDefined() bool
- func (t *Type) IsVoid() bool
- func (t *Type) String() string
- func (t *Type) TagName() string
Constants ¶
This section is empty.
Variables ¶
var ( IdlTypes = []string{ "bool", "byte", "int8", "int16", "int32", "int64", "float32", "float64", "string", "datetime", "decimal", "char", "binary", } IdlContainers = []string{ "list", "map", } )
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
Attribute defines extra metadata for definition following it. Attributes are written similar to C# attributes but have meaning specific to the output code generator. Attributes have a name and a collection of name/value pairs representing the Attirbute's parameters.
type Const ¶
Const is a collection of constant value defintions. A Const block has a name and optional documentation comments.
type Enum ¶
Enum defines a group of enumerated values. An Enum block has a name and optional documentation comments.
type Error ¶
type Error struct { Source string // source of the error - program name, file name, etc. Defaults to "babel" Line int // Line number in the file (optional) Column int // Column number within the line (optional) Category string // Additional cateogrization "Commmand line", "Parsing", etc. (optional) IsWarning bool // True if the message is a warning message Code int // Specific error number Message error // Text of the error message or another error }
Error defines fields that will be logged in a uniform format for build tools to process Source (Line, Column): Category (error|warning) Code: Message
type Field ¶
type Field struct { Comments []string Attributes []*Attribute Type *Type Name string Initializer *Pair }
Field defines a structure field, which has optional docmumentation comments, optional attributes, a type, and a name.
func (*Field) CheckInitializer ¶
CheckInitializer verifies that the initalizer is appropriate for the type
func (*Field) IsCollection ¶
IsCollection returns true if the type of the field is a list or map.
func (*Field) Optional ¶
optional determines whether the field is not required to have a vakue assigned.
func (*Field) Required ¶
Required determines whether the field is required to have a value assigned.
func (*Field) SetInitializer ¶
SetInitializer assigns the given initial value and type, returning an error if it isn't compatible with the type of the field.
type Idl ¶
type Idl struct { Comments []string Filename string Imports []*Idl Namespaces map[string]string Consts []*Const Enums []*Enum Structs []*Struct Services []*Service }
Idl represents the parse tree of an IDL document.
func (*Idl) AddDefaultNamespace ¶
AddDefaultNamespace appends a namespace for all languages, customized for each.
func (*Idl) AddImport ¶
AddImport appends an imported IDL file to this Idl object. Imports could be repeated down the subtrees.
func (*Idl) AddNamespace ¶
AddNamespace appends a namespace for the given language.
func (*Idl) AddService ¶
AddService appends a Service definition.
func (*Idl) FindConst ¶
FindConst searches this Idl and imported Idls for the named Const definition.
func (*Idl) FindService ¶
FindService searches this Idl and imported Idls for the named Service definition.
func (*Idl) FindStruct ¶
FindStruct searches this Idl and imported Idls for the named Struct definition.
func (*Idl) NamespaceOf ¶
NamespaceOf finds the named object and returns the namespace from the Idl that the object is defined in. Objects may be Structs, Enums, Consts, or Services.
func (*Idl) UniqueImports ¶
UniqueImports returns the unique list of all imports referenced by this Idl.
func (*Idl) UniqueNamespaces ¶
UniqueNamespaces returns a list of all the namespaces used in this Idl and all imports for the given language.
func (*Idl) UniqueTypes ¶
UniqueTypes returns a list of all the types in this Idl, first used in structs, second used in services
type Method ¶
type Method struct { Comments []string Attributes []*Attribute Returns *Type Name string Parameters []*Field }
Method defines a service method that can be called to communicate with a service. Methods have parameters and optional documentation comments and attributes.
func (*Method) AddParameter ¶
AddParameter adds a parameter with the given data type and name to the Method.
func (*Method) HasParameters ¶
HasParameters returns true if there are parameters for this method.
type Pair ¶
Pair is a name/value pair that includes an optional format string for Sprintf. Pairs are used to represent constants and other values in the IDL.
type Service ¶
Service defines a web service interface. Services have optional documentation comments and attributes, as well as a collection of Methods.
type Struct ¶
type Struct struct { Comments []string Attributes []*Attribute Name string Extends string Fields []*Field Abstract bool }
Struct defines a collection of fields transmitted as part of a service call. Structs have optional documenation comments and attributes. They may also extend other Structs.
func (*Struct) BaseClasses ¶
BaseClasses returns the base classes of the named class ordered from top to bottom.
func (*Struct) HasRequiredFields ¶
HasRequiredFields return true if the struct has 1 or more fields that are considered required.
func (*Struct) RequiredFields ¶
RequiredFields gets all required fields for this struct
func (*Struct) SubClasses ¶
SubClasses returns a list of structs that extend this one, in no paticular order. BUG WARNING: This can't look down into IDL files that are not currently loaded. It can only see subclasses in the current context.
type Type ¶
type Type struct { Name string // map, list, or type name KeyType *Type // for maps - this will only ever be a basic primitive type ValueType *Type // for maps and lists Rename string // used to rename this type for some serializers }
Type defines an IDL type with a name. Types can be primitive types like strings or ints, but can also be Structs or a collection like maps and lists.
Name KeyType ValueType Description ----------- ----------- ----------- ---------------------------------- (primitive) (empty) (empty) Primitive type (user) (empty) (empty) User defined (Struct, Enum) list (empty) Type List of Type map (primitive) Type Map of (primitive) to Type void (empty) (empty) No return type (only for methods)
Note that types can nest.
func (*Type) IsAbstract ¶
IsAbstract checks if any of the struct members are abstract.
func (*Type) IsCollection ¶
IsCollection returns true if the Type is a list or map
func (*Type) IsDatetime ¶
IsDatetime checks if the Type is a datetime.
func (*Type) IsPrimitive ¶
IsPrimitive checks if the Type is one of the primitive types.
func (*Type) IsUserDefined ¶
IsUserDefined checks if the Type is a user-defined type.