Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertStrToBasicType(str string, t *types.Basic) interface{}
- func InspectPackage(pkg *packages.Package, visit func(pkg *packages.Package) bool)
- func LogDebug(format string, args ...interface{})
- func LogError(format string, args ...interface{})
- func LogInfo(format string, args ...interface{})
- func LogStrictError(format string, args ...interface{})
- func LogStrictWarn(format string, args ...interface{})
- func LogWarn(format string, args ...interface{})
- func NormalizeComment(text, trimStart string) string
- func ReadGoMod(pkgPath string) (mod *modfile.File, err error)
- func SetGlobalLogColorized(colorized bool)
- func SetGlobalLogLevel(level LogLevel)
- func SetGlobalLogStrictMode(strict bool)
- func SetGlobalLogTimestamp(timestamp bool)
- type A
- type API
- type APISpec
- type APIs
- type Analyzer
- func (a *Analyzer) APIs() *APIs
- func (a *Analyzer) AddRoutes(items ...*API)
- func (a *Analyzer) Depends(pkgNames ...string) *Analyzer
- func (a *Analyzer) Doc() *spec.T
- func (a *Analyzer) Plugin(plugins ...Plugin) *Analyzer
- func (a *Analyzer) Process(packagePath string) *Analyzer
- func (a *Analyzer) WithStrictMode(strict bool) *Analyzer
- type CallInfo
- type CallRule
- type Comment
- func (c *Comment) ApplyToSchema(schema *spec.SchemaRef)
- func (c *Comment) Consumes() []string
- func (c *Comment) Deprecated() bool
- func (c *Comment) ID() string
- func (c *Comment) Ignore() bool
- func (c *Comment) Produces() []string
- func (c *Comment) Required() bool
- func (c *Comment) Security() *spec.SecurityRequirements
- func (c *Comment) Summary() string
- func (c *Comment) Tags() []string
- func (c *Comment) Text() string
- func (c *Comment) TextPointer() *string
- func (c *Comment) TrimPrefix(prefix string) string
- type CommentStack
- type Config
- type Context
- func (c *Context) APIs() *APIs
- func (c *Context) AddAPI(items ...*API)
- func (c *Context) Block() *Context
- func (c *Context) CommentStack() *CommentStack
- func (c *Context) Doc() *spec.T
- func (c *Context) File() *ast.File
- func (c *Context) GetCallInfo(n ast.Node) (string, string, error)
- func (c *Context) GetDefinition(pkg, name string) Definition
- func (c *Context) GetFuncFromAstNode(n ast.Node) *types.Func
- func (c *Context) GetHeadingCommentOf(pos token.Pos) *ast.CommentGroup
- func (c *Context) GetSchemaByExpr(expr ast.Expr, contentType string) *spec.SchemaRef
- func (c *Context) GetTrailingCommentOf(pos token.Pos) *ast.CommentGroup
- func (c *Context) LineColumn(pos token.Pos) string
- func (c *Context) MatchCall(n ast.Node, rule *CallRule, ...)
- func (c *Context) NewEnv() *Context
- func (c *Context) Package() *packages.Package
- func (c *Context) ParseComment(commentGroup *ast.CommentGroup) *Comment
- func (c *Context) ParseStatusCode(status ast.Expr) int
- func (c *Context) ParseType(t types.Type) Definition
- func (c *Context) StrictError(format string, args ...interface{})
- func (c *Context) StrictWarn(format string, args ...interface{})
- func (c *Context) WithFile(file *ast.File) *Context
- func (c *Context) WithPackage(pkg *packages.Package) *Context
- type Definition
- type Definitions
- type Entrypoint
- type Environment
- type FieldNameParser
- type FuncDefinition
- type GeneratorConfig
- type LogLevel
- type Logger
- func (l *Logger) Debug(format string, args ...interface{})
- func (l *Logger) Error(format string, args ...interface{})
- func (l *Logger) Info(format string, args ...interface{})
- func (l *Logger) SetColorized(colorized bool)
- func (l *Logger) SetErrorOutput(w io.Writer)
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetStrictMode(strict bool)
- func (l *Logger) SetTimestamp(timestamp bool)
- func (l *Logger) StrictError(format string, args ...interface{})
- func (l *Logger) StrictWarn(format string, args ...interface{})
- func (l *Logger) Warn(format string, args ...interface{})
- type ModFile
- type OpenAPIConfig
- type ParamNameParser
- type ParamParser
- type Plugin
- type RouteAnalyzer
- type RouteGroup
- type SchemaBuilder
- type SecuritySchemes
- type Stack
- type TypeDefinition
Constants ¶
const ( MimeTypeJson = "application/json" MimeApplicationXml = "application/xml" MimeTypeXml = "text/xml" MimeTypeFormData = "multipart/form-data" MimeTypeFormUrlencoded = "application/x-www-form-urlencoded" )
Variables ¶
var DEBUG = os.Getenv("DEBUG") == "on"
Functions ¶
func ConvertStrToBasicType ¶
func InspectPackage ¶
func LogStrictError ¶
func LogStrictError(format string, args ...interface{})
func LogStrictWarn ¶
func LogStrictWarn(format string, args ...interface{})
func NormalizeComment ¶
func SetGlobalLogColorized ¶
func SetGlobalLogColorized(colorized bool)
SetGlobalLogColorized sets the global logger colorization
func SetGlobalLogLevel ¶
func SetGlobalLogLevel(level LogLevel)
SetGlobalLogLevel sets the global logger level
func SetGlobalLogStrictMode ¶
func SetGlobalLogStrictMode(strict bool)
SetGlobalLogStrictMode sets the global logger strict mode
func SetGlobalLogTimestamp ¶
func SetGlobalLogTimestamp(timestamp bool)
SetGlobalLogTimestamp sets the global logger timestamp
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
func NewAnalyzer ¶
func (*Analyzer) WithStrictMode ¶
type CallRule ¶
func NewCallRule ¶
func NewCallRule() *CallRule
type Comment ¶
type Comment struct { Annotations []annotation.Annotation // contains filtered or unexported fields }
func ParseComment ¶
func ParseComment(commentGroup *ast.CommentGroup, fSet *token.FileSet) *Comment
func ParseCommentWithContext ¶
func (*Comment) ApplyToSchema ¶
func (*Comment) Deprecated ¶
func (*Comment) Security ¶
func (c *Comment) Security() *spec.SecurityRequirements
func (*Comment) TextPointer ¶
func (*Comment) TrimPrefix ¶
TrimPrefix trim comment prefix and return trimmed string
type CommentStack ¶
type CommentStack struct {
// contains filtered or unexported fields
}
func NewCommentStack ¶
func NewCommentStack(parent *CommentStack, comment *Comment) *CommentStack
func (*CommentStack) LookupAnnotations ¶
func (e *CommentStack) LookupAnnotations(annotType annotation.Type) []annotation.Annotation
func (*CommentStack) LookupTags ¶
func (e *CommentStack) LookupTags() []string
func (*CommentStack) ResolveByAnnotation ¶
func (e *CommentStack) ResolveByAnnotation(annotType annotation.Type) *CommentStack
type Config ¶
type Config struct { Plugin string Dir string Output string Depends []string StrictMode bool LogLevel string `yaml:"logLevel"` OpenAPI OpenAPIConfig Generators []*GeneratorConfig }
type Context ¶
type Context struct { Env *Environment // contains filtered or unexported fields }
func (*Context) CommentStack ¶
func (c *Context) CommentStack() *CommentStack
func (*Context) GetCallInfo ¶
GetCallInfo returns the package or type and name associated with a call expression
e.g. GetCallInfo(`c.GET("/ping", ...)`) returns ("*github/gin-gonic/gin.RouterGroup", "GET", nil)
func (*Context) GetDefinition ¶
func (c *Context) GetDefinition(pkg, name string) Definition
func (*Context) GetHeadingCommentOf ¶
func (c *Context) GetHeadingCommentOf(pos token.Pos) *ast.CommentGroup
func (*Context) GetSchemaByExpr ¶
func (*Context) GetTrailingCommentOf ¶
func (c *Context) GetTrailingCommentOf(pos token.Pos) *ast.CommentGroup
func (*Context) ParseComment ¶
func (c *Context) ParseComment(commentGroup *ast.CommentGroup) *Comment
func (*Context) StrictError ¶
StrictError prints red error message in strict mode, otherwise prints to stderr
func (*Context) StrictWarn ¶
StrictWarn prints yellow warning message in strict mode, otherwise prints to stderr
type Definition ¶
type Definitions ¶
type Definitions map[string]Definition
func (*Definitions) Get ¶
func (d *Definitions) Get(key string) Definition
func (*Definitions) Set ¶
func (d *Definitions) Set(def Definition)
type Entrypoint ¶
type Entrypoint struct {
// contains filtered or unexported fields
}
func NewEntrypoint ¶
func NewEntrypoint(plugins ...Plugin) *Entrypoint
func (*Entrypoint) Run ¶
func (e *Entrypoint) Run(args []string)
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(parent *Environment) *Environment
func (*Environment) Assign ¶
func (e *Environment) Assign(k, v interface{}) *Environment
func (*Environment) Define ¶
func (e *Environment) Define(k, v interface{}) *Environment
func (*Environment) Lookup ¶
func (e *Environment) Lookup(k interface{}) interface{}
func (*Environment) Resolve ¶
func (e *Environment) Resolve(k interface{}) *Environment
type FuncDefinition ¶
func NewFuncDefinition ¶
func (*FuncDefinition) File ¶
func (f *FuncDefinition) File() *ast.File
func (*FuncDefinition) Key ¶
func (f *FuncDefinition) Key() string
func (*FuncDefinition) Pkg ¶
func (f *FuncDefinition) Pkg() *packages.Package
type GeneratorConfig ¶
type LogLevel ¶
type LogLevel int
LogLevel represents the severity level of a log message
const ( // LogLevelSilent suppresses all log output LogLevelSilent LogLevel = iota // LogLevelError shows only error messages LogLevelError // LogLevelWarn shows error and warning messages LogLevelWarn // LogLevelInfo shows error, warning, and info messages LogLevelInfo // LogLevelDebug shows all messages including debug information LogLevelDebug )
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides structured logging with different levels
func GetGlobalLogger ¶
func GetGlobalLogger() *Logger
GetGlobalLogger returns the global logger instance
func (*Logger) SetColorized ¶
SetColorized enables or disables colored output
func (*Logger) SetErrorOutput ¶
SetErrorOutput sets the output writer for error and warning messages
func (*Logger) SetStrictMode ¶
SetStrictMode enables or disables strict mode
func (*Logger) SetTimestamp ¶
SetTimestamp enables or disables timestamp in log messages
func (*Logger) StrictError ¶
StrictError logs an error in strict mode (red) or normal mode (stderr)
func (*Logger) StrictWarn ¶
StrictWarn logs a warning in strict mode (yellow) or normal mode (stderr)
type ModFile ¶
func LoadModFileFrom ¶
type OpenAPIConfig ¶
type OpenAPIConfig struct { OpenAPI string `yaml:"openapi"` // OpenAPI version 3.0.0|3.0.3|3.1.0 Info *spec.Info `yaml:"info"` // Required SecuritySchemes *SecuritySchemes `yaml:"securitySchemes"` }
func (OpenAPIConfig) ApplyToDoc ¶
func (c OpenAPIConfig) ApplyToDoc(doc *spec.T)
type ParamNameParser ¶
type ParamParser ¶
type ParamParser struct {
// contains filtered or unexported fields
}
func NewParamParser ¶
func NewParamParser(ctx *Context, nameParser ParamNameParser) *ParamParser
type Plugin ¶
type Plugin interface { Name() string Mount(k *koanf.Koanf) error Analyze(ctx *Context, node ast.Node) }
Plugin 用于对解析逻辑进行扩展以支持不同的框架/模式
type RouteGroup ¶
type RouteGroup struct {
Prefix string
}
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
func NewSchemaBuilder ¶
func NewSchemaBuilder(ctx *Context, contentType string) *SchemaBuilder
func (*SchemaBuilder) ParseExpr ¶
func (s *SchemaBuilder) ParseExpr(expr ast.Expr) (schema *spec.SchemaRef)
func (*SchemaBuilder) WithFieldNameParser ¶
func (s *SchemaBuilder) WithFieldNameParser(parser FieldNameParser) *SchemaBuilder
type SecuritySchemes ¶
type SecuritySchemes map[string]*spec.SecurityScheme
type TypeDefinition ¶
type TypeDefinition struct { Spec *ast.TypeSpec // Enum items Enums []*spec.ExtendedEnumItem // contains filtered or unexported fields }
func NewTypeDefinition ¶
func (*TypeDefinition) File ¶
func (t *TypeDefinition) File() *ast.File
func (*TypeDefinition) Key ¶
func (t *TypeDefinition) Key() string
func (*TypeDefinition) ModelKey ¶
func (t *TypeDefinition) ModelKey(typeArgs ...*spec.SchemaRef) string
func (*TypeDefinition) Pkg ¶
func (t *TypeDefinition) Pkg() *packages.Package