Documentation
¶
Index ¶
- func ChangePkgName(code string, pkgname string) string
- func CodeStyleType(typeString string) string
- func Format(filename string, src interface{}, opt *Options) ([]byte, error)
- func FormatFile(filename string, content []byte, opt *Options) error
- func MkdirAll(path string, perm ...os.FileMode) error
- func PkgName(filenameOrDirectory string, src interface{}) (string, error)
- func ReadSource(filename string, src interface{}) ([]byte, error)
- func ReadSourceBytes(src interface{}) ([]byte, error)
- func ReplaceFile(fset *token.FileSet, node ast.Node, newCode string) error
- func RewriteFile(name string, fn func(content []byte) (newContent []byte, err error)) error
- func WriteFile(filename string, data []byte, perm ...os.FileMode) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangePkgName ¶
ChangePkgName change package name of the code and return the new code.
func CodeStyleType ¶
CodeStyleType converts *a/b/c.T to *c.T
func Format ¶
Format formats and adjusts imports for the provided file. If opt is nil the defaults are used.
Note that filename's directory influences which imports can be chosen, so it is important that filename be accurate. To process data “as if” it were in filename, pass the data as a non-nil src.
func FormatFile ¶
FormatFile formats and adjusts imports for the provided file, and rewrites it. NOTE:
If content is not empty, use it as new content, format it and overwriting the original file content.
func MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil. If perm is empty, default use 0755.
func PkgName ¶
PkgName get the package name of the code, file or directory. NOTE:
If src==nil, find the package name from the file or directory specified by 'filenameOrDirectory'; If src!=nil, find the package name from the code represented by 'src'.
func ReadSource ¶
func ReadSourceBytes ¶
func ReplaceFile ¶
ReplaceFile replaces the bytes selected by [start, end] with the new content.
func RewriteFile ¶
RewriteFile rewrite file.
Types ¶
type Options ¶
Options specifies options for processing files.
type Options struct { Fragment bool // Accept fragment of a source file (no package statement) AllErrors bool // Report all errors (not just the first 10 on different lines) Comments bool // Print comments (true if nil *Options provided) TabIndent bool // Use tabs for indent (true if nil *Options provided) TabWidth int // Tab width (8 if nil *Options provided) FormatOnly bool // Disable the insertion and deletion of imports }