idl

package
v1.2.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

type Attribute struct {
	Name       string
	Parameters []*Pair
	Scope      string
}

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

type Const struct {
	Comments []string
	Name     string
	Values   []*Pair
}

Const is a collection of constant value defintions. A Const block has a name and optional documentation comments.

func (*Const) Add

func (c *Const) Add(name string, value interface{}, dataType string) error

Add appends a constant value definition to the Const block.

func (*Const) FindValue

func (c *Const) FindValue(name string) *Pair

FindValue returns the item with the given name.

func (*Const) Init

func (c *Const) Init()

Init initializes the Const for use.

type Enum

type Enum struct {
	Comments []string
	Name     string
	Values   []*Pair
}

Enum defines a group of enumerated values. An Enum block has a name and optional documentation comments.

func (*Enum) Add

func (e *Enum) Add(name string, value int64) error

Add appends an enumeration value to the Enum block.

func (*Enum) FindValue

func (e *Enum) FindValue(name string) *Pair

FindValue returns the item with the given name.

func (*Enum) Init

func (e *Enum) Init()

Init initializes the Enum for use.

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

func (*Error) Error

func (e *Error) Error() string

Implement the error interface

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

func (f *Field) CheckInitializer(idl *Idl) error

CheckInitializer verifies that the initalizer is appropriate for the type

func (*Field) Init

func (f *Field) Init()

Init initializes the Field for use.

func (*Field) IsCollection

func (f *Field) IsCollection() bool

IsCollection returns true if the type of the field is a list or map.

func (*Field) IsList

func (f *Field) IsList() bool

IsList returns true if the type of the field is a list

func (*Field) IsMap

func (f *Field) IsMap() bool

IsMap returns true if the type of the field is a map

func (*Field) Optional

func (f *Field) Optional() bool

optional determines whether the field is not required to have a vakue assigned.

func (*Field) Required

func (f *Field) Required() bool

Required determines whether the field is required to have a value assigned.

func (*Field) SetInitializer

func (f *Field) SetInitializer(i interface{}, t string) error

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) AddConst

func (idl *Idl) AddConst(name string) (*Const, error)

AddConst appends a Const definition.

func (*Idl) AddDefaultNamespace

func (idl *Idl) AddDefaultNamespace(domain, ns string) error

AddDefaultNamespace appends a namespace for all languages, customized for each.

func (*Idl) AddEnum

func (idl *Idl) AddEnum(name string) (*Enum, error)

AddEnum appends an Enum definition.

func (*Idl) AddImport

func (idl *Idl) AddImport(fpath string) (*Idl, error)

AddImport appends an imported IDL file to this Idl object. Imports could be repeated down the subtrees.

func (*Idl) AddNamespace

func (idl *Idl) AddNamespace(language, ns string) error

AddNamespace appends a namespace for the given language.

func (*Idl) AddService

func (idl *Idl) AddService(name string) (*Service, error)

AddService appends a Service definition.

func (*Idl) AddStruct

func (idl *Idl) AddStruct(name string) (*Struct, error)

AddStruct appends a Struct definition.

func (*Idl) FindConst

func (idl *Idl) FindConst(name string) *Const

FindConst searches this Idl and imported Idls for the named Const definition.

func (*Idl) FindEnum

func (idl *Idl) FindEnum(name string) *Enum

FindEnum searches this Idl and imported Idls for the named Enum definition.

func (*Idl) FindService

func (idl *Idl) FindService(name string) *Service

FindService searches this Idl and imported Idls for the named Service definition.

func (*Idl) FindStruct

func (idl *Idl) FindStruct(name string) *Struct

FindStruct searches this Idl and imported Idls for the named Struct definition.

func (*Idl) Init

func (idl *Idl) Init()

Init initializes the Idl for use.

func (*Idl) NamespaceOf

func (idl *Idl) NamespaceOf(name, lang string) string

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

func (idl *Idl) UniqueImports() []*Idl

UniqueImports returns the unique list of all imports referenced by this Idl.

func (*Idl) UniqueNamespaces

func (idl *Idl) UniqueNamespaces(lang string) []string

UniqueNamespaces returns a list of all the namespaces used in this Idl and all imports for the given language.

func (*Idl) UniqueTypes

func (idl *Idl) UniqueTypes() ([]string, []string)

UniqueTypes returns a list of all the types in this Idl, first used in structs, second used in services

func (*Idl) Validate

func (idl *Idl) Validate(lang string) error

Validate tests this Idl for collisions, redefinitions, and other problems.

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

func (m *Method) AddParameter(dataType *Type, name string) (*Field, error)

AddParameter adds a parameter with the given data type and name to the Method.

func (*Method) HasParameters

func (m *Method) HasParameters() bool

HasParameters returns true if there are parameters for this method.

func (*Method) Init

func (m *Method) Init()

Init initializes a Method for use.

type Pair

type Pair struct {
	Name     string
	Value    interface{}
	DataType string
}

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

type Service struct {
	Comments   []string
	Attributes []*Attribute
	Name       string
	Methods    []*Method
}

Service defines a web service interface. Services have optional documentation comments and attributes, as well as a collection of Methods.

func (*Service) AddMethod

func (s *Service) AddMethod(returnType *Type, name string) (*Method, error)

AddMethod appends a method of the given return type and name to the service. A pointer to the new Method is returned.

func (*Service) Init

func (s *Service) Init()

Init initializes the Service for use.

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) AddField

func (s *Struct) AddField(dataType *Type, name string) (*Field, error)

AddField adds a field with the given data type and names to the Struct.

func (*Struct) BaseClasses

func (s *Struct) BaseClasses(idl *Idl) ([]*Struct, error)

BaseClasses returns the base classes of the named class ordered from top to bottom.

func (*Struct) HasRequiredFields

func (s *Struct) HasRequiredFields() bool

HasRequiredFields return true if the struct has 1 or more fields that are considered required.

func (*Struct) Init

func (s *Struct) Init()

Init initializes the Struct for use.

func (*Struct) RequiredFields

func (s *Struct) RequiredFields() []*Field

RequiredFields gets all required fields for this struct

func (*Struct) SubClasses

func (s *Struct) SubClasses(idl *Idl) []*Struct

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) Check

func (t *Type) Check(idl *Idl) error

Check validates that the Type has been defined.

func (*Type) IsAbstract

func (t *Type) IsAbstract(idl *Idl) bool

IsAbstract checks if any of the struct members are abstract.

func (*Type) IsBinary

func (t *Type) IsBinary() bool

IsBinary checks if the Type is a byte array.

func (*Type) IsBool

func (t *Type) IsBool() bool

IsBool checks if the Type is a boolean.

func (*Type) IsByte

func (t *Type) IsByte() bool

IsByte checks if the Type is a byte.

func (*Type) IsChar

func (t *Type) IsChar() bool

IsChar checks if the Type is a character type.

func (*Type) IsCollection

func (t *Type) IsCollection() bool

IsCollection returns true if the Type is a list or map

func (*Type) IsDatetime

func (t *Type) IsDatetime() bool

IsDatetime checks if the Type is a datetime.

func (*Type) IsDecimal

func (t *Type) IsDecimal() bool

IsDecimal checks if the Type is a decimal.

func (*Type) IsEnum

func (t *Type) IsEnum(idl *Idl) bool

IsEnum checks if the Type is an Enum that has been defined.

func (*Type) IsFloat

func (t *Type) IsFloat() bool

IsFloat checks if the Type is a floating-point type.

func (*Type) IsInt

func (t *Type) IsInt() bool

IsInt checks if the Type is an integer type.

func (*Type) IsList

func (t *Type) IsList() bool

IsList checks if the Type is a list.

func (*Type) IsMap

func (t *Type) IsMap() bool

IsMap checks if the Type is a map.

func (*Type) IsPrimitive

func (t *Type) IsPrimitive() bool

IsPrimitive checks if the Type is one of the primitive types.

func (*Type) IsString

func (t *Type) IsString() bool

IsString checks if the Type is a string type.

func (*Type) IsStruct

func (t *Type) IsStruct(idl *Idl) bool

IsStruct checks if the Type is a Struct that has been defined.

func (*Type) IsUserDefined

func (t *Type) IsUserDefined() bool

IsUserDefined checks if the Type is a user-defined type.

func (*Type) IsVoid

func (t *Type) IsVoid() bool

IsVoid checks if the Type is a void (used only for returns from functions).

func (*Type) String

func (t *Type) String() string

String returns the Type as a string in IDL format.

func (*Type) TagName

func (t *Type) TagName() string

TagName returns the name of the type for use in various serializers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL