golang

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package golang is the generator backend for golang.

Index

Constants

View Source
const (
	DefaultThriftLib    = "github.com/apache/thrift/lib/go/thrift"
	DefaultUnknownLib   = "github.com/cloudwegox/thriftgo/generator/golang/extension/unknown"
	DefaultMetaLib      = "github.com/cloudwegox/thriftgo/generator/golang/extension/meta"
	ThriftReflectionLib = "github.com/cloudwegox/thriftgo/thrift_reflection"
	ThriftFieldMaskLib  = "github.com/cloudwegox/thriftgo/fieldmask"
	ThriftOptionLib     = "github.com/cloudwegox/thriftgo/extension/thrift_option"

	ThriftJSONUtilLib = "github.com/cloudwegox/thriftgo/utils/json_utils"
	KitexStreamingLib = "github.com/cloudwego/kitex/pkg/streaming"
)

Default libraries.

Variables

This section is empty.

Functions

func BackQuoted

func BackQuoted(s string) string

func BuildRefScope

func BuildRefScope(cu *CodeUtils, ast *parser.Thrift) (*Scope, *Scope, error)

func GetImportPackage

func GetImportPackage(path string) string

func GetImportPath

func GetImportPath(cu *CodeUtils, ast *parser.Thrift) string

func GetTypeID

func GetTypeID(t *parser.Type) string

GetTypeID returns the thrift type ID literal for the given type which is suitable to concate with "Read" or "Write" to produce a valid method name in the TProtocol interface. Note that enum types results in I32.

func GetTypeIDConstant

func GetTypeIDConstant(t *parser.Type) string

GetTypeIDConstant returns the thrift type ID literal for the given type which is suitable to concate with "thrift." to produce a valid type ID constant.

func IsBaseType

func IsBaseType(t *parser.Type) bool

IsBaseType determines whether the given type is a base type.

func IsConstantInGo

func IsConstantInGo(v *parser.Constant) bool

IsConstantInGo tells whether a constant in thrift IDL results in a constant in go.

func IsFixedLengthType

func IsFixedLengthType(t *parser.Type) bool

IsFixedLengthType determines whether the given type is a fixed length type.

func IsIntType

func IsIntType(t *parser.Type) bool

IsIntType determines whether the given type is a Int type.

func IsStrType

func IsStrType(t *parser.Type) bool

IsStrType determines whether the given type is a Str type.

func JoinPath

func JoinPath(elem ...string) string

func NeedRedirect

func NeedRedirect(f *parser.Field) bool

NeedRedirect deterimines whether the given field should result in a pointer type. Condition: struct-like || (optional non-binary base type without default vlaue).

func SupportIsSet

func SupportIsSet(f *parser.Field) bool

SupportIsSet determines whether a field supports IsSet query.

func ToRefFilename

func ToRefFilename(keepName bool, filename string) string

func ToReflectionFilename

func ToReflectionFilename(filename string) string

func ToReflectionRefFilename

func ToReflectionRefFilename(keepName bool, filename string) string

func ZeroWriter

func ZeroWriter(t *parser.Type, oprot string, err string) string

IsBaseType determines whether the given type is a base type.

Types

type Code

type Code string

Code is the type of go code segments.

func (Code) String

func (c Code) String() string

type CodeUtils

type CodeUtils struct {
	backend.LogFunc
	// contains filtered or unexported fields
}

CodeUtils contains a set of utility functions.

func NewCodeUtils

func NewCodeUtils(log backend.LogFunc) *CodeUtils

NewCodeUtils creates a new CodeUtils.

func (*CodeUtils) BuildFuncMap

func (cu *CodeUtils) BuildFuncMap() template.FuncMap

BuildFuncMap builds a function map for templates.

func (*CodeUtils) CombineOutputPath

func (cu *CodeUtils) CombineOutputPath(outputPath string, t *parser.Thrift) string

CombineOutputPath read the output and path variables and render them into the final path

