Documentation ¶
Index ¶
- func ExprString(expr ast.Expr) string
- func FixImport(src []byte, file string)
- func GetImportPath(dir string) string
- func GetMod() string
- func RewriteJSONTag(file string, omitempty bool, convert func(old string) string) (string, error)
- func Visit(files *[]string) filepath.WalkFunc
- type FieldMeta
- type InterfaceCollector
- type InterfaceMeta
- type MethodMeta
- type PackageMeta
- type StructCollector
- type StructMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExprString ¶ added in v0.2.6
ExprString return string representation from ast.Expr
func FixImport ¶ added in v0.1.4
FixImport format source code and add missing import syntax automatically
func GetImportPath ¶
GetImportPath get import path of pkg from dir
func RewriteJSONTag ¶ added in v0.7.0
RewriteJSONTag overwrites json tag by convert function and return formatted source code
Types ¶
type FieldMeta ¶
type FieldMeta struct { Name string Type string Tag string Comments []string IsExport bool // used in OpenAPI 3.0 spec as property name DocName string }
FieldMeta wraps field info
type InterfaceCollector ¶ added in v0.1.4
type InterfaceCollector struct { Interfaces []InterfaceMeta Package PackageMeta // contains filtered or unexported fields }
InterfaceCollector collect interfaces by parsing source code
func BuildInterfaceCollector ¶ added in v0.2.6
func BuildInterfaceCollector(file string, exprString func(ast.Expr) string) InterfaceCollector
BuildInterfaceCollector initializes an InterfaceCollector and collects interfaces
func NewInterfaceCollector ¶ added in v0.2.6
func NewInterfaceCollector(exprString func(ast.Expr) string) *InterfaceCollector
NewInterfaceCollector initializes an InterfaceCollector
type InterfaceMeta ¶ added in v0.1.4
type InterfaceMeta struct { Name string Methods []MethodMeta Comments []string }
InterfaceMeta wraps interface info
type MethodMeta ¶ added in v0.1.4
type MethodMeta struct { // Recv method receiver Recv string // Name method name Name string // Params when generate client code from openapi3 spec json file, Params holds all method input parameters. // when generate client code from service interface in svc.go file, if there is struct type param, this struct type param will put into request body, // then others will be put into url as query string. if there is no struct type param and the api is a get request, all will be put into url as query string. // if there is no struct type param and the api is Not a get request, all will be put into request body as application/x-www-form-urlencoded data. // specially, if there is one or more *multipart.FileHeader or []*multipart.FileHeader params, all will be put into request body as multipart/form-data data. Params []FieldMeta // Results response Results []FieldMeta // PathVars not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, PathVars is parameters in url as path variable. PathVars []FieldMeta // HeaderVars not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, HeaderVars is parameters in header. HeaderVars []FieldMeta // BodyParams not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, BodyParams is parameters in request body as query string. BodyParams *FieldMeta // BodyJSON not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, BodyJSON is parameters in request body as json. BodyJSON *FieldMeta // Files not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, Files is parameters in request body as multipart file. Files []FieldMeta // Comments of the method Comments []string // Path api path // not support when generate client code from service interface in svc.go file Path string // QueryParams not support when generate client code from service interface in svc.go file // when generate client code from openapi3 spec json file, QueryParams is parameters in url as query string. QueryParams *FieldMeta }
MethodMeta represents an api
func GetMethodMeta ¶ added in v0.2.6
func GetMethodMeta(spec *ast.FuncDecl) MethodMeta
GetMethodMeta get method name then new MethodMeta struct from *ast.FuncDecl
func NewMethodMeta ¶ added in v0.2.6
NewMethodMeta new MethodMeta struct from *ast.FuncDecl
func (MethodMeta) String ¶ added in v0.2.6
func (mm MethodMeta) String() string
type StructCollector ¶
type StructCollector struct { Structs []StructMeta Methods map[string][]MethodMeta Package PackageMeta NonStructTypeMap map[string]ast.Expr // contains filtered or unexported fields }
StructCollector collect structs by parsing source code
func BuildStructCollector ¶ added in v0.2.6
func BuildStructCollector(file string, exprString func(ast.Expr) string) StructCollector
BuildStructCollector initializes an StructCollector and collects structs
func NewStructCollector ¶ added in v0.2.1
func NewStructCollector(exprString func(ast.Expr) string) *StructCollector
NewStructCollector initializes an StructCollector
func (*StructCollector) Collect ¶
func (sc *StructCollector) Collect(n ast.Node) ast.Visitor
Collect collects all structs from source code
func (*StructCollector) DocFlatEmbed ¶ added in v0.2.6
func (sc *StructCollector) DocFlatEmbed() []StructMeta
DocFlatEmbed flatten embed struct fields
type StructMeta ¶
type StructMeta struct { Name string Fields []FieldMeta Comments []string Methods []MethodMeta IsExport bool }
StructMeta wraps struct info
func NewStructMeta ¶ added in v0.2.6
func NewStructMeta(structType *ast.StructType, exprString func(ast.Expr) string) StructMeta
NewStructMeta new StructMeta from *ast.StructType