go 格式化

1. 对已有代码format

for file infind -L *.go .; ``do gofmt -w $file; done

2. 添加hook,在提交代码之前,提醒代码格式化问题

  • 将https://golang.org/misc/git/pre-commit保存成文件, 文件名pre-commit, 放置目录 .git/hooks, 并是的文件pre-common文件具有可执行权限即可。

3. 添加hook到全局的git hook里面

  • 此方法会覆盖项目的hook目录,所以设置去请清晰设置原理,详情见:https://git-scm.com/docs/git-config.html#git-config-corehooksPath
  • git config --global core.hooksPath /Users/name/.git/hooks
  • 将https://golang.org/misc/git/pre-commit保存成文件, 文件名pre-commit, 放置目录 /Users/name/.git/hooks, 并是的文件pre-common文件具有可执行权限即可。
  • 这样设置完毕后,提交所有项目之前会检查,以.go 结尾的文件,是否符合gofmt

你可能感兴趣的:(go 格式化)