func (*CodeUtils) Debug

func (cu *CodeUtils) Debug(vs ...interface{}) string

Debug prints the given values with println.

func (*CodeUtils) Features

func (cu *CodeUtils) Features() Features

Features returns the current settings of generator features.

func (*CodeUtils) GenFieldTags

func (cu *CodeUtils) GenFieldTags(f *Field, insertPoint string) (string, error)

GenFieldTags generates go tags for the given parser.Field.

func (*CodeUtils) GenTags

func (cu *CodeUtils) GenTags(f *parser.Field, insertPoint string) (string, error)

GenTags generates go tags for the given parser.Field.

func (*CodeUtils) GetFilePath

func (cu *CodeUtils) GetFilePath(t *parser.Thrift) string

GetFilePath returns a path to the generated file for the given IDL. Note that the result is a path relative to the root output path.

func (*CodeUtils) GetFilename

func (cu *CodeUtils) GetFilename(t *parser.Thrift) string

func (*CodeUtils) GetKeyType

func (cu *CodeUtils) GetKeyType(s *Scope, t *parser.Type) (*Scope, *parser.Type, error)

GetKeyType returns the key type of the given type. T must be a map type.

func (*CodeUtils) GetPackageName

func (cu *CodeUtils) GetPackageName(ast *parser.Thrift) string

GetPackageName returns a go package name for the given thrift AST.

func (*CodeUtils) GetPackagePrefix

func (cu *CodeUtils) GetPackagePrefix() (pp string)

GetPackagePrefix sets the package prefix in generated codes.

func (*CodeUtils) GetValType

func (cu *CodeUtils) GetValType(s *Scope, t *parser.Type) (*Scope, *parser.Type, error)

GetValType returns the value type of the given type. T must be a container type.

func (*CodeUtils) HandleOptions

func (cu *CodeUtils) HandleOptions(args []string) error

HandleOptions updates the CodeUtils with options.

func (*CodeUtils) Identify

func (cu *CodeUtils) Identify(name string) (s string, err error)

Identify converts an raw name from IDL into an exported identifier in go.

func (*CodeUtils) Import

func (cu *CodeUtils) Import(t *parser.Thrift) (pkg, pth string)

Import returns the package name and the full import path for the given AST.

func (*CodeUtils) MkRWCtx

func (cu *CodeUtils) MkRWCtx(root *Scope, f *Field) (*ReadWriteContext, error)

MkRWCtx = MakeReadWriteContext. Check the documents of ReadWriteContext for more informations.

func (*CodeUtils) NamespaceToFullImportPath

func (cu *CodeUtils) NamespaceToFullImportPath(ns string) string

NamespaceToFullImportPath returns an import path for the given namespace. The result path will contain the package prefix if it is set.

func (*CodeUtils) NamespaceToImportPath

func (cu *CodeUtils) NamespaceToImportPath(ns string) string

NamespaceToImportPath returns an import path for the given namespace. Note that the result will not have the package prefix set with SetPackagePrefix.

func (*CodeUtils) NamespaceToPackage

func (cu *CodeUtils) NamespaceToPackage(ns string) string

NamespaceToPackage converts a namespace to a package.

func (*CodeUtils) NamingStyle

func (cu *CodeUtils) NamingStyle() styles.Naming

NamingStyle returns the current naming style.

func (*CodeUtils) ParseNamespace

func (cu *CodeUtils) ParseNamespace(ast *parser.Thrift) (ref, pkg, pth string)

ParseNamespace retrieves informations from the given AST and returns a reference name in the IDL, a package name for generated codes and an import path.

func (*CodeUtils) RootScope

func (cu *CodeUtils) RootScope() *Scope

RootScope returns the root scope previously set by SetRootScope.

func (*CodeUtils) SetFeatures

func (cu *CodeUtils) SetFeatures(fs Features)

SetFeatures sets the feature set.

func (*CodeUtils) SetNamingStyle

func (cu *CodeUtils) SetNamingStyle(style styles.Naming)

SetNamingStyle sets the naming style.

func (*CodeUtils) SetPackagePrefix

func (cu *CodeUtils) SetPackagePrefix(pp string)

SetPackagePrefix sets the package prefix in generated codes.

func (*CodeUtils) SetRootScope

func (cu *CodeUtils) SetRootScope(s *Scope)

SetRootScope sets the root scope for rendering templates.

func (*CodeUtils) SetWithFieldMask

func (cu *CodeUtils) SetWithFieldMask(enable bool) bool

func (*CodeUtils) Template

func (cu *CodeUtils) Template() string

Template returns the current template name. Empty for the default.

func (*CodeUtils) UseInitialisms

func (cu *CodeUtils) UseInitialisms(enable bool)

UseInitialisms sets the naming style's initialisms option.

func (*CodeUtils) UsePackage

func (cu *CodeUtils) UsePackage(path, repl string)

UsePackage forces the generated codes to use the specific package.

func (*CodeUtils) UseTemplate

func (cu *CodeUtils) UseTemplate(value string) error

UseTemplate specifies a different template to generate codes.

type Constant

type Constant struct {
	*parser.Constant
	// contains filtered or unexported fields
}

Constant is a wrapper for the parser.Constant.

func (*Constant) GoName

func (c *Constant) GoName() Name

GoName returns the name in go code of the constant.

func (*Constant) GoTypeName

func (c *Constant) GoTypeName() TypeName

GoTypeName returns the type name in go code of the constant.

func (*Constant) Initialization

func (c *Constant) Initialization() Code

Initialization returns the initialization code of the constant.

type Constants

type Constants []*Constant

Constants is a list of constants.

func (Constants) GoConstants

func (cs Constants) GoConstants() (gcs Constants)

GoConstants returns the subset of the current constants that each one of them results a constant in Go.

func (Constants) GoVariables

func (cs Constants) GoVariables() (gvs Constants)

GoVariables returns the subset of the current constants that each one of them results a variable in Go.

type Enum

type Enum struct {
	*parser.Enum
	// contains filtered or unexported fields
}

Enum is a wrapper for the parser.Enum.

func (*Enum) GoName

func (e *Enum) GoName() Name

GoName returns the name in go code of the enum.

func (*Enum) Value

func (e *Enum) Value(name string) *EnumValue

Value returns a value defined in the enum with the given name. It returns nil if the value is not found.

func (*Enum) Values

func (e *Enum) Values() []*EnumValue

Values returns all values defined in the enum.

type EnumValue

type EnumValue struct {
	*parser.EnumValue
	// contains filtered or unexported fields
}

EnumValue is a wrapper for the parser.EnumValue.

func (*EnumValue) GoLiteral

func (ev *EnumValue) GoLiteral() Code

GoLiteral returns the literal in go code of the enum value.

func (*EnumValue) GoName

func (ev *EnumValue) GoName() Name

GoName returns the name in go code of the enum value.

type Features

