Documentation
¶
Index ¶
- Variables
- func IsBaseType(typ *Type) bool
- type BoolExpression
- type Category
- type Choice
- type Constant
- type DoubleExpression
- type Enum
- type Field
- type Function
- type IntExpression
- type Kind
- type ListExpression
- type Literal
- type MapExpression
- type Method
- type Model
- type Models
- type NumberExpression
- type Oneof
- type RequiredNess
- type StringExpression
- type Struct
- type Tag
- type Tags
- type Type
- type TypeDef
- type Variable
Constants ¶
This section is empty.
Variables ¶
var ( // BaseTypes enumerates all IDL primitive types mapped to Go types. BaseTypes = []*Type{TypeBool, TypeByte, TypeInt8, TypeInt16, TypeInt32, TypeInt64, TypeUint8, TypeUint16, TypeUint32, TypeUint64, TypeFloat64, TypeString, TypeBinary} ContainerTypes = []*Type{TypeBaseList, TypeBaseMap, TypeBaseSet} // BaseModel is a sentinel Model used as Scope for builtin types. // Types with Scope == &BaseModel are treated as built-in and don't need cross-package qualification. BaseModel = Model{} )
var ( TypeBool = &Type{ Name: "bool", Scope: &BaseModel, Kind: KindBool, } // TypeByte maps Thrift's "byte" to Go's "int8" (Thrift byte is signed). TypeByte = &Type{ Name: "int8", Scope: &BaseModel, Kind: KindInt8, } // TypePbByte maps Protobuf's "bytes" element to Go's "byte" (unsigned). TypePbByte = &Type{ Name: "byte", Scope: &BaseModel, Kind: KindInt8, } TypeUint8 = &Type{ Name: "uint8", Scope: &BaseModel, Kind: KindInt8, } TypeUint16 = &Type{ Name: "uint16", Scope: &BaseModel, Kind: KindInt16, } TypeUint32 = &Type{ Name: "uint32", Scope: &BaseModel, Kind: KindInt32, } TypeUint64 = &Type{ Name: "uint64", Scope: &BaseModel, Kind: KindInt64, } TypeUint = &Type{ Name: "uint", Scope: &BaseModel, Kind: KindInt, } TypeInt8 = &Type{ Name: "int8", Scope: &BaseModel, Kind: KindInt8, } TypeInt16 = &Type{ Name: "int16", Scope: &BaseModel, Kind: KindInt16, } TypeInt32 = &Type{ Name: "int32", Scope: &BaseModel, Kind: KindInt32, } TypeInt64 = &Type{ Name: "int64", Scope: &BaseModel, Kind: KindInt64, } TypeInt = &Type{ Name: "int", Scope: &BaseModel, Kind: KindInt, } TypeFloat32 = &Type{ Name: "float32", Scope: &BaseModel, Kind: KindFloat64, } TypeFloat64 = &Type{ Name: "float64", Scope: &BaseModel, Kind: KindFloat64, } TypeString = &Type{ Name: "string", Scope: &BaseModel, Kind: KindString, } TypeBinary = &Type{ Name: "binary", Scope: &BaseModel, Kind: KindSlice, Category: CategoryBinary, Extra: []*Type{TypePbByte}, } TypeBaseMap = &Type{ Name: "map", Scope: &BaseModel, Kind: KindMap, Category: CategoryMap, } TypeBaseSet = &Type{ Name: "set", Scope: &BaseModel, Kind: KindSlice, Category: CategorySet, } TypeBaseList = &Type{ Name: "list", Scope: &BaseModel, Kind: KindSlice, Category: CategoryList, } )
Functions ¶
func IsBaseType ¶
Types ¶
type BoolExpression ¶
type BoolExpression struct {
Src bool
}
func (BoolExpression) Expression ¶
func (boolExpr BoolExpression) Expression() string
type Category ¶
type Category int64
Category represents the IDL-level semantic type category (Thrift/Protobuf). Values align with Thrift type IDs where applicable.
const ( CategoryConstant Category = 1 CategoryBinary Category = 8 CategoryMap Category = 9 CategoryList Category = 10 CategorySet Category = 11 CategoryEnum Category = 12 CategoryStruct Category = 13 CategoryUnion Category = 14 CategoryException Category = 15 CategoryTypedef Category = 16 CategoryService Category = 17 )
type DoubleExpression ¶
type DoubleExpression struct {
Src float64
}
func (DoubleExpression) Expression ¶
func (doubleExpr DoubleExpression) Expression() string
type Field ¶
type Field struct {
Scope *Struct
Name string
Type *Type
IsSetDefault bool // whether a default value is explicitly set in IDL
DefaultValue Literal // the default value expression
Required RequiredNess // Thrift requiredness
Tags Tags // struct field tags (json, query, form, etc.)
LeadingComments string
TrailingComments string
IsPointer bool // whether to generate as pointer type (for optional fields)
}
type IntExpression ¶
type IntExpression struct {
Src int
}
func (IntExpression) Expression ¶
func (intExpr IntExpression) Expression() string
type Kind ¶
type Kind uint
Kind mirrors reflect.Kind to represent Go type kinds for code generation.
const ( KindInvalid Kind = iota KindBool KindInt KindInt8 KindInt16 KindInt32 KindInt64 KindUint KindUint8 KindUint16 KindUint32 KindUint64 KindUintptr KindFloat32 KindFloat64 KindComplex64 KindComplex128 KindArray KindChan KindFunc KindInterface KindMap KindPtr KindSlice KindString KindStruct KindUnsafePointer )
type ListExpression ¶
func (ListExpression) Expression ¶
func (listExpr ListExpression) Expression() string
type MapExpression ¶
func (MapExpression) Expression ¶
func (mapExpr MapExpression) Expression() string
type Model ¶
type Model struct {
FilePath string // output file path (set during generation)
Package string // Go import path for this model
Imports map[string]*Model // imported models, keyed by import path
PackageName string // short package name (last segment of Package)
Typedefs []TypeDef
Constants []Constant
Variables []Variable
Functions []Function
Enums []Enum
Structs []Struct
Methods []Method
Oneofs []Oneof // protobuf oneof fields
}
Model represents a single IDL file translated into Go code generation data. Each Model corresponds to one output .go file.
type NumberExpression ¶
type NumberExpression struct {
Src string
}
NumberExpression stores the number as a raw string to preserve the original IDL representation (e.g. hex literals, large numbers).
func (NumberExpression) Expression ¶
func (numExpr NumberExpression) Expression() string
type RequiredNess ¶
type RequiredNess int
RequiredNess maps to Thrift field requiredness semantics.
const ( RequiredNess_Default RequiredNess = 0 // Thrift "default" requiredness RequiredNess_Required RequiredNess = 1 RequiredNess_Optional RequiredNess = 2 )
type StringExpression ¶
type StringExpression struct {
Src string
}
func (StringExpression) Expression ¶
func (stringExpr StringExpression) Expression() string
type Type ¶
type Type struct {
Name string // Go type name (e.g. "int64", "MyStruct")
Scope *Model // owning model; nil means unresolved, &BaseModel means builtin
Kind Kind // Go type kind
Indirect bool // whether this type is referenced indirectly (pointer)
Category Category // IDL semantic category
Extra []*Type // container element types: [elem] for list/set, [key, value] for map
HasNew bool // whether this type needs a constructor (e.g. structs, enums)
}
Type describes a Go type for code generation, bridging IDL types to Go types.
func NewCategoryType ¶
NewCategoryType creates a shallow copy of typ with a different Category. Used when the same Go type has different IDL semantics (e.g. int64 as enum vs constant).
func NewEnumType ¶
func NewFuncType ¶
func NewOneofType ¶
func NewStructType ¶
func (*Type) IsBaseType ¶
func (*Type) IsSettable ¶
IsSettable returns true if the type is a reference type that can be nil-checked.
func (*Type) ResolveDefaultValue ¶
func (*Type) ResolveName ¶
ResolveName returns the fully qualified Go type name relative to scope. For structs, it prepends "*" (pointer). For types from different packages, it prepends the package name qualifier.
func (*Type) ResolveNameForTypedef ¶
ResolveNameForTypedef returns the fully qualified Go type name for a typedef alias. Unlike ResolveName, it does not add pointer prefix for struct types since typedefs define new named types rather than references.