refactor(lint): apply Go best practices across codebase

- Use errors.Is() instead of direct sentinel comparison (13 instances)
- Convert if/else-if chains to switch/case for same-variable comparisons
- Remove redundant bitwise OR with zero
- Add post-implementation checklist to CLAUDE.md
This commit is contained in:
viettranx committed 2026-03-07 20:51:39 +07:00
1 parent df684e2582
commit b62d46e50e
14 files changed
+56 -28

No files matched your search

+2 -1
View File
@@ -6,6 +6,7 @@ package feishu
import (
"context"
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
@@ -278,7 +279,7 @@ func (c *Channel) startWebhook(ctx context.Context) error {
}
go func() {
if err := c.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := c.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
slog.Error("feishu webhook server error", "error", err)
}
}()
+3 -2
View File
@@ -3,6 +3,7 @@ package feishu
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
)
@@ -83,7 +84,7 @@ func unmarshalFrame(data []byte) (*wsFrame, error) {
for r.Len() > 0 {
tag, err := binary.ReadUvarint(r)
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return nil, fmt.Errorf("read tag: %w", err)
@@ -181,7 +182,7 @@ func unmarshalHeader(data []byte) (wsHeader, error) {
// --- Protobuf encoding helpers ---
func pbWriteVarintField(w *bytes.Buffer, fieldNum int, val uint64) {
tag := uint64(fieldNum<<3 | 0) // wire type 0 = varint
tag := uint64(fieldNum << 3) // wire type 0 = varint
pbWriteUvarint(w, tag)
pbWriteUvarint(w, val)
}