Skip to content

Commit ede4373

Browse files
committed
fix: Lint & Fmt
1 parent 50466b8 commit ede4373

File tree

9 files changed

+27
-28
lines changed

9 files changed

+27
-28
lines changed

common/buf/buffer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (b *Buffer) Release() {
233233
if b == nil || b.closed || !b.managed {
234234
return
235235
}
236-
Put(b.data)
236+
Put(b.data) //nolint:errcheck
237237
*b = Buffer{closed: true}
238238
}
239239

common/mcprotocol/message.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func (m *Message) ReadMessage(buffer *buf.Buffer) error {
123123
return err
124124
}
125125
code, err := buffer.Peek(int(length))
126+
if err != nil {
127+
return err
128+
}
126129
err = json.Unmarshal(code, m)
127130
return err
128131
}

common/mcprotocol/varint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package mcprotocol
22

33
import (
44
"errors"
5-
"github.com/layou233/ZBProxy/common/rw"
65
"io"
6+
7+
"github.com/layou233/ZBProxy/common/rw"
78
)
89

910
const MaxVarIntLen = 5

common/mcprotocol/varint_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
func checkWrite(t *testing.T, n int32, result [MaxVarIntLen]byte) {
1414
buffer := buf.NewSize(MaxVarIntLen + 1)
15-
buffer.WriteZeroN(MaxVarIntLen)
16-
buffer.FullReset()
1715
defer buffer.Release()
1816
_, err := VarInt(n).WriteTo(buffer)
1917
if err != nil {
@@ -24,7 +22,6 @@ func checkWrite(t *testing.T, n int32, result [MaxVarIntLen]byte) {
2422
if !bytes.Equal(buffer.Bytes(), result[:]) {
2523
t.Fatalf("VarInt WriteTo error: got %v, expect %v", buffer.Bytes(), result)
2624
}
27-
return
2825
}
2926

3027
func checkRead(t *testing.T, n int32, result [MaxVarIntLen]byte) {
@@ -38,7 +35,6 @@ func checkRead(t *testing.T, n int32, result [MaxVarIntLen]byte) {
3835
if n != vi {
3936
t.Fatalf("VarInt ReadFrom error: got %v, expect %v", vi, n)
4037
}
41-
return
4238
}
4339

4440
func TestVarInt_WriteTo(t *testing.T) {
@@ -74,15 +70,6 @@ func BenchmarkVarInt_WriteTo(b *testing.B) {
7470
vi := VarInt(25565)
7571
b.ResetTimer()
7672
for i := 0; i < b.N; i++ {
77-
vi.WriteTo(io.Discard)
73+
_, _ = vi.WriteTo(io.Discard)
7874
}
7975
}
80-
81-
/*func BenchmarkGoMCVarInt_WriteTo(b *testing.B) {
82-
b.ReportAllocs()
83-
vi := packet.VarInt(25565)
84-
b.ResetTimer()
85-
for i := 0; i < b.N; i++ {
86-
vi.WriteTo(io.Discard)
87-
}
88-
}*/

common/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ func Must[T any](s T, err error) T {
77
return s
88
}
99

10+
func Must0(err error) {
11+
if err != nil {
12+
panic(err)
13+
}
14+
}
15+
1016
func GetSecond[T any](_ any, r T) T {
1117
return r
1218
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
color.HiGreen("Welcome to ZBProxy %s (%s)!\n", version.Version, version.CommitHash)
3434
color.HiBlack("Build Information: %s, %s/%s, CGO %s\n",
3535
runtime.Version(), runtime.GOOS, runtime.GOARCH, common.CGOHint)
36-
//go version.CheckUpdate()
36+
// go version.CheckUpdate()
3737

3838
config.LoadConfig()
3939

service/minecraft/handler.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func NewConnHandler(s *config.ConfigProxyService,
100100
motdLen := len(motd)
101101

102102
buffer.Reset(mcprotocol.MaxVarIntLen)
103-
buffer.WriteByte(0x00) // Client bound : Status Response
104-
mcprotocol.VarInt(motdLen).WriteTo(buffer)
103+
common.Must0(buffer.WriteByte(0x00)) // Client bound : Status Response
104+
common.Must(mcprotocol.VarInt(motdLen).WriteTo(buffer))
105105
mcprotocol.AppendPacketLength(buffer, buffer.Len()+motdLen)
106106

107107
_, err = c.Write(buffer.Bytes())
@@ -159,9 +159,7 @@ func NewConnHandler(s *config.ConfigProxyService,
159159
if err != nil {
160160
return nil, err
161161
}
162-
var (
163-
playerName string
164-
)
162+
var playerName string
165163
err = mcprotocol.Scan(buffer, &packetID, &playerName)
166164
if err != nil {
167165
return nil, err
@@ -176,8 +174,8 @@ func NewConnHandler(s *config.ConfigProxyService,
176174
msgLen := len(msg)
177175

178176
buffer.Reset(mcprotocol.MaxVarIntLen)
179-
buffer.WriteByte(0x00) // Client bound : Disconnect (login)
180-
mcprotocol.VarInt(msgLen).WriteTo(buffer)
177+
common.Must0(buffer.WriteByte(0x00)) // Client bound : Disconnect (login)
178+
common.Must(mcprotocol.VarInt(msgLen).WriteTo(buffer))
181179
mcprotocol.AppendPacketLength(buffer, buffer.Len()+msgLen)
182180

183181
_, err = c.Write(buffer.Bytes())
@@ -227,8 +225,8 @@ func NewConnHandler(s *config.ConfigProxyService,
227225
msgLen := len(msg)
228226

229227
buffer.Reset(mcprotocol.MaxVarIntLen)
230-
buffer.WriteByte(0x00) // Client bound : Disconnect (login)
231-
mcprotocol.VarInt(msgLen).WriteTo(buffer)
228+
common.Must0(buffer.WriteByte(0x00)) // Client bound : Disconnect (login)
229+
common.Must(mcprotocol.VarInt(msgLen).WriteTo(buffer))
232230
mcprotocol.AppendPacketLength(buffer, buffer.Len()+msgLen)
233231

234232
_, err = c.Write(buffer.Bytes())
@@ -292,6 +290,9 @@ func NewConnHandler(s *config.ConfigProxyService,
292290
byte(0x00),
293291
playerName,
294292
)
293+
if err != nil {
294+
return nil, err
295+
}
295296
err = remoteMC.WritePacket(buffer)
296297
if err != nil {
297298
return nil, err

service/minecraft/kick.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func generateKickMessage(s *config.ConfigProxyService, name string) mcprotocol.M
3131
{
3232
Color: mcprotocol.Aqua, UnderLined: true,
3333
Text: "https://github.com/layou233/ZBProxy",
34-
//ClickEvent: chat.OpenURL("https://github.com/layou233/ZBProxy"),
34+
// ClickEvent: chat.OpenURL("https://github.com/layou233/ZBProxy"),
3535
},
3636
},
3737
}
@@ -60,7 +60,7 @@ func generatePlayerNumberLimitExceededMessage(s *config.ConfigProxyService, name
6060
{
6161
Color: mcprotocol.Aqua, UnderLined: true,
6262
Text: "https://github.com/layou233/ZBProxy",
63-
//ClickEvent: chat.OpenURL("https://github.com/layou233/ZBProxy"),
63+
// ClickEvent: chat.OpenURL("https://github.com/layou233/ZBProxy"),
6464
},
6565
},
6666
}

service/minecraft/motd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package minecraft
22

33
import (
44
"encoding/json"
5+
56
"github.com/layou233/ZBProxy/config"
67
"github.com/layou233/ZBProxy/service/transfer"
78
"github.com/layou233/ZBProxy/version"

0 commit comments

Comments
 (0)