Documentation
¶
Index ¶
- func CleanCodeImportNewlines(source []byte) ([]byte, error)
- func CleanFileImportNewlines(path string) error
- func FormatBytes(code []byte) ([]byte, error)
- func FormatBytesWithOptions(code []byte, options *Options) ([]byte, error)
- func FormatCode(code string) (string, error)
- func FormatCodeWithOptions(code string, options *Options) (string, error)
- func FormatFile(path string) error
- func FormatFileWithOptions(path string, options *Options) error
- func FormatRoot(root string) error
- func FormatRootWithOptions(root string, options *RootOptions) error
- func NewImportsOptions() *imports.Options
- type Options
- type RootOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanCodeImportNewlines ¶
CleanCodeImportNewlines processes the source code and condenses consecutive empty lines in the import section to a single newline. CleanCodeImportNewlines 处理源代码,并将导入部分中的连续空行压缩为单一的换行符。
func CleanFileImportNewlines ¶
CleanFileImportNewlines reads a Go source file, condenses the import section by removing consecutive empty lines, and writes the result back to the file. CleanFileImportNewlines 读取 Go 源代码文件,压缩导入部分 通过去除连续的空行并将结果写回文件。
func FormatBytes ¶
FormatBytes formats Go source code from a byte slice. FormatBytes 格式化golang的源代码
func FormatBytesWithOptions ¶
FormatBytesWithOptions formats Go source code from a byte slice. Even if an error occurs during formatting, it returns the intermediate code. FormatBytesWithOptions 格式化 Go 的源代码(以字节切片形式提供)。 即使在格式化期间发生错误,也会返回中间结果代码。
func FormatCode ¶
FormatCode formats Go source code from a string. FormatCode 格式化源代码字符串
func FormatCodeWithOptions ¶
FormatCodeWithOptions formats Go source code from a string. Even if an error occurs during formatting, it returns the intermediate code as a string. FormatCodeWithOptions 格式化 Go 的源代码(以字符串形式提供)。 即使在格式化期间发生错误,也会返回中间结果代码(字符串形式)。
func FormatFile ¶
FormatFile formats a Go source code file at the given path. FormatFile 格式化源代码文件
func FormatFileWithOptions ¶
FormatFileWithOptions formats a Go source code file. It reads the file, formats it, and writes back the result if changes are made. FormatFileWithOptions 格式化一个 Go 源代码文件。 它会读取文件内容,进行格式化,如果内容有变化则写回结果。
func FormatRoot ¶
FormatRoot formats all Go source files in the specified root directory and its subdirectories. FormatRoot 格式化整个目录以及其子目录下的所有go文件
func FormatRootWithOptions ¶
func FormatRootWithOptions(root string, options *RootOptions) error
FormatRootWithOptions formats all Go files in a directory and its subdirectories. It recursively processes each directory and applies the provided options. FormatRootWithOptions 格式化指定目录及其子目录下的所有 Go 文件。 它递归处理每个目录,并根据提供的选项进行格式化。
func NewImportsOptions ¶
NewImportsOptions returns a new imports.Options with default settings. NewImportsOptions 返回一个具有默认设置的 imports.Options。
Types ¶
type Options ¶
type Options struct { ImportsOptions *imports.Options // Options for formatting imports // 导入格式化的选项 CondenseImport bool // Whether to condense imports by removing empty lines // 是否压缩导入部分,去除空行 IsFormatImport bool // Whether to format import statements // 是否格式化导入语句 }
Options holds configuration options for imports formatting. Options 结构体保存了导入格式化的配置选项。
func NewOptions ¶
func NewOptions() *Options
NewOptions creates and returns a new Options instance with default values. NewOptions 创建并返回一个带有默认值的 Options 实例。
type RootOptions ¶
type RootOptions struct { FileOptions *Options // File formatting options // 文件格式化选项 FilterRoot func(depth int, path string, name string) bool // Filter to format only directories that match certain criteria // 用于过滤目录名/路径的条件,只有符合条件的目录才会被格式化 FilterFile func(depth int, path string, name string) bool // Filter to format only files that match certain criteria // 用于过滤文件名/路径的条件,只有符合条件的文件才会被格式化 FileHasSuffixes []string // Suffixes of files to be formatted // 要格式化的文件后缀列表 SkipHiddenDepth int // Depth level to skip hidden directories (e.g., .git, .idea) // 在多少层深度内跳过隐藏目录(例如 .git,.idea) }
RootOptions holds configuration options for the root directory formatting. RootOptions 结构体保存了根目录格式化的配置选项。
func NewRootOptions ¶
func NewRootOptions() *RootOptions
NewRootOptions creates and returns a new RootOptions instance with default values. NewRootOptions 创建并返回一个带有默认值的 RootOptions 实例。