Documentation
¶
Index ¶
Constants ¶
const ( // LogTrace is a flag that if used will enable // Trace logs LogTrace = logger.LvlTrace // LogDebug is a flag that if used will enable // Debug logs LogDebug = logger.LvlDebug // LogInfo is a flag that if used will enable // Info logs LogInfo = logger.LvlInfo // LogWarn is a flag that if used will enable // Warn logs LogWarn = logger.LvlWarn // LogError is a flag that if used will enable // Error logs LogError = logger.LvlError // LogFatal is a flag that if used will enable // Fatal logs LogFatal = logger.LvlFatal // LogJSON set the logs to be parsed // to JSON before printing it to the // stdout (one per line) LogJSON = uint64(1 << 6) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Tests (from packages.Config) if set, the
// loader includes not just the packages matching
// a particular pattern but also any related test
// packages, including test-only variants of the
// package and the test executable.
//
// For example, when using the go command, loading
// "fmt" with Tests=true returns four packages, with
// IDs "fmt" (the standard package), "fmt [fmt.test]"
// (the package as compiled for the test), "fmt_test"
// (the test functions from source files in package fmt_test),
// and "fmt.test" (the test binary).
//
// In build systems with explicit names for tests,
// setting Tests may have no effect.
Tests bool
// Dir (from packages.Config) is the directory
// in which to run the build system's query tool
// that provides information about the packages.
//
// If Dir is empty, the tool is run in the current
// directory
Dir string
// Env (from packages.Config) is the environment
// to use when invoking the build system's query
// tool.
//
// If Env is nil, the current environment is used.
// As in os/exec's Cmd, only the last value in the
// slice for each environment key is used. To specify
// the setting of only a few variables, append to the
// current environment, as in:
// opt.Env = append(os.Environ(), "GOOS=plan9", "GOARCH=386")
Env []string
// Fset (from packages.Config) provides source
// position information for syntax trees and
// types.
//
// If Fset is nil, go-codegen will create a new
// fileset.
Fset *token.FileSet
// BuildFlags (from packages.Config) is a list of
// command-line flags to be passed through to the
// build system's query tool.
BuildFlags []string
// Focus sets the typename/filename/pkgname/etc that
// the parser should focus.
//
// Note that if you set the focus to be some pkg, the
// filenames, typenames, etc, will continue to be used.
// Only other pkgs will be ignored (the same for filenames,
// typenames, etc)
Focus *Focus
// Logger is an instance of the LoggerCLI, already created
// by the lib user.
//
// Note that by using this field, the value of the LogFlags
// field will be ignored
Logger LoggerCLI
// LogFlags controls the logging configuration of the parser.
// It can be set using the constants LogTrace, LogDebug, LogJSON,
// etc. If the Logger field is set, this field will be ignored.
//
// Note that you can use a bitwise-AND operator to combine
// multiple flags
LogFlags uint64
}
Config holds some information about the parser behaviour.
Some fields of the packages.Config struct may appear inside this Config struct, exposing them to client customization (others hidden)
type Focus ¶
type Focus struct {
// contains filtered or unexported fields
}
Focus tells to the parser what it needs to focus on
func FocusFilePath ¶
FocusFilePath will tell the parser to look for a specific file, based on it's ABSOLUTE path.
The given string will be directly forwarded to a regexp.MatchString call, so it should represent a go regular expression.
func FocusPackagePath ¶
FocusPackagePath will tell the parser to look for a specific package.
The given string will be directly forwarded to a regexp.MatchString call, so it should represent a go regular expression.
Note that the packagePath argument refers to the import path to the target package, not the package name
func FocusTypeName ¶
FocusTypeName will tell the parser to look for a specific GO typename.
The given string will be directly forwarded to a regexp.MatchString call, so it should represent a go regular expression.
func MergeFocus ¶ added in v1.0.1
type GoParser ¶
type GoParser struct {
// contains filtered or unexported fields
}
GoParser is a type that can parse GO source code and iterate over the parsed code
func NewGoParser ¶
NewGoParser creates a new parser for GO source files
The pattern argument will be forwarded directly to the packages.Load function. Take a look at the docs:
Load passes most patterns directly to the underlying build tool,
but all patterns with the prefix "query=", where query is a non-empty
string of letters from [a-z], are reserved and may be interpreted
as query operators
Two query operators are currently supported: "file" and "pattern"
The query "file=path/to/file.go" matches the package or packages
enclosing the Go source file path/to/file.go. For example
"file=~/go/src/fmt/print.go" might return the packages "fmt" and
"fmt [fmt.test]"
The query "pattern=string" causes "string" to be passed directly to
the underlying build tool. In most cases this is unnecessary, but an
application can use Load("pattern=" + x) as an escaping mechanism to
ensure that x is not interpreted as a query operator if it contains
'='
All other query operators are reserved for future use and currently
cause Load to report an error
Note that one pattern can match multiple packages and that a package
might be matched by multiple patterns: in general it is not possible
to determine which packages correspond to which patterns.
func (*GoParser) IterateInterfaces ¶
func (p *GoParser) IterateInterfaces(callback InterfacesIterator, optionalLogger ...LoggerCLI) error
IterateInterfaces will iterate only over the interfaces that are defined inside the parsed go code
func (*GoParser) IterateStructs ¶
func (p *GoParser) IterateStructs(callback StructsIterator, optionalLogger ...LoggerCLI) error
IterateStructs will iterate only over the structs that are defined inside the parsed go code