Skip to content

Commit 5e142e7

Browse files
committed
Update doa
1 parent d5c39f3 commit 5e142e7

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

daze.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ func (l *Locale) ServeSocks4(ctx *Context, cli io.ReadWriteCloser) error {
291291
err error
292292
)
293293
cliReader.Discard(1)
294-
fCode, _ = cliReader.ReadByte()
294+
fCode, err = cliReader.ReadByte()
295+
if err != nil {
296+
return err
297+
}
295298
io.ReadFull(cliReader, fDstPort)
296299
dstPort = binary.BigEndian.Uint16(fDstPort)
297300
io.ReadFull(cliReader, fDstIP)
@@ -352,13 +355,13 @@ func (l *Locale) ServeSocks5(ctx *Context, cli io.ReadWriteCloser) error {
352355
err error
353356
)
354357
cliReader.Discard(1)
355-
fN, _ = cliReader.ReadByte()
358+
fN = doa.Val(cliReader.ReadByte())
356359
cliReader.Discard(int(fN))
357360
cli.Write([]byte{0x05, 0x00})
358361
cliReader.Discard(1)
359-
fCmd, _ = cliReader.ReadByte()
362+
fCmd = doa.Val(cliReader.ReadByte())
360363
cliReader.Discard(1)
361-
fAT, _ = cliReader.ReadByte()
364+
fAT = doa.Val(cliReader.ReadByte())
362365
switch fAT {
363366
case 0x01:
364367
fDstAddr = make([]byte, 4)

lib/doa/doa.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
// Package doa is the abbreviation of the "Dead or alive". It provides some easy ways to make you panic down the
2-
// program.
1+
// Package doa stands for "dead or alive". It provides simple utilities to intentionally crash the program with a panic.
32
package doa
43

5-
// Doa lets you test if a condition in your code returns true, if not, the program will panic.
4+
// Doa checks a boolean condition and triggers a panic if it’s false.
65
func Doa(b bool) {
76
if !b {
87
panic("unreachable")
98
}
109
}
1110

12-
// Nil lets you test if an error in your code is nil, if not, the program will panic.
11+
// Err returns the error passed to it, ignoring the first argument.
12+
func Err[T any](a T, err error) error {
13+
return err
14+
}
15+
16+
// Nil checks if an error is non-nil and panics if it is.
1317
func Nil(err error) {
1418
if err != nil {
1519
panic(err)
1620
}
1721
}
1822

19-
// Try will give you the embedded value if there is no error returns. If instead error then it will panic.
23+
// Try returns a value if there’s no error, otherwise it panics.
2024
func Try[T any](a T, err error) T {
2125
if err != nil {
2226
panic(err)
2327
}
2428
return a
2529
}
2630

27-
// Err just returns error.
28-
func Err[T any](a T, err error) error {
29-
return err
31+
// Val returns the first argument, ignoring the error.
32+
func Val[T any](a T, err error) T {
33+
return a
3034
}

0 commit comments

Comments
 (0)