Skip to content

Commit

Permalink
增加代码风格审查
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomeng79 committed Oct 9, 2019
1 parent ea1957b commit bc7f738
Show file tree
Hide file tree
Showing 102 changed files with 3,856 additions and 5,437 deletions.
131 changes: 131 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
linters-settings:
govet:
check-shadowing: true
settings:
printf:
funcs:
- (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
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
- github.com/sirupsen/logrus
packages-with-error-messages:
github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
misspell:
locale: US
ignore-words:
- someword
lll:
line-length: 260
goimports:
local-prefixes: github.com/xiaomeng79/istio-micro
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- wrapperFunc
- commentedOutCode
- dupImport # https://github.com/go-critic/go-critic/issues/845
funlen:
lines: 100
statements: 50
gosec:

linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
# - dupl
- errcheck
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- errcheck
- unparam
- unused
- varcheck
- whitespace

# don't enable:
# - gochecknoglobals
# - gocognit
# - godox
# - maligned
# - prealloc

issues:
exclude:
- G108
# # Exclude some linters from running on tests files.
# - path: srv/account/proto
## - linters:
## - lll
## source: "^//go:generate "
# exclude-use-default: false
max-same-issues: 5

run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 1m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

skip-dirs:
- docs/
skip-files:
- ".*\\.my\\.go$"

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.19.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ vendor :
@echo "结束vendor"

.PHONY : test
test : vendor check
test : vendor
@echo "代码测试[覆盖率]"
@go test -mod=vendor -race -cover -coverprofile=coverage.txt -covermode=atomic ./...

Expand Down Expand Up @@ -114,6 +114,11 @@ k8sconfig :

@echo "配置k8s"
@chmod +x ./scripts/k8sconf.sh && ./scripts/k8sconf.sh
# 代码风格检查
.PHONY : lint
lint :
@golangci-lint run -v ./...


#pprof性能分析
.PHONY : pprofon
Expand Down
71 changes: 30 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
|metric|监控报警(influxdb+grafana)|
|docker-compose|容器部署|
|istio|流量控制,服务降级,跟踪,服务发现,分流等|
|golangci-lint|代码风格一致性,静态检查|

### 模块

Expand All @@ -43,11 +44,12 @@
1. 安装依赖

- 系统依赖安装
1. git >= 2.17
2. wget
3. make
4. unzip
5. tar
- git >= 2.17
- wget
- make
- unzip
- tar
- go >= 1.13

```bash
#ubuntu系统安装
Expand All @@ -70,7 +72,7 @@ git clone https://github.com/xiaomeng79/istio-micro.git
cd istio-micro && git pull --all
make ver
source ~/.profile
make install
make install sample
```

4. 编译代码
Expand Down Expand Up @@ -157,48 +159,36 @@ curl -X POST \

Makefile

```go
//格式化代码
```go// 格式化代码
make fmt

//vendor
// vendor
make vendor

//代码测试,代码检查
// 代码测试,代码检查
make test

//编译单个服务,同时添加版本信息
// 编译单个服务,同时添加版本信息
make build type=srv project=user

//编译全部服务
// 编译全部服务
make allbuild

//protobuf
// protobuf
make proto

//生成单个dockerfile
// 生成单个dockerfile
make dockerfile type=srv project=user

//生成全部dockerfile
// 生成全部dockerfile
make alldockerfile

//docker-compose部署
// docker-compose部署
make compose up

//打包静态文件
// 打包静态文件
make builddata

//提交代码到远程仓库
// 提交代码到远程仓库
make push msg="提交信息"

//开启代码性能分析(如type为api,project为frontend)
// 开启代码性能分析(如type为api,project为frontend)
make pprofon type=api project=frontend

//关闭代码性能分析(如type为api,project为frontend)
// 关闭代码性能分析(如type为api,project为frontend)
make pprofoff type=api project=frontend

// 清空编译
// 清空编译
make clean
// 代码风格检查
make lint
```

#### 命令行
Expand Down Expand Up @@ -234,15 +224,14 @@ http://127.0.0.1:3000 账号密码:admin
程序运行的时候会生成进程id(默认在运行目录下server.pid),通过kill命令发送一个信号(默认10)到程序**开启**性能分析,kill命令发送一个信号(默认12)到程序**关闭**性能分析


```shell
//比如进程id:3125
kill -10 3125 //开启代码性能分析
```shell// 比如进程id:3125
kill -10 3125// 开启代码性能分析
go tool pprof http://127.0.0.1:38888/debug/pprof/goroutine //goroutine
go tool pprof http://127.0.0.1:38888/debug/pprof/heap //heap
go tool pprof http://127.0.0.1:38888/debug/pprof/profile //profile
go tool pprof http://127.0.0.1:38888/debug/pprof/goroutine// goroutine
go tool pprof http://127.0.0.1:38888/debug/pprof/heap// heap
go tool pprof http://127.0.0.1:38888/debug/pprof/profile// profile
kill -12 3125 //关闭代码性能分析
kill -12 3125// 关闭代码性能分析
```

#### 生成文档(swagger)
Expand Down
Loading

0 comments on commit bc7f738

Please sign in to comment.