Documentation
¶
Overview ¶
Package compile provides specifications for the types and services defined in a Thrift file.
Files are parsed using the Compile method, which will return a Module that contains the types and services defined in the Thrift file.
Index ¶
- type Annotations
- type ArgsSpec
- type BinarySpec
- type BoolSpec
- type ConstReference
- type Constant
- type ConstantBool
- type ConstantDouble
- type ConstantInt
- type ConstantList
- type ConstantMap
- type ConstantSet
- type ConstantString
- type ConstantStruct
- type ConstantValue
- type ConstantValuePair
- type DoubleSpec
- type EnumItem
- type EnumItemReference
- type EnumSpec
- func (e *EnumSpec) ForEachTypeReference(func(TypeSpec) error) error
- func (e *EnumSpec) Link(scope Scope) (TypeSpec, error)
- func (e *EnumSpec) LookupItem(name string) (*EnumItem, bool)
- func (e *EnumSpec) ThriftAnnotations() Annotations
- func (e *EnumSpec) ThriftFile() string
- func (e *EnumSpec) ThriftName() string
- func (e *EnumSpec) TypeCode() wire.Type
- type FS
- type FieldGroup
- type FieldSpec
- type FunctionSpec
- type I16Spec
- type I32Spec
- type I64Spec
- type I8Spec
- type IncludedModule
- type ListSpec
- type MapSpec
- type Module
- func (m *Module) GetName() string
- func (m *Module) LookupConstant(name string) (*Constant, error)
- func (m *Module) LookupInclude(name string) (Scope, error)
- func (m *Module) LookupService(name string) (*ServiceSpec, error)
- func (m *Module) LookupType(name string) (TypeSpec, error)
- func (m *Module) Walk(f func(*Module) error) error
- type NamedEntity
- type Option
- type ResultSpec
- type Scope
- type ServiceSpec
- type SetSpec
- type StringSpec
- type StructSpec
- func (s *StructSpec) ForEachTypeReference(f func(TypeSpec) error) error
- func (s *StructSpec) IsExceptionType() bool
- func (s *StructSpec) Link(scope Scope) (TypeSpec, error)
- func (s *StructSpec) ThriftAnnotations() Annotations
- func (s *StructSpec) ThriftFile() string
- func (s *StructSpec) ThriftName() string
- func (s *StructSpec) TypeCode() wire.Type
- type TypeSpec
- type TypedefSpec
- func (t *TypedefSpec) ForEachTypeReference(f func(TypeSpec) error) error
- func (t *TypedefSpec) Link(scope Scope) (TypeSpec, error)
- func (t *TypedefSpec) ThriftAnnotations() Annotations
- func (t *TypedefSpec) ThriftFile() string
- func (t *TypedefSpec) ThriftName() string
- func (t *TypedefSpec) TypeCode() wire.Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgsSpec ¶
type ArgsSpec FieldGroup
ArgsSpec contains information about a Function's arguments.
type BinarySpec ¶
type BinarySpec struct { Annotations Annotations // contains filtered or unexported fields }
BinarySpec is the TypeSpec for binary types in a Thrift file.
func (*BinarySpec) ForEachTypeReference ¶ added in v0.4.0
func (*BinarySpec) ForEachTypeReference(func(TypeSpec) error) error
ForEachTypeReference is a no-op for primitives.
func (*BinarySpec) Link ¶ added in v0.4.0
func (t *BinarySpec) Link(Scope) (TypeSpec, error)
Link is a no-op for primitives.
func (*BinarySpec) ThriftAnnotations ¶ added in v0.5.0
func (t *BinarySpec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (BinarySpec) ThriftFile ¶ added in v0.4.0
func (BinarySpec) ThriftFile() string
func (*BinarySpec) ThriftName ¶ added in v0.4.0
func (*BinarySpec) ThriftName() string
ThriftName returns "binary".
func (*BinarySpec) TypeCode ¶ added in v0.4.0
func (*BinarySpec) TypeCode() wire.Type
TypeCode returns TBinary.
type BoolSpec ¶
type BoolSpec struct { Annotations Annotations // contains filtered or unexported fields }
BoolSpec is the TypeSpec for bool types in a Thrift file.
func (*BoolSpec) ForEachTypeReference ¶ added in v0.4.0
ForEachTypeReference is a no-op for primitives.
func (*BoolSpec) ThriftAnnotations ¶ added in v0.5.0
func (t *BoolSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (BoolSpec) ThriftFile ¶ added in v0.4.0
func (BoolSpec) ThriftFile() string
func (*BoolSpec) ThriftName ¶ added in v0.4.0
ThriftName returns "bool".
type ConstReference ¶
type ConstReference struct {
Target *Constant
}
ConstReference represents a reference to a 'const' declared in the Thrift file.
func (ConstReference) Link ¶
func (c ConstReference) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstReference.
type Constant ¶
type Constant struct { Name string File string Doc string Type TypeSpec Value ConstantValue // contains filtered or unexported fields }
Constant represents a single named constant value from the Thrift file.
type ConstantBool ¶
type ConstantBool bool
ConstantBool represents a boolean constant from the Thrift file.
func (ConstantBool) Link ¶
func (c ConstantBool) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantBool
type ConstantDouble ¶
type ConstantDouble float64
ConstantDouble represents a double constant from the Thrift file.
func (ConstantDouble) Link ¶
func (c ConstantDouble) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantDouble.
type ConstantInt ¶
type ConstantInt int64
ConstantInt represents an integer constant from the Thrift file.
func (ConstantInt) Link ¶
func (c ConstantInt) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantInt.
type ConstantList ¶
type ConstantList []ConstantValue
ConstantList represents a list of constant values from the Thrift file.
func (ConstantList) Link ¶
func (c ConstantList) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantList.
type ConstantMap ¶
type ConstantMap []ConstantValuePair
ConstantMap represents a map literal from the Thrift file.
func (ConstantMap) Link ¶
func (c ConstantMap) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantMap.
type ConstantSet ¶
type ConstantSet []ConstantValue
ConstantSet represents a set of constant values from the Thrift file.
func (ConstantSet) Link ¶
func (c ConstantSet) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantSet.
type ConstantString ¶
type ConstantString string
ConstantString represents a string constant from the Thrift file.
func (ConstantString) Link ¶
func (c ConstantString) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantString.
type ConstantStruct ¶
type ConstantStruct struct {
Fields map[string]ConstantValue
}
ConstantStruct represents a struct literal from the Thrift file.
func (*ConstantStruct) Link ¶
func (c *ConstantStruct) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for ConstantStruct
type ConstantValue ¶
type ConstantValue interface { // Link the constant value with the given scope, casting it to the given // type if necessary. Link(scope Scope, t TypeSpec) (ConstantValue, error) }
ConstantValue represents a compiled constant value or a reference to one.
type ConstantValuePair ¶
type ConstantValuePair struct {
Key, Value ConstantValue
}
ConstantValuePair represents a key-value pair of ConstantValues in a constant map.
type DoubleSpec ¶
type DoubleSpec struct { Annotations Annotations // contains filtered or unexported fields }
DoubleSpec is the TypeSpec for double types in a Thrift file.
func (*DoubleSpec) ForEachTypeReference ¶ added in v0.4.0
func (*DoubleSpec) ForEachTypeReference(func(TypeSpec) error) error
ForEachTypeReference is a no-op for primitives.
func (*DoubleSpec) Link ¶ added in v0.4.0
func (t *DoubleSpec) Link(Scope) (TypeSpec, error)
Link is a no-op for primitives.
func (*DoubleSpec) ThriftAnnotations ¶ added in v0.5.0
func (t *DoubleSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (DoubleSpec) ThriftFile ¶ added in v0.4.0
func (DoubleSpec) ThriftFile() string
func (*DoubleSpec) ThriftName ¶ added in v0.4.0
func (*DoubleSpec) ThriftName() string
ThriftName returns "double".
func (*DoubleSpec) TypeCode ¶ added in v0.4.0
func (*DoubleSpec) TypeCode() wire.Type
TypeCode returns TDouble.
type EnumItem ¶
type EnumItem struct { Name string Value int32 Annotations Annotations Doc string }
EnumItem is a single item inside an enum.
func (*EnumItem) ThriftAnnotations ¶ added in v0.5.0
func (e *EnumItem) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (*EnumItem) ThriftName ¶ added in v0.5.0
ThriftName for EnumItem
type EnumItemReference ¶
EnumItemReference represents a reference to an item of an enum defined in the THrift file.
func (EnumItemReference) Link ¶
func (e EnumItemReference) Link(scope Scope, t TypeSpec) (ConstantValue, error)
Link for EnumItemReference.
type EnumSpec ¶
type EnumSpec struct { Name string File string Items []EnumItem Annotations Annotations Doc string }
EnumSpec represents an enum defined in the Thrift file.
func (*EnumSpec) ForEachTypeReference ¶
ForEachTypeReference for EnumSpec
func (*EnumSpec) LookupItem ¶
LookupItem retrieves the item with the given name from the enum.
Returns true or false indicating whether the result is valid or not.
func (*EnumSpec) ThriftAnnotations ¶ added in v0.5.0
func (e *EnumSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
type FS ¶
type FS interface { // Read reads the file named by filename and returns the contents. // See: https://golang.org/pkg/os/#ReadFile Read(filename string) ([]byte, error) // Abs returns an absolute representation of path. // See: https://golang.org/pkg/path/filepath/#Abs Abs(p string) (string, error) }
FS is used by the compiler to interact with the filesystem.
type FieldGroup ¶
type FieldGroup []*FieldSpec
FieldGroup represents a collection of fields for struct-like types.
func (FieldGroup) FindByName ¶
func (fg FieldGroup) FindByName(name string) (*FieldSpec, error)
FindByName retrieves the FieldSpec for the field with the given name.
func (FieldGroup) ForEachTypeReference ¶
func (fg FieldGroup) ForEachTypeReference(f func(TypeSpec) error) error
ForEachTypeReference applies the given function on each TypeSpec in the FieldGroup.
func (FieldGroup) Link ¶
func (fg FieldGroup) Link(scope Scope) error
Link resolves references made by fields inside the FieldGroup.
type FieldSpec ¶
type FieldSpec struct { ID int16 Name string Type TypeSpec Required bool Doc string Default ConstantValue Annotations Annotations }
FieldSpec represents a single field of a struct or parameter list.
func (*FieldSpec) ThriftAnnotations ¶ added in v0.5.0
func (f *FieldSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (*FieldSpec) ThriftName ¶
ThriftName is the name of the FieldSpec as it appears in the Thrift file.
type FunctionSpec ¶
type FunctionSpec struct { Name string ArgsSpec ArgsSpec ResultSpec *ResultSpec // nil if OneWay is true OneWay bool Annotations Annotations // contains filtered or unexported fields }
FunctionSpec is a single function inside a Service.
func (*FunctionSpec) CallType ¶
func (f *FunctionSpec) CallType() wire.EnvelopeType
CallType returns the envelope type that is used when making enveloped requests for this function.
func (*FunctionSpec) Link ¶
func (f *FunctionSpec) Link(scope Scope) error
Link resolves any references made by the given function.
func (*FunctionSpec) MethodName ¶
func (f *FunctionSpec) MethodName() string
MethodName returns the method name for this function.
type I16Spec ¶
type I16Spec struct { Annotations Annotations // contains filtered or unexported fields }
I16Spec is the TypeSpec for i16 types in a Thrift file.
func (*I16Spec) ForEachTypeReference ¶ added in v0.4.0
ForEachTypeReference is a no-op for primitives.
func (*I16Spec) ThriftAnnotations ¶ added in v0.5.0
func (t *I16Spec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (I16Spec) ThriftFile ¶ added in v0.4.0
func (I16Spec) ThriftFile() string
func (*I16Spec) ThriftName ¶ added in v0.4.0
ThriftName returns "i16".
type I32Spec ¶
type I32Spec struct { Annotations Annotations // contains filtered or unexported fields }
I32Spec is the TypeSpec for i32 types in a Thrift file.
func (*I32Spec) ForEachTypeReference ¶ added in v0.4.0
ForEachTypeReference is a no-op for primitives.
func (*I32Spec) ThriftAnnotations ¶ added in v0.5.0
func (t *I32Spec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (I32Spec) ThriftFile ¶ added in v0.4.0
func (I32Spec) ThriftFile() string
func (*I32Spec) ThriftName ¶ added in v0.4.0
ThriftName returns "i32".
type I64Spec ¶
type I64Spec struct { Annotations Annotations // contains filtered or unexported fields }
I64Spec is the TypeSpec for i64 types in a Thrift file.
func (*I64Spec) ForEachTypeReference ¶ added in v0.4.0
ForEachTypeReference is a no-op for primitives.
func (*I64Spec) ThriftAnnotations ¶ added in v0.5.0
func (t *I64Spec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (I64Spec) ThriftFile ¶ added in v0.4.0
func (I64Spec) ThriftFile() string
func (*I64Spec) ThriftName ¶ added in v0.4.0
ThriftName returns "i64".
type I8Spec ¶
type I8Spec struct { Annotations Annotations // contains filtered or unexported fields }
I8Spec is the TypeSpec for i8/byte types in a Thrift file.
func (*I8Spec) ForEachTypeReference ¶ added in v0.4.0
ForEachTypeReference is a no-op for primitives.
func (*I8Spec) ThriftAnnotations ¶ added in v0.5.0
func (t *I8Spec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (I8Spec) ThriftFile ¶ added in v0.4.0
func (I8Spec) ThriftFile() string
func (*I8Spec) ThriftName ¶ added in v0.4.0
ThriftName returns "byte".
type IncludedModule ¶
IncludedModule represents an included module in the Thrift file.
The name of the IncludedModule is the name under which the module is exposed in the Thrift file which included it. This is usually the same as the Module name except when our custom include-as syntax is used.
type ListSpec ¶
type ListSpec struct { ValueSpec TypeSpec Annotations Annotations // contains filtered or unexported fields }
ListSpec represents lists of values of the same type.
func (*ListSpec) ForEachTypeReference ¶
ForEachTypeReference for ListSpec
func (*ListSpec) ThriftAnnotations ¶ added in v0.5.0
func (l *ListSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (ListSpec) ThriftFile ¶
func (ListSpec) ThriftFile() string
type MapSpec ¶
type MapSpec struct {
KeySpec, ValueSpec TypeSpec
Annotations Annotations
// contains filtered or unexported fields
}
MapSpec represents a key-value mapping between two types.
func (*MapSpec) ForEachTypeReference ¶
ForEachTypeReference for MapSpec
func (*MapSpec) ThriftAnnotations ¶ added in v0.5.0
func (m *MapSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (MapSpec) ThriftFile ¶
func (MapSpec) ThriftFile() string
type Module ¶
type Module struct { Name string ThriftPath string Includes map[string]*IncludedModule Constants map[string]*Constant Types map[string]TypeSpec Services map[string]*ServiceSpec Raw []byte // The raw IDL input. }
Module represents a compiled Thrift module. It contains all information about all known types, constants, services, and includes from the Thrift file.
ThriftPath is the absolute path to the Thrift file from which this module was compiled. All includes made by the Thrift file are relative to that path.
The module name is usually just the basename of the ThriftPath.
func Compile ¶
Compile parses and compiles the Thrift file at the given path and any other Thrift file it includes.
func (*Module) LookupConstant ¶
LookupConstant for Module.
func (*Module) LookupInclude ¶
LookupInclude for Module.
func (*Module) LookupService ¶
func (m *Module) LookupService(name string) (*ServiceSpec, error)
LookupService for Module.
func (*Module) LookupType ¶
LookupType for Module.
type NamedEntity ¶ added in v0.5.0
type NamedEntity interface { // ThriftName is the name of the type as it appears in the Thrift file. ThriftName() string // ThriftAnnotations is the map of all associated annotations from the Thrift file. ThriftAnnotations() Annotations }
NamedEntity is any Thrift entity with a name and annotations. Not all entities are TypeSpecs.
type Option ¶
type Option func(*compiler)
Option represents a compiler option.
func Filesystem ¶
Filesystem controls how the Thrift compiler accesses the filesystem.
type ResultSpec ¶
type ResultSpec struct { ReturnType TypeSpec Exceptions FieldGroup }
ResultSpec contains information about a Function's result type.
func (*ResultSpec) Link ¶
func (rs *ResultSpec) Link(scope Scope) (err error)
Link resolves any references made by the return type or exceptions in the ResultSpec.
type Scope ¶
type Scope interface { // GetName retrieves gets this scope. GetName() string // Retrieve a type defined in this scope. LookupType(name string) (TypeSpec, error) // Retrieve a service defined in this scope. LookupService(name string) (*ServiceSpec, error) // Retrieve a constant defined in this scope. LookupConstant(name string) (*Constant, error) // Retrieve an included scope. LookupInclude(name string) (Scope, error) }
Scope represents a queryable compilation scope.
All Lookup methods must only return types defined in this scope. References to items defined in included modules will be resolved by the caller.
func EmptyScope ¶
EmptyScope returns a Scope that fails all lookups.
type ServiceSpec ¶
type ServiceSpec struct { Name string File string Parent *ServiceSpec Functions map[string]*FunctionSpec Annotations Annotations // contains filtered or unexported fields }
ServiceSpec is a collection of named functions.
func (*ServiceSpec) Link ¶
func (s *ServiceSpec) Link(scope Scope) error
Link resolves any references made by the given service.
func (*ServiceSpec) ThriftFile ¶
func (s *ServiceSpec) ThriftFile() string
ThriftFile is the Thrift file in which this service was defined.
type SetSpec ¶
type SetSpec struct { ValueSpec TypeSpec Annotations Annotations // contains filtered or unexported fields }
SetSpec represents sets of values of the same type.
func (*SetSpec) ForEachTypeReference ¶
ForEachTypeReference for SetSpec
func (*SetSpec) ThriftAnnotations ¶ added in v0.5.0
func (s *SetSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (SetSpec) ThriftFile ¶
func (SetSpec) ThriftFile() string
type StringSpec ¶
type StringSpec struct { Annotations Annotations // contains filtered or unexported fields }
StringSpec is the TypeSpec for string types in a Thrift file.
func (*StringSpec) ForEachTypeReference ¶ added in v0.4.0
func (*StringSpec) ForEachTypeReference(func(TypeSpec) error) error
ForEachTypeReference is a no-op for primitives.
func (*StringSpec) Link ¶ added in v0.4.0
func (t *StringSpec) Link(Scope) (TypeSpec, error)
Link is a no-op for primitives.
func (*StringSpec) ThriftAnnotations ¶ added in v0.5.0
func (t *StringSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns the Thrift annotations specified with the reference to this type.
func (StringSpec) ThriftFile ¶ added in v0.4.0
func (StringSpec) ThriftFile() string
func (*StringSpec) ThriftName ¶ added in v0.4.0
func (*StringSpec) ThriftName() string
ThriftName returns "string".
func (*StringSpec) TypeCode ¶ added in v0.4.0
func (*StringSpec) TypeCode() wire.Type
TypeCode returns TBinary since Thrift strings are sent as binary over the wire.
type StructSpec ¶
type StructSpec struct { Name string File string Type ast.StructureType Fields FieldGroup Doc string Annotations Annotations // contains filtered or unexported fields }
StructSpec represents a structure defined in the Thrift file.
func (*StructSpec) ForEachTypeReference ¶
func (s *StructSpec) ForEachTypeReference(f func(TypeSpec) error) error
ForEachTypeReference for StructSpec
func (*StructSpec) IsExceptionType ¶
func (s *StructSpec) IsExceptionType() bool
IsExceptionType returns true if the StructSpec represents an exception declaration.
func (*StructSpec) Link ¶
func (s *StructSpec) Link(scope Scope) (TypeSpec, error)
Link links together all references in the StructSpec.
func (*StructSpec) ThriftAnnotations ¶ added in v0.5.0
func (s *StructSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (*StructSpec) ThriftFile ¶
func (s *StructSpec) ThriftFile() string
ThriftFile of the StructSpec.
func (*StructSpec) ThriftName ¶
func (s *StructSpec) ThriftName() string
ThriftName of the StructSpec.
type TypeSpec ¶
type TypeSpec interface { NamedEntity // Link resolves references to other types in this TypeSpecs to actual // TypeSpecs from the given Scope. Link(scope Scope) (TypeSpec, error) // TypeCode is the wire-level Thrift Type associated with this Type. TypeCode() wire.Type // ThriftFile is the path to the Thrift file in which this TypeSpec was // defined. This may be an empty string if this type is a native Thrift // type. ThriftFile() string // Applies the given function to each TypeSpec referenced by this // TypeSpec. This function MUST NOT be automatically called recursively on // the TypeSpecs referenced by the child TypeSpecs. The decision to make // that call is up to the caller of this function. // // Returns the first error returned by the function call or nil. ForEachTypeReference(func(TypeSpec) error) error }
TypeSpec contains information about Thrift types.
func RootTypeSpec ¶
RootTypeSpec returns the TypeSpec that the given linked TypeSpec points to.
For most types, this is the type itself. For Typedefs, it is the root TypeSpec of the Typedef's target.
type TypedefSpec ¶
type TypedefSpec struct { Name string File string Target TypeSpec Annotations Annotations Doc string // contains filtered or unexported fields }
TypedefSpec represents an alias to another type in the Thrift file.
func (*TypedefSpec) ForEachTypeReference ¶
func (t *TypedefSpec) ForEachTypeReference(f func(TypeSpec) error) error
ForEachTypeReference for TypedefSpec
func (*TypedefSpec) Link ¶
func (t *TypedefSpec) Link(scope Scope) (TypeSpec, error)
Link links the Target TypeSpec for this typedef in the given scope.
func (*TypedefSpec) ThriftAnnotations ¶ added in v0.5.0
func (t *TypedefSpec) ThriftAnnotations() Annotations
ThriftAnnotations returns all associated annotations.
func (*TypedefSpec) ThriftFile ¶
func (t *TypedefSpec) ThriftFile() string
ThriftFile for TypedefSpec.
func (*TypedefSpec) ThriftName ¶
func (t *TypedefSpec) ThriftName() string
ThriftName is the name of the typedef as it appears in the Thrift file.
func (*TypedefSpec) TypeCode ¶
func (t *TypedefSpec) TypeCode() wire.Type
TypeCode gets the wire type for the typedef.