type Features struct {
	MarshalEnumToText           bool `json_enum_as_text:"Generate MarshalText and UnmarshalText for enum values"`
	MarshalEnum                 bool `enum_marshal:"Generate MarshalText for enum values"`
	UnmarshalEnum               bool `enum_unmarshal:"Generate UnmarshalText for enum values"`
	GenerateSetter              bool `gen_setter:"Generate Set* methods for fields"`
	GenDatabaseTag              bool `gen_db_tag:"Generate 'db:$field' tag"`
	GenOmitEmptyTag             bool `omitempty_for_optional:"Generate 'omitempty' tags for optional fields."`
	TypedefAsTypeAlias          bool `use_type_alias:"Generate type alias for typedef instead of type define."`
	ValidateSet                 bool `validate_set:"Generate codes to validate the uniqueness of set elements."`
	ValueTypeForSIC             bool `value_type_in_container:"Generate value type for struct-like in container instead of pointer type."`
	ScanValueForEnum            bool `scan_value_for_enum:"Generate Scan and Value methods for enums to implement interfaces in std sql library."`
	ReorderFields               bool `reorder_fields:"Reorder fields of structs to improve memory usage."`
	TypedEnumString             bool `typed_enum_string:"Add type prefix to the string representation of enum values."`
	KeepUnknownFields           bool `keep_unknown_fields:"Generate codes to store unrecognized fields in structs."`
	GenDeepEqual                bool `gen_deep_equal:"Generate DeepEqual function for struct/union/exception."`
	CompatibleNames             bool `compatible_names:"Add a '_' suffix if an name has a prefix 'New' or suffix 'Args' or 'Result'."`
	ReserveComments             bool `reserve_comments:"Reserve comments of definitions in thrift file"`
	NilSafe                     bool `nil_safe:"Generate nil-safe getters."`
	FrugalTag                   bool `frugal_tag:"Generate 'frugal' tags."`
	EscapeDoubleInTag           bool `unescape_double_quote:"Unescape the double quotes in literals when generating go tags."`
	GenerateTypeMeta            bool `gen_type_meta:"Generate and register type meta for structures."`
	GenerateJSONTag             bool `gen_json_tag:"Generate struct with 'json' tag"`
	AlwaysGenerateJSONTag       bool `always_gen_json_tag:"Always generate 'json' tag even if go.tag is provided (Disabled by default)"`
	SnakeTyleJSONTag            bool `snake_style_json_tag:"Generate snake style json tag"`
	LowerCamelCaseJSONTag       bool `lower_camel_style_json_tag:"Generate lower camel case style json tag"`
	WithReflection              bool `with_reflection:"Generate reflection info"`
	EnumAsINT32                 bool `enum_as_int_32:"Generate enum type as int32"`
	CodeRefSlim                 bool `code_ref_slim:"Generate code ref by given idl-ref.yaml with less refs to avoid conflict"`
	CodeRef                     bool `code_ref:"Generate code ref by given idl-ref.yaml"`
	ExpCodeRef                  bool `` /* 146-byte string literal not displayed */
	KeepCodeRefName             bool `keep_code_ref_name:"Generate code ref but still keep file name."`
	TrimIDL                     bool `trim_idl:"Simplify IDL to the most concise form before generating code."`
	EnableNestedStruct          bool `` /* 147-byte string literal not displayed */
	JSONStringer                bool `json_stringer:"Generate the JSON marshal method in String() method."`
	WithFieldMask               bool `with_field_mask:"Support field-mask for generated code."`
	FieldMaskHalfway            bool `field_mask_halfway:"Support set field-mask on not-root struct."`
	FieldMaskZeroRequired       bool `field_mask_zero_required:"Write zero value instead of current value for required fields filtered by fieldmask."`
	ThriftStreaming             bool `thrift_streaming:"Recognize thrift streaming annotation and generate streaming code."`
	NoDefaultSerdes             bool `no_default_serdes:"Do not generate default thrift serdes code."`
	NoAliasTypeReflectionMethod bool `` /* 153-byte string literal not displayed */
	EnableRefInterface          bool `` /* 151-byte string literal not displayed */
	UseOption                   bool `` /* 127-byte string literal not displayed */
	// ForceUseOption         bool `use_option:"Forcefully parse all Thrift annotations into struct-style option fields. If parsing is not possible, an error will be thrown."`
	NoFmt             bool `` /* 129-byte string literal not displayed */
	SkipEmpty         bool `skip_empty:"If there's not content in file, just skip it. Later this feature will be a default feature."`
	NoProcessor       bool `no_processor:" Do not generate default thrift processor and client. Later this feature will be a default feature."`
	GetEnumAnnotation bool `get_enum_annotation:"Generate GetAnnotation method for enum types."`
}

Features controls the behavior of CodeUtils.

type Field

type Field struct {
	*parser.Field
	// contains filtered or unexported fields
}

