Learn to double your development efficiency with these Goland tips

hi, everyone, my name is hhf.

"Goland these practical skills, you may not yet! " Introduces some useful skills in daily development. This article goes on to introduce some other useful techniques.

custom structure tag

A very useful feature of Goland: tag auto-completion. In a struct structure, you can type json or xml after the field type to add markup to the structure.

Goland's default json is in the glideline format. But sometimes there are special needs.

For example: the company has uniform requirements for the fields of the return value of the interface. In most cases, the return value in json format is mostly below the sliding line, but there are also camel case format. If you encounter this situation, how to adjust the tag auto-completion?

There is also a situation where some companies will customize the tag field, and these fields are definitely not built-in in goland. If you encounter such a situation, and also want the tag to be automatically completed, what should you do?

Code to automatically sync remote server

Goland is a more comfortable thing to see the code, after all, Goland provides a lot of functions, such as: Find Usages, view interface implementation, Debug and so on.

For various reasons, in many cases we need to push the code to a remote server to compile the code. Through packaging or git synchronization, it is always a little troublesome. Is there a way to modify the code locally and automatically synchronize the code to the remote?

Goland provides exactly this functionality.

go list -m fails

This is usually caused by a failure to download go.mod dependencies. Just set Goland's Goproxy.

code folding

My obsessive-compulsive disorder is one of the more serious ones. I especially can't accept code being folded.

There are three places where Goland folds code: import folding, error folding, and string format folding. How to close them?

Project directory automatically selects open files

Looking at the source code, we need to know the directory where the currently opened file is located, which is helpful for understanding the entire code process. By default, Goland does not select open files in the Project directory. How to set it up?

go tool recommendation

  • golangci-lint [1] 一款集成了 Go 的所有工具链的工具,极好用,可以集成到 goland 中
  • gofumpt [2] 自动将格式化代码替换的工具,用过的都说好,可以集成到 goland 中
  • json to go [3] 一款 chrome 插件,自动将 json 或者 mysql 语句转成对应的 struct,省时省力的神器

欢迎关注公众号。更多学习学习资料分享,关注公众号回复指令:

  • 回复 0,获取 《Go 面经》
  • 回复 1,获取 《Go 源码流程图》

参考资料

[1]

golangci-lint: https://github.com/golangci/golangci-lint

[2]

gofumpt: https://github.com/mvdan/gofumpt

[3]

json to go: https://chrome.google.com/webstore/detail/json-to-go/adibamafcjbolhaaccnhdebpncglaohb

本文分享自微信公众号 - HHFCodeRv(hhfcodearts)。
如有侵权,请联系 [email protected] 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/3162806/blog/5188295