This is the 17th day of my participation in Gwen Challenge

Code specification

Why you need a specification

Java style code: this and package

package ConcurrentFuture
type xx struct{... }func (this *xxx) method(a){... }Copy the code

The style of Go should be: more concise

package concurrentfuture
type xx struct{... }func (t *xxx) method(a){... }Copy the code

Specification of Go – naming

  • Package style:

    • Singleflight. Go’s entries are all lowercase, with no underscores or uppercase letters. If you want to convey too much meaning, Go suggests using a hierarchical directory.
    • If you have a byte-type conversion package that contains the byte-type conversion method, the best thing to sign up for is byteconV. Reason: The package name should not be plural.
  • variable

    • HTTPRequst, xmlHTTPRquest. Must be all uppercase or all lowercase for acronyms (e.g., either XML or XML)
    • Error variables usually start with err/ err
  • Error content

    • Errors. New(“not enough image data”). Error data will always be passed, so no caps and no punctuation. But if it’s a legitimate noun like HTTP you can capitalize it.
    • The rules for printing logs don’t apply, because logs are printed separately, case insensitive, and error messages tend to be printed along with other things.

Linter practice

Use the Linter tool to unify/check everyone’s code style.

The official Go Linter has fallen into disrepair and is often not very accurate.

Go FMT, go vet, go linter

There were so many that an aggregator, Golangci-Lint, came out.

conclusion

Q: Why can Golang-Lint aggregate so many Linters?

A: Because these Linters are essentially the same parser. In golang/tools/tree/master/go/analysis

One more thing:

How do you know about go Run? Go breaks up the code into pieces it can understand. This step is called tokenize (such as package main, which breaks up the two words package and main) and then string them together according to syntax rules. This step is called parse. Form ast (Abstract syntax tree) and save it.

Check out this article at www.01happy.com/golang-ast-…