Field is a wrapper for the parser.Field.

func (*Field) DeepEqual

func (f *Field) DeepEqual() Name

DeepEqual returns the deep compare method's name for the field.

func (*Field) DefaultTypeName

func (f *Field) DefaultTypeName() TypeName

DefaultTypeName returns the type name in go code of the default value of the field. Note that it might be different with the result of GoTypeName.

func (*Field) DefaultValue

func (f *Field) DefaultValue() Code

DefaultValue returns the go code of the field for its Initialization. Note that the code exists only when the field has default value.

func (*Field) Getter

func (f *Field) Getter() Name

Getter returns the getter method's name for the field.

func (*Field) GoName

func (f *Field) GoName() Name

GoName returns the name in go code of the field.

func (*Field) GoTypeName

func (f *Field) GoTypeName() TypeName

GoTypeName returns the type name in go code of the field.

func (*Field) IsNested

func (f *Field) IsNested() bool

IsNested returns whether the field is a nested type.

func (*Field) IsResponseFieldOfResult

func (f *Field) IsResponseFieldOfResult() bool

IsResponseFieldOfResult tells if the field is the response of a result type of a method.

func (*Field) IsSetter

func (f *Field) IsSetter() Name

IsSetter returns the isset method's name for the field.

func (*Field) Reader

func (f *Field) Reader() Name

Reader returns the name of the method that reads the field.

func (*Field) Setter

func (f *Field) Setter() Name

Setter returns the setter method's name for the field.

func (*Field) Writer

func (f *Field) Writer() Name

Writer returns the name of the method that writes the field.

type FrugalResolver

type FrugalResolver struct {
	// contains filtered or unexported fields
}

FrugalResolver resolves type names for frugal.

func NewFrugalResolver

func NewFrugalResolver(root *Scope, cu *CodeUtils) *FrugalResolver

NewFrugalResolver creates a new FrugalResolver with the given scope.

func (*FrugalResolver) ResolveFrugalTypeName

func (r *FrugalResolver) ResolveFrugalTypeName(t *parser.Type) (TypeName, error)

ResolveFrugalTypeName returns a legal type name in frugal for the given AST type.

type Function

type Function struct {
	*parser.Function
	// contains filtered or unexported fields
}

Function is a wrapper for the parser.Function.

func (*Function) ArgType

func (f *Function) ArgType() *StructLike

ArgType returns the synthesized structure that wraps of the function.

func (*Function) Arguments

func (f *Function) Arguments() []*Field

Arguments returns the argument list of the function.

func (*Function) GoName

func (f *Function) GoName() Name

GoName returns the go name of the function.

func (*Function) ResType

func (f *Function) ResType() *StructLike

ResType returns the synthesized structure of arguments of the function.

func (*Function) ResponseGoTypeName

func (f *Function) ResponseGoTypeName() TypeName

ResponseGoTypeName returns the go type of the response type of the function.

func (*Function) Service

func (f *Function) Service() *Service

Service returns the service that the function is defined in.

func (*Function) Streaming

func (f *Function) Streaming() *streaming.Streaming

func (*Function) Throws

func (f *Function) Throws() []*Field

Throws returns the throw list of the function.

type GoBackend

type GoBackend struct {
	// contains filtered or unexported fields
}

GoBackend generates go codes. The zero value of GoBackend is ready for use.

func (*GoBackend) BuiltinPlugins

func (g *GoBackend) BuiltinPlugins() []*plugin.Desc

BuiltinPlugins implements the Backend interface.

func (*GoBackend) Generate

func (g *GoBackend) Generate(req *plugin.Request, log backend.LogFunc) *plugin.Response

Generate implements the Backend interface.

func (*GoBackend) GetPlugin

func (g *GoBackend) GetPlugin(desc *plugin.Desc) plugin.Plugin

GetPlugin implements the Backend interface.

func (*GoBackend) Lang

func (g *GoBackend) Lang() string

