Documentation ¶
Overview ¶
Package st2 provide a package to parse json/protobuf/thrift/go/csv code and generage go/protobuf/thrift code
Index ¶
- Constants
- Variables
- func Convert(ctx Context, reader io.Reader, writer io.Writer) error
- func CreateTmpl(ctx Context) string
- type AnyType
- type ArrayType
- type BinaryType
- type BoolType
- type Comment
- type Context
- type CsvParser
- type EmptyFormater
- type EnumType
- func (v EnumType) Go() string
- func (v EnumType) GoStructType() string
- func (v EnumType) IsBasicType() bool
- func (v EnumType) Json() string
- func (v EnumType) Proto() string
- func (v EnumType) ProtoStructType() string
- func (v EnumType) StructName() string
- func (v EnumType) Thrift() string
- func (v EnumType) ThriftStructType() string
- type Float32Type
- type Float64Type
- type Format
- type GoFormater
- type GoParser
- type Int16Type
- type Int32Type
- type Int64Type
- type Int8Type
- type JsonUnmarshalTagFormat
- type Lang
- type MapType
- type Member
- type NodeList
- type Parse
- type ProtoParser
- type SetType
- type StringType
- type Struct
- type StructLikeSource
- type StructLikeType
- func (v StructLikeType) Go() string
- func (v StructLikeType) GoStructType() string
- func (v StructLikeType) IsBasicType() bool
- func (v StructLikeType) Json() string
- func (v StructLikeType) Proto() string
- func (v StructLikeType) ProtoStructType() string
- func (v StructLikeType) StructName() string
- func (v StructLikeType) Thrift() string
- func (v StructLikeType) ThriftStructType() string
- type StructuredParser
- type ThriftParser
- type TomlUnmarshalTagFormat
- type Type
- type Uint16Type
- type Uint32Type
- type Uint64Type
- type Uint8Type
- type UnmarshalFunc
- type UnmarshalTagFormat
- type XMLContext
- type XMLUnmarshalTagFormat
- type YamlUnmarshalTagFormat
Constants ¶
const ( LangGo = "go" LangJson = "json" LangProto = "proto" LangThrift = "thrift" LangCsv = "csv" LangYaml = "yaml" LangYml = "yml" LangXML = "xml" LangToml = "toml" RootDefault = "Root" FlagXMLAttributeTagPrefixDefault = "," )
const ( StrInt = "int" StrInt8 = "int8" StrInt16 = "int16" StrInt32 = "int32" StrInt64 = "int64" StrUint = "uint" StrUint8 = "uint8" StrUint16 = "uint16" StrUint32 = "uint32" StrUint64 = "uint64" StrSint32 = "sint32" StrSint64 = "sint64" StrI16 = "i16" StrI32 = "i32" StrI64 = "i64" StrFixed32 = "fixed32" StrFixed64 = "fixed64" StrFloat32 = "float32" StrFloat64 = "float64" StrDouble = "double" StrFloat = "float" StrBool = "bool" StrString = "string" StrComplex64 = "complex64" StrComplex128 = "complex128" StrByte = "byte" StrBytes = "bytes" StrRune = "rune" StrUintptr = "uintptr" StrAny = "any" StrPbAny = "google.protobuf.Any" StrBinary = "binary" StrMap = "map" StrList = "list" StrSet = "set" StrNil = "nil" StrNull = "null" StrNumber = "number" StrRepeated = "repeated" )
Variables ¶
var ( SourceLangs = []Lang{ { Lang: LangJson, }, { Lang: LangYaml, Aliases: []string{LangYml}, }, { Lang: LangProto, }, { Lang: LangThrift, }, { Lang: LangGo, }, { Lang: LangCsv, }, { Lang: LangXML, }, { Lang: LangToml, }, } DestinationLangs = []Lang{ { Lang: LangGo, }, { Lang: LangProto, }, { Lang: LangThrift, }, } LangTmplMap = map[string]string{ LangGo: tmpl.Go, LangProto: tmpl.Proto, LangThrift: tmpl.Thrift, } )
Functions ¶
func CreateTmpl ¶
CreateTmpl Get the template data belongs to the context
Types ¶
type AnyType ¶
type AnyType struct{}
AnyType cover json null value, go any value, proto any value
func (AnyType) IsBasicType ¶
type BinaryType ¶
type BinaryType struct{}
func (BinaryType) Go ¶
func (v BinaryType) Go() string
func (BinaryType) IsBasicType ¶
func (v BinaryType) IsBasicType() bool
func (BinaryType) Json ¶
func (v BinaryType) Json() string
func (BinaryType) Proto ¶
func (v BinaryType) Proto() string
func (BinaryType) Thrift ¶
func (v BinaryType) Thrift() string
type Context ¶
type Context struct { Src string Dst string Root string Prefix string Suffix string XMLContext XMLContext }
Context struct contains the context running
func NewContext ¶
func NewContext(src, dst, root, prefix, suffix string, xmlContext XMLContext) Context
type CsvParser ¶
type CsvParser struct {
// contains filtered or unexported fields
}
CsvParser is a Parser to parse `.csv` source.
type EmptyFormater ¶
type EmptyFormater struct { }
EmptyFormat is a struct implement the Format interface with empty action
func (EmptyFormater) Format ¶
func (f EmptyFormater) Format(data []byte) []byte
type EnumType ¶
type EnumType struct {
Name string
}
func (EnumType) GoStructType ¶
func (EnumType) IsBasicType ¶
func (EnumType) ProtoStructType ¶
func (EnumType) StructName ¶
func (EnumType) ThriftStructType ¶
type Float32Type ¶
type Float32Type struct {
V float32
}
func (Float32Type) Go ¶
func (v Float32Type) Go() string
func (Float32Type) IsBasicType ¶
func (v Float32Type) IsBasicType() bool
func (Float32Type) Json ¶
func (v Float32Type) Json() string
func (Float32Type) Proto ¶
func (v Float32Type) Proto() string
func (Float32Type) Thrift ¶
func (v Float32Type) Thrift() string
func (Float32Type) Value ¶
func (v Float32Type) Value() string
type Float64Type ¶
type Float64Type struct {
V float64
}
func (Float64Type) Go ¶
func (v Float64Type) Go() string
func (Float64Type) IsBasicType ¶
func (v Float64Type) IsBasicType() bool
func (Float64Type) Json ¶
func (v Float64Type) Json() string
func (Float64Type) Proto ¶
func (v Float64Type) Proto() string
func (Float64Type) Thrift ¶
func (v Float64Type) Thrift() string
func (Float64Type) Value ¶
func (v Float64Type) Value() string
type Format ¶
Format is an interface to format source code
func CreateFormater ¶
CreateFormater Create a Format to format code
type GoFormater ¶
type GoFormater struct { }
GoFormater is a struct implement the Format interface with format golang source data
func (GoFormater) Format ¶
func (f GoFormater) Format(data []byte) []byte
type GoParser ¶
type GoParser struct {
// contains filtered or unexported fields
}
GoParser is a Parser to parse golang source.
type JsonUnmarshalTagFormat ¶
type JsonUnmarshalTagFormat struct{}
func (JsonUnmarshalTagFormat) TagFormat ¶
func (j JsonUnmarshalTagFormat) TagFormat() string
type MapType ¶
func (MapType) IsBasicType ¶
type Member ¶
Member is fields of Struct
func (Member) FieldCamel ¶
FieldCamel get a camel type field name
func (Member) GoTagString ¶
GoTagString get the go field tag string
type Parse ¶
Parse interface has a method `Parse` which parse source code to a list of Struct
func CreateParser ¶
CreateParser Create a Parse belongs to the context
type ProtoParser ¶
type ProtoParser struct {
// contains filtered or unexported fields
}
ProtoParser is a Parser to parse protobuf source
func NewProtoParser ¶
func NewProtoParser(ctx Context) *ProtoParser
NewProtoParser create ProtoParser
type StringType ¶
type StringType struct {
V string
}
func (StringType) Go ¶
func (v StringType) Go() string
func (StringType) IsBasicType ¶
func (v StringType) IsBasicType() bool
func (StringType) Json ¶
func (v StringType) Json() string
func (StringType) Proto ¶
func (v StringType) Proto() string
func (StringType) Thrift ¶
func (v StringType) Thrift() string
func (StringType) Value ¶
func (v StringType) Value() string
type StructLikeSource ¶
type StructLikeSource int
StructLikeSource which type of StructLikeType
const ( SLSUnknown StructLikeSource = 0 // Unknown type SLSStruct StructLikeSource = 1 // Struct type SLSUnion StructLikeSource = 2 // Union type )
const values of StructLikeSource
type StructLikeType ¶
type StructLikeType struct { Name string Source StructLikeSource }
func (StructLikeType) Go ¶
func (v StructLikeType) Go() string
func (StructLikeType) GoStructType ¶
func (v StructLikeType) GoStructType() string
func (StructLikeType) IsBasicType ¶
func (v StructLikeType) IsBasicType() bool
func (StructLikeType) Json ¶
func (v StructLikeType) Json() string
func (StructLikeType) Proto ¶
func (v StructLikeType) Proto() string
func (StructLikeType) ProtoStructType ¶
func (v StructLikeType) ProtoStructType() string
func (StructLikeType) StructName ¶
func (v StructLikeType) StructName() string
func (StructLikeType) Thrift ¶
func (v StructLikeType) Thrift() string
func (StructLikeType) ThriftStructType ¶
func (v StructLikeType) ThriftStructType() string
type StructuredParser ¶
type StructuredParser struct {
// contains filtered or unexported fields
}
StructuredParser is a Parser to parse structured data source
func NewJsonParser ¶
func NewJsonParser(ctx Context) *StructuredParser
NewJsonParser create StructuredParser to parse json source
func NewStructuredParser ¶
func NewStructuredParser(ctx Context, unmarshalTagFormat UnmarshalTagFormat) *StructuredParser
NewStructuredParser create StructuredParser
func NewTomlParser ¶
func NewTomlParser(ctx Context) *StructuredParser
func NewXMLParser ¶
func NewXMLParser(ctx Context) *StructuredParser
func NewYamlParser ¶
func NewYamlParser(ctx Context) *StructuredParser
NewYamlParser create StructuredParser to parse yaml source
type ThriftParser ¶
type ThriftParser struct {
// contains filtered or unexported fields
}
ThriftParser is a Parser to parse thrift source
func NewThriftParser ¶
func NewThriftParser(ctx Context) *ThriftParser
NewThriftParser create ThriftParser
type TomlUnmarshalTagFormat ¶
type TomlUnmarshalTagFormat struct{}
func (TomlUnmarshalTagFormat) TagFormat ¶
func (t TomlUnmarshalTagFormat) TagFormat() string
type Type ¶
var ( AnyVal Type = &AnyType{} BoolVal Type = &BoolType{} Float32Val Type = &Float32Type{} Float64Val Type = &Float64Type{} StringVal Type = &StringType{} ArrayVal Type = &ArrayType{} Int8Val Type = &Int8Type{} Int16Val Type = &Int16Type{} Int32Val Type = &Int32Type{} Int64Val Type = &Int64Type{} Uint8Val Type = &Uint8Type{} Uint16Val Type = &Uint16Type{} Uint32Val Type = &Uint32Type{} Uint64Val Type = &Uint64Type{} BinaryVal Type = &BinaryType{} MapVal Type = &MapType{} SetVal Type = &SetType{} EnumVal Type = &EnumType{} StructLikeVal Type = &StructLikeType{} )
type Uint16Type ¶
type Uint16Type struct {
V int16
}
func (Uint16Type) Go ¶
func (v Uint16Type) Go() string
func (Uint16Type) IsBasicType ¶
func (v Uint16Type) IsBasicType() bool
func (Uint16Type) Json ¶
func (v Uint16Type) Json() string
func (Uint16Type) Proto ¶
func (v Uint16Type) Proto() string
func (Uint16Type) Thrift ¶
func (v Uint16Type) Thrift() string
func (Uint16Type) Value ¶
func (v Uint16Type) Value() string
type Uint32Type ¶
type Uint32Type struct {
V int32
}
func (Uint32Type) Go ¶
func (v Uint32Type) Go() string
func (Uint32Type) IsBasicType ¶
func (v Uint32Type) IsBasicType() bool
func (Uint32Type) Json ¶
func (v Uint32Type) Json() string
func (Uint32Type) Proto ¶
func (v Uint32Type) Proto() string
func (Uint32Type) Thrift ¶
func (v Uint32Type) Thrift() string
func (Uint32Type) Value ¶
func (v Uint32Type) Value() string
type Uint64Type ¶
type Uint64Type struct {
V int64
}
func (Uint64Type) Go ¶
func (v Uint64Type) Go() string
func (Uint64Type) IsBasicType ¶
func (v Uint64Type) IsBasicType() bool
func (Uint64Type) Json ¶
func (v Uint64Type) Json() string
func (Uint64Type) Proto ¶
func (v Uint64Type) Proto() string
func (Uint64Type) Thrift ¶
func (v Uint64Type) Thrift() string
func (Uint64Type) Value ¶
func (v Uint64Type) Value() string
type UnmarshalFunc ¶
type UnmarshalTagFormat ¶
type XMLContext ¶
type XMLUnmarshalTagFormat ¶
func (XMLUnmarshalTagFormat) TagFormat ¶
func (x XMLUnmarshalTagFormat) TagFormat() string
type YamlUnmarshalTagFormat ¶
type YamlUnmarshalTagFormat struct{}
func (YamlUnmarshalTagFormat) TagFormat ¶
func (j YamlUnmarshalTagFormat) TagFormat() string