Documentation ¶
Index ¶
- func FormatCodeFromParser(p *Parser, dst io.Writer, opts ...FormatOptions) error
- func FormatCodeFromSource(src []byte) ([]byte, error)
- func GetGoModuleNameFromDir(dir string) string
- func GoBin() string
- func GoInstall(repository string) error
- func GoModCachePath() string
- func GoModFilePath() string
- func GoModName() string
- func GoModPath() string
- func GoPath() string
- func GoProxy() string
- func GoRoot() string
- func GoVersion() string
- func ImportPathForDir(dir string) (res string)
- func IsGO111ModuleOn() bool
- func IsGoFile(path string) bool
- func IsGoModProject() bool
- func IsInvalidPackageName(pkg string) bool
- func IsValidPackageName(pkg string) bool
- func NameForDir(dir string) string
- func NormalizeVendor(pkg string) string
- func QualifyPackagePath(importPath string) string
- func RefPathToGoModPath(path string) string
- func RemoveUnusedImports(parser *Parser)
- func SanitizePackageName(pkg string) string
- func SortImports(parser *Parser)
- type FormatOptions
- func WithAllErrors(allErrors bool) FormatOptions
- func WithComments(comments bool) FormatOptions
- func WithFormatOnly(formatOnly bool) FormatOptions
- func WithFragment(fragment bool) FormatOptions
- func WithOptions(opts imports.Options) FormatOptions
- func WithTabIndent(tabIndent bool) FormatOptions
- func WithTabWidth(tabWidth int) FormatOptions
- type ImportSpec
- type Node
- type Parser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatCodeFromParser ¶
func FormatCodeFromParser(p *Parser, dst io.Writer, opts ...FormatOptions) error
FormatCodeFromParser formats the given source code from a parser. and writes the result to the given writer. an error is returned if formatting fails.
func FormatCodeFromSource ¶
FormatCodeFromSource formats the given source code.
func GetGoModuleNameFromDir ¶
func GoInstall ¶
GoInstall is a functionx that installs a package from a remote repository. returns an error if something goes wrong.
func GoModCachePath ¶
func GoModCachePath() string
GoModCachePath returns the path of Go module cache.
func GoModFilePath ¶
func GoModFilePath() string
GoModFilePath returns the full path to the go.mod file for the current project.
func GoModName ¶
func GoModName() string
GoModName returns the name of the current project without version.
func GoModPath ¶
func GoModPath() string
GoModPath returns the directory path of the go.mod file for the current project.
func GoProxy ¶
func GoProxy() string
GoProxy returns the proxy setting for go. if not set, return a default proxy setting: "https://goproxy.cn,direct".
func ImportPathForDir ¶
ImportPathForDir takes a path and returns a golang import path for the package taken from "github.com/99designs/gqlgen/internal/codegen/imports.go"
func IsGO111ModuleOn ¶
func IsGO111ModuleOn() bool
IsGO111ModuleOn returns true if go111module is set to on.
func IsGoModProject ¶
func IsGoModProject() bool
IsGoModProject returns true if the current project is a Go module project.
func IsInvalidPackageName ¶
IsInvalidPackageName returns true if the package name is invalid.
func IsValidPackageName ¶
IsValidPackageName returns true if the package name is valid.
func NameForDir ¶
NameForDir returns the name of the package for the given directory. Taken from "github.com/99designs/gqlgen/internal/codegen/imports.go"
func NormalizeVendor ¶
NormalizeVendor takes a qualified package path and turns it into normal one. eg . github.com/foo/vendor/github.com/aesoper101/go-utils becomes github.com/aesoper101/go-utils Taken from "github.com/99designs/gqlgen/internal/codegen/utils.go"
func QualifyPackagePath ¶
QualifyPackagePath takes an import and fully qualifies it with a vendor dir, if one is required. eg . github.com/aesoper101/go-utils becomes github.com/foo/vendor/github.com/aesoper101/go-utils
x/tools/packages only supports 'qualified package paths' so this will need to be done prior to calling it See https://github.com/golang/go/issues/30289 Taken from "github.com/99designs/gqlgen/internal/codegen/util.go"
func RefPathToGoModPath ¶
RefPathToGoModPath returns the relative path to the go.mod file for the given path.
func RemoveUnusedImports ¶
func RemoveUnusedImports(parser *Parser)
RemoveUnusedImports removes unused imports from the file.
func SanitizePackageName ¶
SanitizePackageName replaces invalid package name characters with '_'. Taken from "github.com/99designs/gqlgen/internal/codegen/utils.go"
Types ¶
type FormatOptions ¶
func WithAllErrors ¶
func WithAllErrors(allErrors bool) FormatOptions
func WithComments ¶
func WithComments(comments bool) FormatOptions
func WithFormatOnly ¶
func WithFormatOnly(formatOnly bool) FormatOptions
func WithFragment ¶
func WithFragment(fragment bool) FormatOptions
func WithOptions ¶
func WithOptions(opts imports.Options) FormatOptions
func WithTabIndent ¶
func WithTabIndent(tabIndent bool) FormatOptions
func WithTabWidth ¶
func WithTabWidth(tabWidth int) FormatOptions
type ImportSpec ¶
type ImportSpec struct { // Name of imported package if needed. e.g "utils" or "" if not needed. Name string // Go import path of package. e.g. "github.com/aesoper101/go-utils" Path string }
ImportSpec represents a single import spec. Taken from "goa.design/goa/v3/codegen/import.go"
func CollectImports ¶
func CollectImports(parser *Parser) []*ImportSpec
CollectImports returns all the imports by Parser
func NewImport ¶
func NewImport(name, path string) *ImportSpec
NewImport creates an import spec. Taken from "goa.design/goa/v3/codegen/import.go"
func SimpleImport ¶
func SimpleImport(path string) *ImportSpec
SimpleImport creates an import with no explicit path component. Taken from "goa.design/goa/v3/codegen/import.go"
func (*ImportSpec) Code ¶
func (s *ImportSpec) Code() string
Code returns the Go import statement for the ImportSpec. Taken from "goa.design/goa/v3/codegen/import.go"
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func MustParser ¶
MustParser is a convenience wrapper for NewParser that panics if NewParser returns an error.
func NewParser ¶
NewParser returns a new Parser. If testSrc is not nil, it parses source code from testSrc and returns the resulting Parser. If testSrc is nil, it parses source code from the contents of filename and returns the resulting Parser. at least one of testSrc and filename must not be nil. testSrc may be a string, a byte slice, or an io.Reader. If an error is returned, parsing fails and the returned Parser is nil.