Lang implements the Backend interface.

func (*GoBackend) Name

func (g *GoBackend) Name() string

Name implements the Backend interface.

func (*GoBackend) Options

func (g *GoBackend) Options() (opts []plugin.Option)

Options implements the Backend interface.

func (*GoBackend) PostProcess

func (g *GoBackend) PostProcess(path string, content []byte) ([]byte, error)

PostProcess implements the backend.PostProcessor interface to do source formatting before writing files out.

type Include

type Include struct {
	PackageName string
	ImportPath  string
	*Scope
}

Include associates an import in golang with the corresponding scope that built from an thrift AST in the include list.

type Includes

type Includes []*Include

Includes is a list of Include objects.

func (Includes) ByAST

func (is Includes) ByAST(ast *parser.Thrift) *Include

ByAST returns an Include whose scope matches the given AST. It returns nil if such an Include is not found.

func (Includes) ByIndex

func (is Includes) ByIndex(i int) *Include

ByIndex returns an Include at the given index. It returns nil if the index is invalid.

func (Includes) ByPackage

func (is Includes) ByPackage(pkg string) *Include

ByPackage returns an Include whose package name matches the given one. It returns nil if such an Include is not found.

type Name

type Name string

Name is the type of identifiers converted from a thrift AST to Go code.

func (Name) String

func (n Name) String() string

type ReadWriteContext

type ReadWriteContext struct {
	Type      *parser.Type
	TypeName  TypeName // The type name in Go code
	TypeID    string   // For `thrift.TProtocol.(Read|Write)${TypeID}` methods
	IsPointer bool     // Whether the target type is a pointer type in Go

	KeyCtx *ReadWriteContext // sub-context if the type is map
	ValCtx *ReadWriteContext // sub-context if the type is container

	Target   string // The target for assignment
	Source   string // The variable for right hand operand in deep-equal
	NeedDecl bool   // Whether a declaration of target is needed

	FieldMask string
	// contains filtered or unexported fields
}

ReadWriteContext contains information for generating codes in ReadField* and WriteField* functions. Each context stands for a struct field, a map key, a map value, a list elemement, or a set elemement.

func (*ReadWriteContext) GenID

func (c *ReadWriteContext) GenID(prefix string) (name string)

GenID returns a local variable with the given name as prefix.

func (*ReadWriteContext) NeedFieldMask

func (c *ReadWriteContext) NeedFieldMask() bool

func (*ReadWriteContext) WithDecl

func (c *ReadWriteContext) WithDecl() *ReadWriteContext

WithDecl claims that the context needs a variable declaration.

func (*ReadWriteContext) WithFieldMask

func (c *ReadWriteContext) WithFieldMask(fm string) *ReadWriteContext

WithDecl claims that the context needs a variable declaration.

func (*ReadWriteContext) WithSource

func (c *ReadWriteContext) WithSource(s string) *ReadWriteContext

WithSource sets the source name.

func (*ReadWriteContext) WithTarget

func (c *ReadWriteContext) WithTarget(t string) *ReadWriteContext

WithTarget sets the target name.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves names for types, names and initialization value for thrift AST nodes in a scope (the root scope).

func NewResolver

func NewResolver(root *Scope, cu *CodeUtils) *Resolver

NewResolver creates a new Resolver with the given scope.

func (*Resolver) GetConstInit

func (r *Resolver) GetConstInit(name string, t *parser.Type, v *parser.ConstValue) (Code, error)

GetConstInit returns the initialization code for a constant.

func (*Resolver) GetDefaultValueTypeName

func (r *Resolver) GetDefaultValueTypeName(f *parser.Field) (TypeName, error)

GetDefaultValueTypeName returns a type name suitable for the default value of the given field.

func (*Resolver) GetFieldInit

func (r *Resolver) GetFieldInit(f *parser.Field) (Code, error)

GetFieldInit returns the initialization code for a field. The given field must have a default value.

func (*Resolver) GetTypeName

