GoLand practical skills

GoLand practical skills

If you want to do your job well, you must first sharpen your tools. Adjusting GoLand to suit your own habits can also save a lot of time. This article mainly records some commonly used configuration content.

1. Code forward and backward function

When viewing code, you often jump between multiple files or functions. If you want to go back to the previous viewing position, you can use this function

This column is not displayed by default and needs to be configured. The configuration location is: View->Appearance->Toolbar

2. Automatic code generation

2.1 Unit test code

Go code needs to write unit tests, but the framework of unit tests is fixed. If it is a waste of time to write the shelf every time, GoLand provides the function of automatically generating unit tests. In Code->Generate, you can choose which test codes to generate according to your needs.

2.2 Function code

Some codes just have different names, but the structure is exactly the same, and there is no need to write and copy each time for this kind of code. We can use the code template function. Configure in GoLang->Perferances->Editor->Live Templates->Go.

In the configuration process, you need to name (for calling and use), write description, and write template content. Variables need to be set in the template. Variables can be configured through Edit variables.

func $ FUNC $ (ctx context.Context) (resp *$BASE$.$FUNC$Response, err error) { req := &$BASE$.$FUNC$Request{ } resp, err = $CLIENT$.$FUNC$(ctx, req) if err != nil { logs.CtxError(ctx, "[rpc] $CLIENT$ $FUNC$ err: %+v" , err) return nil , err } logs.CtxInfoKvs(ctx, "[rpc] $CLIENT$ $FUNC$ resp:%v" , resp) if resp.BaseResp.StatusCode != 0 { logs.CtxError(ctx, "[rpc] $CLIENT$ $FUNC$ status error: %+v" , resp.BaseResp) err = fmt.Errorf(resp.BaseResp.StatusMessage) return nil , err } return resp, nil } Copy code

After the configuration is complete, as long as there is content in the pasteboard, the code can be automatically generated. For example, the pasteboard content is Show, and the result after calling rpccreate:

func Show (ctx context.Context) (resp *baseinfo.ShowResponse, err error) { req := &baseinfo.ShowRequest{ } resp, err = .Show(ctx, req) if err != nil { logs.CtxError(ctx, "[rpc] Show err: %+v" , err) return nil , err } logs.CtxInfoKvs(ctx, "[rpc] Show resp:%v" , resp) if resp.BaseResp.StatusCode != 0 { logs.CtxError(ctx, "[rpc] Show status error: %+v" , resp.BaseResp) err = fmt.Errorf(resp.BaseResp.StatusMessage) return nil , err } return resp, nil } Copy code

3. Annotation

It is a good habit to write code and comment. Let me talk about how to easily add file comments and function comments.

3.1 New file comment

It is relatively simple to add comments to new files, just modify Go File in GoLang->Perferances->Editor->File and Code Templates.

3.2 Function annotation

GoLand itself does not support function annotation very well, but fortunately there are many good plug-ins on the market. Goanno is recommended here, which can be installed in GoLang->Perferances->Plugins

After the installation is complete, use the shortcut key control + commond +/above the function to automatically generate function comments, such as:

/** * @Author: *** * @Description: * @param a * @return b */ func test (a int ) (b int ) { return 0 } Copy code

If you are not satisfied with the automatically generated content, you can edit it and change the location to Tools->Goanno Setting:


  1. blog.csdn.net/u010243725/...
  2. www.jianshu.com/p/964e5b0c4...
  3. blog.csdn.net/wzbwzh/arti...

At last

If you like my article, you can follow my official account (Programmer Mala Tang)

My personal blog is: shidawuhen.github.io/

Review of previous articles:


  1. Byte Beat | Douyin e-commerce server technical positions are waiting
  2. ByteDance Recruitment Topic

Design Patterns

  1. Go design pattern (6)-singleton pattern
  2. Go design pattern (5)-class diagram notation
  3. Go design pattern (4)-code writing optimization
  4. Go design pattern (4)-code writing
  5. Go design pattern (3)-design principles
  6. Go design pattern (2)-object-oriented analysis and design
  7. Go design pattern (1)-syntax


  1. Generate of Go tools
  2. Go singleton implementation scheme
  3. Go channel implementation principle
  4. Go timer implementation principle
  5. Beego framework usage
  6. Golang source code bug tracking
  7. Gin framework concise version
  8. Gin source code analysis


  1. General issues of payment access
  2. Current limit realization 2
  3. Spike system
  4. Distributed system and consensus protocol
  5. Service framework and registry of microservices
  6. Talking about microservices
  7. Current limit realization 1
  8. Detailed explanation of CDN request process
  9. Common caching techniques
  10. How to efficiently connect with third-party payment
  11. Algorithm summary


  1. MySQL Development Specification
  2. Redis implements distributed locks
  3. The realization principle of transaction atomicity, consistency and durability
  4. A brief analysis of InnoDB locks and transactions

The internet

  1. HTTP2.0 basic tutorial
  2. HTTPS configuration combat
  3. HTTPS connection process
  4. TCP performance optimization


  1. Automatically generate go struct according to mysql table
  2. Markdown editor recommendation-typora

study notes

  1. in principle
  2. Zi Zhi Tong Jian
  3. Agile revolution
  4. How to exercise your memory
  5. Simple logic-after reading
  6. Hot air-after reading
  7. The Analects-Thoughts after Reading
  8. Sun Tzu Art of War-Thoughts after reading


  1. To mobilize all forces for victory in the War of Resistance
  2. Against liberalism
  3. Practice theory
  4. Evaluate one's own standards
  5. Server team holiday duty plan
  6. Project process management
  7. Some views on project management
  8. Some thoughts on product managers
  9. Thoughts on the career development of programmers
  10. Thinking about code review