Skip to content

Commit a60ea33

Browse files
committed
ci(linter): add linter
1 parent 617fdbf commit a60ea33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+428
-581
lines changed

.github/workflows/lint.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
check:
11+
timeout-minutes: 1
12+
runs-on: ubuntu-latest
13+
outputs:
14+
run_job: ${{ steps.check.outputs.run_job }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 2
20+
21+
- name: check modified files
22+
id: check
23+
run: |
24+
echo "=============== list modified files ==============="
25+
git diff --name-only HEAD^ HEAD
26+
27+
echo "========== check paths of modified files =========="
28+
git diff --name-only HEAD^ HEAD > files.txt
29+
while IFS= read -r file
30+
do
31+
echo $file
32+
if [[ $file == *.go ]]; then
33+
echo "run job"
34+
echo "::set-output name=run_job::true"
35+
break
36+
fi
37+
done < files.txt
38+
39+
lint:
40+
name: Lint
41+
needs: check
42+
if: needs.check.outputs.run_job == 'true'
43+
runs-on: ubuntu-latest
44+
env:
45+
GO_VERSION: '1.16.7'
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
with:
50+
fetch-depth: 2
51+
52+
- name: Setup go
53+
id: go
54+
uses: actions/setup-go@v2
55+
with:
56+
go-version: ${{ env.GO_VERSION }}
57+
58+
- name: Cache go
59+
uses: actions/[email protected]
60+
with:
61+
path: |
62+
~/.cache/go-build
63+
~/go/pkg/mod
64+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
65+
restore-keys: |
66+
${{ runner.os }}-go-
67+
68+
- name: Golangci lint
69+
uses: golangci/golangci-lint-action@v2
70+
with:
71+
version: v1.41.1
72+
skip-go-installation: true
73+
skip-pkg-cache: true
74+
skip-build-cache: true
75+
only-new-issues: true
76+
args: -v ./...

.golangci.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This file contains all available configuration options
2+
# with their default values.
3+
4+
# options for analysis running
5+
run:
6+
# timeout for analysis, e.g. 30s, 5m, default is 1m
7+
timeout: 5m
8+
9+
# include test files or not, default is true
10+
tests: false
11+
12+
linters:
13+
disable:
14+
- scopelint
15+
enable:
16+
- errcheck
17+
- goimports
18+
- gofmt
19+
- revive
20+
- exportloopref
21+
- prealloc
22+
- lll
23+
- staticcheck
24+
- govet
25+
- whitespace
26+
- unconvert
27+
- goconst
28+
- gocritic
29+
presets:
30+
- bugs
31+
- unused
32+
33+
linters-settings:
34+
lll:
35+
line-length: 160
36+
revive:
37+
ignore-generated-header: true
38+
rules:
39+
- name: unexported-return
40+
disabled: true
41+
42+
issues:
43+
exclude-rules:
44+
- linters:
45+
- lll
46+
source: "^//go:generate "

LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2016, Actionpay
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following disclaimer
12+
in the documentation and/or other materials provided with the distribution.
13+
14+
* Neither the name of the Actionpay nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# PostmanQ
22

3+
[![license](https://img.shields.io/github/license/halfi/postmanq?style=flat-square)](https://github.com/Halfi/postmanq/blob/main/LICENSE)
4+
[![go version](https://img.shields.io/github/go-mod/go-version/Halfi/postmanq?style=flat-square)](https://github.com/Halfi/postmanq/)
5+
[![go version](https://goreportcard.com/badge/github.com/Halfi/postmanq?style=flat-square)](https://goreportcard.com/report/github.com/Halfi/postmanq)
6+
7+
---
8+
39
PostmanQ - это высокопроизводительный почтовый сервер(MTA).
410
На сервере под управлением Ubuntu 12.04 с 8-ми ядерным процессором и 32ГБ оперативной памяти
511
PostmanQ рассылает более 300 писем в секунду.

analyser/aggregate.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package analyser
22

3-
// автор таблиц, агрегирующий отчеты по ключу, например по коду ошибки
3+
// KeyAggregateTableWriter автор таблиц, агрегирующий отчеты по ключу, например по коду ошибки
44
type KeyAggregateTableWriter struct {
55
*AbstractTableWriter
66
}
@@ -12,7 +12,7 @@ func newKeyAggregateTableWriter(fields []interface{}) TableWriter {
1212
}
1313
}
1414

15-
// записывает данные в таблицу
15+
// Show записывает данные в таблицу
1616
func (t *KeyAggregateTableWriter) Show() {
1717
t.Clean()
1818
for key, ids := range t.ids {
@@ -21,7 +21,7 @@ func (t *KeyAggregateTableWriter) Show() {
2121
t.Print()
2222
}
2323

24-
// автор таблиц, агрегирующий данные
24+
// AggregateTableWriter автор таблиц, агрегирующий данные
2525
type AggregateTableWriter struct {
2626
*AbstractTableWriter
2727
}
@@ -33,7 +33,7 @@ func newAggregateTableWriter(fields []interface{}) TableWriter {
3333
}
3434
}
3535

36-
// записывает данные в таблицу
36+
// Show записывает данные в таблицу
3737
func (a *AggregateTableWriter) Show() {
3838
a.Clean()
3939
for _, row := range a.rows {

analyser/detail.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package analyser
22

33
import (
44
"fmt"
5-
"github.com/Halfi/postmanq/common"
65
"regexp"
76
"strings"
7+
8+
"github.com/Halfi/postmanq/common"
89
)
910

1011
// автор таблиц, выводящий детализированные отчеты об ошибке

analyser/rows.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
package analyser
22

33
import (
4-
"github.com/byorty/clitable"
54
"regexp"
65
"time"
6+
7+
"github.com/byorty/clitable"
78
)
89

9-
// отчет об ошибке
10+
// Report отчет об ошибке
1011
type Report struct {
11-
// идентификатор
12+
// Id идентификатор
1213
Id int
1314

14-
// отправитель
15+
// Envelope отправитель
1516
Envelope string
1617

17-
// получатель
18+
// Recipient получатель
1819
Recipient string
1920

20-
// код ошибки
21+
// Code код ошибки
2122
Code int
2223

23-
// сообщение об ошибке
24+
// Message сообщение об ошибке
2425
Message string
2526

26-
// даты отправок
27+
// CreatedDates даты отправок
2728
CreatedDates []time.Time
2829
}
2930

30-
// записывает отчет в таблицу
31+
// Write записывает отчет в таблицу
3132
func (r Report) Write(table *clitable.Table, valueRegex *regexp.Regexp) {
3233
if valueRegex == nil ||
3334
(valueRegex != nil &&
@@ -44,10 +45,10 @@ func (r Report) Write(table *clitable.Table, valueRegex *regexp.Regexp) {
4445
}
4546
}
4647

47-
// агрегированная строка
48+
// AggregateRow агрегированная строка
4849
type AggregateRow []int
4950

50-
// записывает строку в таблицу
51+
// Write записывает строку в таблицу
5152
func (a AggregateRow) Write(table *clitable.Table, valueRegex *regexp.Regexp) {
5253
table.AddRow(a[0], a[1], a[2], a[3])
5354
}

analyser/writer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package analyser
22

33
import (
4-
"github.com/byorty/clitable"
54
"regexp"
65
"sort"
6+
7+
"github.com/byorty/clitable"
78
)
89

910
// автор таблиц

application/abstract.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
}
3131
)
3232

33-
// базовое приложение
33+
// Abstract базовое приложение
3434
type Abstract struct {
3535
// путь до конфигурационного файла
3636
configFilename string
@@ -49,7 +49,7 @@ type Abstract struct {
4949
CommonTimeout common.Timeout `yaml:"timeouts"`
5050
}
5151

52-
// проверяет валидность пути к файлу с настройками
52+
// IsValidConfigFilename проверяет валидность пути к файлу с настройками
5353
func (a *Abstract) IsValidConfigFilename(filename string) bool {
5454
return len(filename) > 0 && filename != common.ExampleConfigYaml
5555
}
@@ -84,12 +84,12 @@ func (a Abstract) GetConfigFilename() string {
8484
return a.configFilename
8585
}
8686

87-
// устанавливает путь к файлу с настройками
87+
// SetConfigFilename устанавливает путь к файлу с настройками
8888
func (a *Abstract) SetConfigFilename(configFilename string) {
8989
a.configFilename = configFilename
9090
}
9191

92-
// устанавливает канал событий приложения
92+
// SetEvents устанавливает канал событий приложения
9393
func (a *Abstract) SetEvents(events chan *common.ApplicationEvent) {
9494
a.events = events
9595
}
@@ -125,7 +125,7 @@ func (a *Abstract) SendEvents(ev *common.ApplicationEvent) bool {
125125
return true
126126
}
127127

128-
// возвращает канал завершения приложения
128+
// Done возвращает канал завершения приложения
129129
func (a *Abstract) Done() <-chan bool {
130130
return a.done
131131
}
@@ -137,33 +137,33 @@ func (a *Abstract) Close() {
137137
}
138138
}
139139

140-
// возвращает сервисы, используемые приложением
140+
// Services возвращает сервисы, используемые приложением
141141
func (a *Abstract) Services() []interface{} {
142142
return a.services
143143
}
144144

145-
// инициализирует сервисы
145+
// FireInit инициализирует сервисы
146146
func (a *Abstract) FireInit(event *common.ApplicationEvent, abstractService interface{}) {
147147
service := abstractService.(common.Service)
148148
service.OnInit(event)
149149
}
150150

151-
// инициализирует приложение
151+
// Init инициализирует приложение
152152
func (a *Abstract) Init(event *common.ApplicationEvent) {}
153153

154-
// запускает приложение
154+
// Run запускает приложение
155155
func (a *Abstract) Run() {}
156156

157-
// запускает приложение с аргументами
157+
// RunWithArgs запускает приложение с аргументами
158158
func (a *Abstract) RunWithArgs(args ...interface{}) {}
159159

160-
// запускает сервисы приложения
160+
// FireRun запускает сервисы приложения
161161
func (a *Abstract) FireRun(event *common.ApplicationEvent, abstractService interface{}) {}
162162

163-
// останавливает сервисы приложения
163+
// FireFinish останавливает сервисы приложения
164164
func (a *Abstract) FireFinish(event *common.ApplicationEvent, abstractService interface{}) {}
165165

166-
// возвращает таймауты приложения
166+
// Timeout возвращает таймауты приложения
167167
func (a *Abstract) Timeout() common.Timeout {
168168
return a.CommonTimeout
169169
}

application/grep.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
"github.com/Halfi/postmanq/grep"
66
)
77

8-
// приложение, ищущее логи по адресату или получателю
8+
// Grep приложение, ищущее логи по адресату или получателю
99
type Grep struct {
1010
Abstract
1111
}
1212

13-
// создает новое приложение
13+
// NewGrep создает новое приложение
1414
func NewGrep() common.Application {
1515
return new(Grep)
1616
}
1717

18-
// запускает приложение с аргументами
18+
// RunWithArgs запускает приложение с аргументами
1919
func (g *Grep) RunWithArgs(args ...interface{}) {
2020
common.App = g
2121
g.services = []interface{}{
@@ -31,7 +31,7 @@ func (g *Grep) RunWithArgs(args ...interface{}) {
3131
g.run(g, event)
3232
}
3333

34-
// запускает сервисы приложения
34+
// FireRun запускает сервисы приложения
3535
func (g *Grep) FireRun(event *common.ApplicationEvent, abstractService interface{}) {
3636
service := abstractService.(common.GrepService)
3737
go service.OnGrep(event)

0 commit comments

Comments
 (0)