func (r *Resolver) GetTypeName(g *Scope, t *parser.Type) (name TypeName, err error)

GetTypeName returns a an type name (with selector if necessary) of the given type to be used in the root file. The type t must be a parser.Type associated with g.

func (*Resolver) ResolveConst

func (r *Resolver) ResolveConst(g *Scope, name string, t *parser.Type, v *parser.ConstValue) (Code, error)

ResolveConst returns the initialization code for a constant or a default value. The type t must be a parser.Type associated with g.

func (*Resolver) ResolveFieldTypeName

func (r *Resolver) ResolveFieldTypeName(f *parser.Field) (TypeName, error)

ResolveFieldTypeName returns a legal type name in go for the given field.

func (*Resolver) ResolveTypeName

func (r *Resolver) ResolveTypeName(t *parser.Type) (TypeName, error)

ResolveTypeName returns a legal type name in go for the given AST type.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope contains the type symbols defined in a thrift IDL and wraps them to provide access to resolved names in go code.

func BuildScope

func BuildScope(cu *CodeUtils, ast *parser.Thrift) (*Scope, error)

BuildScope creates a scope of the AST with its includes processed recursively. todo check cache

func (*Scope) AST

func (s *Scope) AST() *parser.Thrift

AST returns the thrift AST associated with the scope.

func (*Scope) Constant

func (s *Scope) Constant(name string) *Constant

Constant returns a constant defined in the current scope with the given name. It returns nil if the constant is not found.

func (*Scope) Constants

func (s *Scope) Constants() Constants

Constants returns all thrift constants defined in the current scope.

func (*Scope) Enum

func (s *Scope) Enum(name string) *Enum

Enum returns an enum defined in the current scope with the given name. It returns nil if the enum is not found.

func (*Scope) Enums

func (s *Scope) Enums() []*Enum

Enums returns all enums defined in the current scope.

func (*Scope) Exception

func (s *Scope) Exception(name string) *StructLike

Exception returns an exception defined in the current scope with the given name. It returns nil if the exception is not found.

func (*Scope) Exceptions

func (s *Scope) Exceptions() []*StructLike

Exceptions returns all exception defined in the current scope.

func (*Scope) FilePackage

func (s *Scope) FilePackage() string

func (*Scope) GetFirstDescriptor

func (s *Scope) GetFirstDescriptor() string

func (*Scope) GetOption

func (s *Scope) GetOption(filepath string) []string

func (*Scope) IDLName

func (s *Scope) IDLName() string

func (*Scope) Includes

func (s *Scope) Includes() Includes

Includes returns the include list of the current scope.

func (*Scope) IsEmpty

func (s *Scope) IsEmpty() bool

func (*Scope) MarshalDescriptor

func (s *Scope) MarshalDescriptor() string

func (*Scope) Namespace

func (s *Scope) Namespace() namespace.Namespace

Namespace returns the global namespace of the current scope.

func (*Scope) RefPackage

func (s *Scope) RefPackage() string

func (*Scope) RefPath

func (s *Scope) RefPath() string

func (*Scope) ResolveImports

func (s *Scope) ResolveImports() (map[string]string, error)

ResolveImports returns a map of import path to alias built from the include list of the IDL. An alias may be an empty string to indicate no alias is need for the import path.

func (*Scope) Service

func (s *Scope) Service(name string) *Service

Service returns a service defined in the current scope with the given name. It returns nil if the service is not found.

func (*Scope) Services

func (s *Scope) Services() []*Service

Services returns all service defined in the current scope.

func (*Scope) Struct

func (s *Scope) Struct(name string) *StructLike

Struct returns a struct defined in the current scope with the given name. It returns nil if the struct is not found.

func (*Scope) StructLike

func (s *Scope) StructLike(name string) *StructLike

StructLike returns a struct-like defined in the current scope with the given name. It returns nil if the struct-like is not found.

func (*Scope) StructLikes

