Skip to content

Commit 7861266

Browse files
authored
Merge pull request #123 from wechaty/linter
make linter happy
2 parents 8647605 + 0915fa1 commit 7861266

File tree

26 files changed

+99
-73
lines changed

26 files changed

+99
-73
lines changed

wechaty-puppet-service/filebox.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func (m *MessageFile) Read(p []byte) (n int, err error) {
4747
recv, err := m.client.Recv()
4848
if err == io.EOF {
4949
m.done = true
50-
err = nil
5150
break
5251
}
5352
if err != nil {
@@ -144,7 +143,6 @@ func (m *DownloadFile) Read(p []byte) (n int, err error) {
144143
recv, err := m.client.Recv()
145144
if err == io.EOF {
146145
m.done = true
147-
err = nil
148146
break
149147
}
150148
if err != nil {
@@ -171,7 +169,7 @@ func NewDownloadFile(client pbwechaty.Puppet_DownloadClient) *DownloadFile {
171169
* for testing propose, use 20KB as the threshold
172170
* after stable we should use a value between 64KB to 256KB as the threshold
173171
*/
174-
const passThroughThresholdBytes = 20 * 1024 // 20KB
172+
const passThroughThresholdBytes = 20 * 1024 //nolint:unused, deadcode, varcheck // TODO 未来会被用到
175173

176174
/**
177175
* 1. Green:

wechaty-puppet-service/puppet_service.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/connectivity"
16+
"google.golang.org/grpc/credentials/insecure"
1617
"google.golang.org/protobuf/types/known/timestamppb"
1718
"io"
1819
"log"
@@ -237,7 +238,9 @@ func (p *PuppetService) startGrpcClient() error {
237238
}
238239
endpoint = serviceEndPoint.Target()
239240
}
240-
conn, err := grpc.Dial(endpoint, grpc.WithInsecure(), grpc.WithAuthority(p.Token))
241+
242+
// TODO 支持 tls
243+
conn, err := grpc.Dial(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithAuthority(p.Token))
241244
if err != nil {
242245
return err
243246
}
@@ -628,7 +631,7 @@ func (p *PuppetService) MessageRawPayload(id string) (*schemas.MessagePayload, e
628631
if response.ReceiveTime != nil {
629632
payload.Timestamp = grpcTimestampToGoTime(response.ReceiveTime)
630633
} else {
631-
payload.Timestamp = time.Unix(int64(response.TimestampDeprecated), 0)
634+
payload.Timestamp = time.Unix(int64(response.TimestampDeprecated), 0) //nolint:staticcheck
632635
}
633636
return payload, nil
634637
}
@@ -786,7 +789,7 @@ func (p *PuppetService) MessageURL(messageID string) (*schemas.UrlLinkPayload, e
786789
if response.UrlLink == nil {
787790
// Deprecated: will be removed after Dec 31, 2022
788791
payload := &schemas.UrlLinkPayload{}
789-
p.unMarshal(response.UrlLinkDeprecated, payload)
792+
p.unMarshal(response.UrlLinkDeprecated, payload) //nolint:staticcheck
790793
return payload, nil
791794
}
792795

wechaty-puppet/events/events.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type (
7676

7777
// CopyTo copies the event listeners to an EventEmitter
7878
func (e Events) CopyTo(emitter EventEmitter) {
79-
if e != nil && len(e) > 0 {
79+
if len(e) > 0 {
8080
// register the events to/with their listeners
8181
for evt, listeners := range e {
8282
if len(listeners) > 0 {
@@ -143,7 +143,7 @@ func (e *emitter) Emit(evt EventName, data ...interface{}) {
143143
if e.evtListeners == nil {
144144
return // has no listeners to emit/speak yet
145145
}
146-
if listeners := e.evtListeners[evt]; listeners != nil && len(listeners) > 0 { // len() should be just fine, but for any case on future...
146+
if listeners := e.evtListeners[evt]; len(listeners) > 0 { // len() should be just fine, but for any case on future...
147147
for i := range listeners {
148148
l := listeners[i]
149149
if l != nil {
@@ -164,7 +164,7 @@ func (e *emitter) EventNames() []EventName {
164164
return nil
165165
}
166166

167-
names := make([]EventName, e.Len(), e.Len())
167+
names := make([]EventName, e.Len())
168168
i := 0
169169
for k := range e.evtListeners {
170170
names[i] = k

wechaty-puppet/filebox/file_box_base64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (fb *fileBoxBase64) toJSONMap() (map[string]interface{}, error) {
2727
}, nil
2828
}
2929

30-
func (fb *fileBoxBase64) toBytes() ([]byte, error) {
30+
func (fb *fileBoxBase64) toBytes() ([]byte, error) { //nolint:unused
3131
dec, err := base64.StdEncoding.DecodeString(fb.base64Data)
3232
if err != nil {
3333
return nil, err

wechaty-puppet/filebox/file_box_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func (fb *fileBoxFile) toJSONMap() (map[string]interface{}, error) {
2121
return nil, nil
2222
}
2323

24-
func (fb *fileBoxFile) toBytes() ([]byte, error) {
24+
func (fb *fileBoxFile) toBytes() ([]byte, error) { //nolint:unused
2525
file, err := ioutil.ReadFile(fb.path)
2626
if err != nil {
2727
return nil, err
2828
}
2929
return file, nil
3030
}
3131

32-
func (fb *fileBoxFile) toBase64() (string, error) {
32+
func (fb *fileBoxFile) toBase64() (string, error) { //nolint:unused
3333
file, err := fb.toBytes()
3434
if err != nil {
3535
return "", err

wechaty-puppet/filebox/file_box_stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (fb *fileBoxStream) toJSONMap() (map[string]interface{}, error) {
1818
return nil, nil
1919
}
2020

21-
func (fb *fileBoxStream) toBytes() ([]byte, error) {
21+
func (fb *fileBoxStream) toBytes() ([]byte, error) { // nolint:unused
2222
panic("im")
2323
}
2424

wechaty-puppet/filebox/file_box_url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (fb *fileBoxUrl) toJSONMap() (map[string]interface{}, error) {
2828
}, nil
2929
}
3030

31-
func (fb *fileBoxUrl) toBytes() ([]byte, error) {
31+
func (fb *fileBoxUrl) toBytes() ([]byte, error) { //nolint:unused
3232
request, err := http.NewRequest(http.MethodGet, fb.remoteUrl, nil)
3333
if err != nil {
3434
return nil, err

wechaty-puppet/helper/file.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@ import "os"
44

55
func FileExists(path string) bool {
66
_, err := os.Stat(path)
7-
if err != nil {
8-
if os.IsExist(err) {
9-
return true
10-
}
11-
return false
12-
}
13-
return true
7+
return !os.IsNotExist(err)
148
}

wechaty-puppet/helper/file_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package helper
2+
3+
import "testing"
4+
5+
func TestFileExists(t *testing.T) {
6+
type args struct {
7+
path string
8+
}
9+
tests := []struct {
10+
name string
11+
args args
12+
want bool
13+
}{
14+
{"exists", args{path: "testdata/a.txt"}, true},
15+
{"not exists", args{path: "no.txt"}, false},
16+
}
17+
for _, tt := range tests {
18+
t.Run(tt.name, func(t *testing.T) {
19+
if got := FileExists(tt.args.path); got != tt.want {
20+
t.Errorf("FileExists() = %v, want %v", got, tt.want)
21+
}
22+
})
23+
}
24+
}

wechaty-puppet/helper/testdata/a.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)