golangx

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

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

func FormatCodeFromSource(src []byte) ([]byte, error)

FormatCodeFromSource formats the given source code.

func GetGoModuleNameFromDir

func GetGoModuleNameFromDir(dir string) string

func GoBin

func GoBin() string

GoBin returns the path to the go binary.

func GoInstall

func GoInstall(repository string) error

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 GoPath

func GoPath() string

GoPath returns the GOPATH.

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 GoRoot

func GoRoot() string

GoRoot returns the GOROOT.

func GoVersion

func GoVersion() string

GoVersion returns the go version.

func ImportPathForDir

func ImportPathForDir(dir string) (res string)

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 IsGoFile

func IsGoFile(path string) bool

IsGoFile checks if the given file is a go file

func IsGoModProject

func IsGoModProject() bool

IsGoModProject returns true if the current project is a Go module project.

func IsInvalidPackageName

func IsInvalidPackageName(pkg string) bool

IsInvalidPackageName returns true if the package name is invalid.

func IsValidPackageName

func IsValidPackageName(pkg string) bool

IsValidPackageName returns true if the package name is valid.

func NameForDir

func NameForDir(dir string) string

NameForDir returns the name of the package for the given directory. Taken from "github.com/99designs/gqlgen/internal/codegen/imports.go"

func NormalizeVendor

func NormalizeVendor(pkg string) string

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

func QualifyPackagePath(importPath string) string

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

func RefPathToGoModPath(path string) string

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

func SanitizePackageName(pkg string) string

SanitizePackageName replaces invalid package name characters with '_'. Taken from "github.com/99designs/gqlgen/internal/codegen/utils.go"

func SortImports

func SortImports(parser *Parser)

SortImports sorts the imports in the file.

Types

type FormatOptions

type FormatOptions func(opt *imports.Options)

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 Node

type Node struct {
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func MustParser

func MustParser(p *Parser, err error) *Parser

MustParser is a convenience wrapper for NewParser that panics if NewParser returns an error.

func NewParser

func NewParser(filename string, src any, mode parser.Mode) (*Parser, error)

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.

func (*Parser) File

func (p *Parser) File() *ast.File

File returns the parsed File.

func (*Parser) FileSet

func (p *Parser) FileSet() *token.FileSet

FileSet returns the FileSet used to parse the source code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL