前置环境
- 安装Go (自行百度)
- 安装Sublime Text (自行百度)
Sublime Text安装Go插件
- Godef
- Gofmt
- Golang Build
- GoSublime (只能通过源码安装,直接下载源码,然后放到sublime插件目录下会自动安装, 源码地址: https://github.com/DisposaBoy/GoSublime 插件目录可通过Preferences --> Browse Packages... 打开)
- SublimeLinter
- SublimeLinter-golangcilint
上面下载的GoSumlime 插件 源码有个坑
打开下载的GoSumlime源码目录,在src目录下新建一个 margo
目录,然后从src/margo.sh/extension-example
目录拷贝一份 extension-example.go
文件到新建的margo目录下即可
安装 golangci-lint
地址: https://github.com/golangci/golangci-lint
直接下载编译好的文件,然后解压放到 GOPATH 的bin 目录下即可
设置 (Preferences --> Package Setttings)
- Golang config
{
"PATH": "/Users/my/goroot/bin", // GOROOT
"GOPATH": "/Users/lan/go" // GOPATH
}
- GoSublime
{
"env":
{
"GOROOT": "xxx", // GOROOT
"GOPATH": "xxx", // GOPATH
"PATH": "$HOME/go/bin:$GOROOT/bin:$PATH"
},
"gscomplete_enabled": true,
"fmt_enabled": true,
"autocomplete_suggest_imports": true,
"calltips": true,
"fmt_cmd": ["goimports"],
}
- SublimeLinter
{
"debug": true,
"paths":{
"osx":[
"$GOROOT/bin:$PATH", //GOROOT 替换为实际绝对路径
"$GOPATH" // GOPATH 替换为实际绝对路径
]
},
"linters":{
"golangcilint":{
"env":{
"PATH":"$GOPATH/bin:$GOROOT/bin" // GOPATH, GOROOT 替换为绝对路径
},
"args": ["-c", "/xxx/.golangci.yml"] // 指定一个golangci-lint 配置文件,否则检查无意义
}
}
}
至此就可以编写运行go文件了
保存代码会自动检查代码规范,具体错误可以通过
ctr + ~
查看
运行代码可以通过cmd + b
运行
推荐几个sublime text的插件
SideBarEnhancements -- 目录增强工具
Terminal -- 终端
.golangci.yml 文件(也可以参考官网介绍去写: https://golangci-lint.run/usage/configuration/)
# options for analysis running
run:
timeout: 30m
skip-dirs-use-default: false
skip-files:
- ".*_pie.go"
- ".*autogen.go"
- ".*errcode.go"
modules-download-mode: mod
allow-parallel-runners: true
concurrency: 1
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true
linters-settings:
bidichk:
left-to-right-embedding: true
right-to-left-embedding: true
pop-directional-formatting: true
left-to-right-override: true
right-to-left-override: true
left-to-right-isolate: true
right-to-left-isolate: true
first-strong-isolate: true
pop-directional-isolate: true
dogsled:
max-blank-identifiers: 2
errcheck:
check-type-assertions: false
check-blank: true
disable-default-exclusions: true
ignore: fmt:.*,io/ioutil:^Read.*/strconv.Parse*
exclude-functions:
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
- (*bytes.Buffer).WriteString
- (*bytes.Buffer).Write
errorlint:
errorf: true
asserts: false
comparison: false
exhaustive:
check-generated: false
default-signifies-exhaustive: false
package-scope-only: false
ignore-enum-members: ".+Nil"
gocyclo:
min-complexity: 20
godox:
keywords:
- REVIEW
- OPTIMIZE
- HACK
gofmt:
simplify: false
gosec:
includes:
- G103
- G104
- G106
- G108
- G109
- G110
- G201
- G202
- G203
- G301
- G302
- G303
- G304
- G305
- G307
- G401
- G402
- G403
- G601
exclude-generated: true
severity: "low"
confidence: "low"
gosimple:
go: "1.16"
checks: [ "all" ]
govet:
check-shadowing: false
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
disable-all: true
enable:
- asmdecl
- assign
- atomic
- atomicalign
- bools
- buildtag
- cgocall
- composites
- copylocks
- deepequalerrors
- errorsas
- findcall
- framepointer
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
# - nilness
- printf
- reflectvaluecompare
- shift
- sigchanyzer
- sortslice
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
# - unusedwrite
lll:
line-length: 120
tab-width: 4
misspell:
ignore-words:
- qrobot
- qwhale
- rela
nakedret:
max-func-lines: 200
nestif:
min-complexity: 6
staticcheck:
go: "1.16"
checks:
- SA1000
- SA1001
- SA1002
- SA1003
- SA1004
- SA1005
- SA1006
- SA1007
- SA1008
- SA1010
- SA1011
- SA1012
- SA1013
- SA1014
- SA1015
- SA1016
- SA1017
- SA1018
- SA1020
- SA1021
- SA1023
- SA1024
- SA1025
- SA1026
- SA1027
- SA1028
- SA1029
- SA1030
- SA2000
- SA2001
- SA2002
- SA2003
- SA3000
- SA3001
- SA4000
- SA4001
- SA4003
- SA4004
- SA4005
- SA4008
- SA4009
- SA4010
- SA4011
- SA4012
- SA4013
- SA4014
- SA4015
- SA4016
- SA4017
- SA4018
- SA4019
- SA4020
- SA4021
- SA4022
- SA4023
- SA4024
- SA4025
- SA4026
- SA4027
- SA4028
- SA4029
- SA4030
- SA4031
- SA5000
- SA5001
- SA5002
- SA5003
- SA5004
- SA5005
- SA5007
- SA5008
- SA5009
- SA5010
- SA5011
- SA5012
- SA6000
- SA6001
- SA6002
- SA6003
- SA6005
- SA9001
- SA9002
- SA9003
- SA9004
- SA9005
- SA9006
- SA9007
- SA9008
- S1000
- S1001
- S1002
- S1003
- S1004
- S1005
- S1006
- S1007
- S1008
- S1009
- S1010
- S1011
- S1012
- S1016
- S1017
- S1018
- S1019
- S1020
- S1021
- S1023
- S1024
- S1025
- S1028
- S1029
- S1030
- S1031
- S1032
- S1033
- S1034
- S1035
- S1036
- S1037
- S1038
- S1039
- S1040
- ST1000
- ST1005
- ST1006
- ST1008
- ST1011
- ST1012
- ST1013
- ST1015
- ST1016
- ST1017
- ST1018
- ST1019
- ST1020
- ST1021
- ST1022
- ST1023
- QF1001
- QF1002
- QF1003
- QF1004
- QF1005
- QF1006
- QF1007
- QF1008
- QF1009
- QF1010
- QF1011
- QF1012
stylecheck:
go: "1.16"
checks:
- SA1000
- SA1001
- SA1002
- SA1003
- SA1004
- SA1005
- SA1006
- SA1007
- SA1008
- SA1010
- SA1011
- SA1012
- SA1013
- SA1014
- SA1015
- SA1016
- SA1018
- SA1020
- SA1021
- SA1023
- SA1024
- SA1025
- SA1026
- SA1027
- SA1028
- SA1029
- SA1030
- SA2000
- SA2001
- SA2002
- SA2003
- SA3000
- SA3001
- SA4000
- SA4001
- SA4003
- SA4004
- SA4005
- SA4008
- SA4009
- SA4010
- SA4011
- SA4012
- SA4013
- SA4014
- SA4015
- SA4016
- SA4017
- SA4018
- SA4019
- SA4020
- SA4021
- SA4022
- SA4023
- SA4024
- SA4025
- SA4026
- SA4027
- SA4028
- SA4029
- SA4030
- SA4031
- SA5000
- SA5001
- SA5002
- SA5003
- SA5004
- SA5005
- SA5007
- SA5008
- SA5009
- SA5010
- SA5011
- SA5012
- SA6000
- SA6001
- SA6002
- SA6003
- SA6005
- SA9001
- SA9002
- SA9003
- SA9004
- SA9005
- SA9006
- SA9007
- SA9008
- S1000
- S1001
- S1002
- S1003
- S1004
- S1005
- S1006
- S1007
- S1008
- S1009
- S1010
- S1011
- S1012
- S1016
- S1017
- S1018
- S1019
- S1020
- S1021
- S1023
- S1024
- S1025
- S1028
- S1029
- S1030
- S1031
- S1032
- S1033
- S1034
- S1035
- S1036
- S1037
- S1038
- S1039
- S1040
- ST1000
- ST1005
- ST1006
- ST1008
- ST1011
- ST1012
- ST1013
- ST1015
- ST1016
- ST1018
- ST1019
- ST1020
- ST1021
- ST1023
- QF1001
- QF1002
- QF1003
- QF1004
- QF1005
- QF1006
- QF1007
- QF1008
- QF1009
- QF1010
- QF1011
- QF1012
dot-import-whitelist:
- fmt
initialisms:
- "ASCII"
- "CPU"
- "DNS"
- "EOF"
- "QPS"
- "RAM"
- "RPC"
- "TCP"
- "TLS"
- "TTL"
- "UDP"
- "UTF8"
- "VM"
- "XML"
- "XMPP"
- "XSRF"
- "XSS"
- "Db"
http-status-code-whitelist: [ "200", "400", "404", "500", "301", "302" ]
varnamelen:
max-distance: 5
min-name-length: 1
check-receiver: false
check-return: false
ignore-type-assert-ok: true
ignore-map-index-ok: true
ignore-chan-recv-ok: true
ignore-names:
- err
gomnd:
ignored-functions:
- 'time.*'
- 'xtime.*'
forbidigo:
exclude_godoc_examples: false
tagliatelle:
case:
rules:
json: snake
yaml: snake
xml: snake
bson: snake
avro: snake
toml: snake
nilnil:
checked-types:
- ptr
- func
- iface
- map
- chan
gocritic:
disabled-checks:
# 可能需要删除的代码
- commentedOutCode
- elseif
- rangeValCopy
- paramTypeCombine
- hugeParam
- regexpMust
- singleCaseSwitch
- stringConcatSimplify
- unnecessaryBlock
- ifElseChain
- appendCombine
- importShadow
- unnamedResult
- typeDefFirst
- appendAssign
- nestingReduce
- sloppyLen
- commentFormatting
enabled-tags:
- diagnostic
- style
- performance
- experimental
- opinionated
settings:
tooManyResultsChecker:
maxResults: 10
truncateCmp:
skipArchDependent: false
underef:
skipRecvDeref: false
unnamedResult:
checkExported: true
elseif:
skipBalanced: true
rangeValCopy:
sizeThreshold: 128
skipTestFuncs: true
linters:
disable-all: true
fast: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- depguard
- dogsled
- durationcheck
- errcheck
- errname
- errorlint
- execinquery
- exportloopref
- forbidigo
- gocritic
- godox
- goheader
- gomodguard
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- interfacebloat
- logrlint
- makezero
- misspell
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- unconvert
- unused
- usestdlibvars
- varnamelen
- wastedassign
个人博客: https://lanxy.top