func (s *Scope) StructLikes() (ss []*StructLike)

StructLikes returns all struct-like defined in the current scope.

func (*Scope) Structs

func (s *Scope) Structs() []*StructLike

Structs returns all struct defined in the current scope.

func (*Scope) Typedef

func (s *Scope) Typedef(alias string) *Typedef

Typedef returns a typedef defined in the current scope with the given name. It returns nil if the typedef is not found.

func (*Scope) Typedefs

func (s *Scope) Typedefs() []*Typedef

Typedefs returns all typedefs defined in the current scope.

func (*Scope) Union

func (s *Scope) Union(name string) *StructLike

Union returns a union defined in the current scope with the given name. It returns nil if the union is not found.

func (*Scope) Unions

func (s *Scope) Unions() []*StructLike

Unions returns all union defined in the current scope.

type Service

type Service struct {
	*parser.Service
	// contains filtered or unexported fields
}

Service is a wrapper for the parser.Service.

func (*Service) Base

func (s *Service) Base() *Service

Base returns the base service that the current service extends. It returns nil if the service has no base service.

func (*Service) From

func (s *Service) From() *Scope

From returns the scope that the service is defined in.

func (*Service) Function

func (s *Service) Function(name string) *Function

Function returns a function defined in the service with the given name. It returns nil if the function is not found.

func (*Service) Functions

func (s *Service) Functions() []*Function

Functions returns all functions defined in the service.

func (*Service) GoName

func (s *Service) GoName() Name

GoName returns the name in go code of the service.

func (*Service) Namespace

func (s *Service) Namespace() namespace.Namespace

Namespace returns the namespace of the service.

type StructLike

type StructLike struct {
	*parser.StructLike
	// contains filtered or unexported fields
}

StructLike is a wrapper for the parser.StructLike.

func (*StructLike) Field

func (s *StructLike) Field(name string) *Field

Field returns a field of the struct-like that has the given name. It returns nil if such a field is not found.

func (*StructLike) Fields

func (s *StructLike) Fields() []*Field

Fields returns all fields defined in the struct-like.

func (*StructLike) GoName

func (s *StructLike) GoName() Name

GoName returns the name in go code of the struct-like.

func (*StructLike) IsAlias

func (s *StructLike) IsAlias() bool

IsAlias returns whether this type is alias of existing type

func (*StructLike) Namespace

func (s *StructLike) Namespace() namespace.Namespace

Namespace returns the namescope of the struct-like.

type TypeName

type TypeName string

TypeName is the type for Go symbols converted from a thrift AST. It provides serveral methods to manipulate a type name of a symbol.

func (TypeName) Deref

func (tn TypeName) Deref() TypeName

Deref removes the "&" and "*" prefix of the given type name.

func (TypeName) IsForeign

func (tn TypeName) IsForeign() bool

IsForeign reports whether the type name is from another module.

func (TypeName) IsPointer

func (tn TypeName) IsPointer() bool

IsPointer reports whether the type name is a pointer type by detecting the prefix "*".

func (TypeName) NewFunc

func (tn TypeName) NewFunc() Name

NewFunc returns the construction function of the given type.

func (TypeName) Pointerize

func (tn TypeName) Pointerize() TypeName

Pointerize returns the pointer type of the current type name.

func (TypeName) String

func (tn TypeName) String() string

type Typedef

type Typedef struct {
	*parser.Typedef
	// contains filtered or unexported fields
}

Typedef is a wrapper for the parser.Typedef.

func (*Typedef) GoName

func (t *Typedef) GoName() Name

GoName returns the name in go code of the typedef.

func (*Typedef) GoTypeName

func (t *Typedef) GoTypeName() TypeName

GoTypeName returns the type name in go code of the typedef.

Directories

Path Synopsis
extension
unknown
Package unknown .
Package unknown .
Package templates defines templates for generating golang codes.
Package templates defines templates for generating golang codes.
ref

Jump to

Keyboard shortcuts

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