Go - go fmt用法

Posted 王万林 Ben

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Go - go fmt用法相关的知识,希望对你有一定的参考价值。

Go - go fmt用法

go fmt介绍

usage: go fmt [-n] [-x] [packages]

Fmt runs the command 'gofmt -l -w' on the packages named
by the import paths. It prints the names of the files that are modified.

For more about gofmt, see 'go doc cmd/gofmt'.
For more about specifying packages, see 'go help packages'.

The -n flag prints commands that would be executed.
The -x flag prints commands as they are executed.

The -mod flag's value sets which module download mode
to use: readonly or vendor. See 'go help modules' for more.

To run gofmt with specific options, run gofmt itself.

See also: go fix, go vet.

根据介绍,got fmt可以对代码格式进行标准化调整。

用法

╭─ben at MacBook Pro in ~/go/src/github.com/goinaction/code/chapter3/tmp on master✘✘✘ 2021/08/29 - 15:34:40
╰─⠠⠵ cat go_fmt.go  
package main

import "fmt"

func main() {
	if err != nil { return err }
}
╭─ben at MacBook Pro in ~/go/src/github.com/goinaction/code/chapter3/tmp on master✘✘✘ 2021/08/29 - 15:34:45
╰─⠠⠵ go fmt go_fmt.go 
go_fmt.go
╭─ben at MacBook Pro in ~/go/src/github.com/goinaction/code/chapter3/tmp on master✘✘✘ 2021/08/29 - 15:34:48
╰─⠠⠵ cat go_fmt.go 
package main

import "fmt"

func main() {
	if err != nil {
		return err
	}
}

以上是关于Go - go fmt用法的主要内容,如果未能解决你的问题,请参考以下文章

Go 中 fmt.Println() 和 println() 的区别

Go-内置函数之appendrecover用法

go——选择和循环

go——选择和循环

go语音基础之goto的用法

go中浮点型用法总结