From 92f4b7af1073b6cdd0786ce2090d6e446e0903ad Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 15 Mar 2026 20:48:45 -0700 Subject: Extract shared readFrom helper to deduplicate io.Reader boilerplate 13 types implemented identical offset-based io.Reader patterns with 5-7 lines of copy-and-offset-tracking code each. Extract a shared readFrom(p, offset, data) helper and reduce each Read() method to a one-liner delegating to it. --- hotline/user.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'hotline/user.go') diff --git a/hotline/user.go b/hotline/user.go index c4e0790..d68997b 100644 --- a/hotline/user.go +++ b/hotline/user.go @@ -2,7 +2,6 @@ package hotline import ( "encoding/binary" - "io" "math/big" "slices" ) @@ -64,14 +63,7 @@ func (u *User) Read(p []byte) (int, error) { []byte(u.Name), ) - if u.readOffset >= len(b) { - return 0, io.EOF // All bytes have been read - } - - n := copy(p, b) - u.readOffset = n - - return n, nil + return readFrom(p, &u.readOffset, b) } func (u *User) Write(p []byte) (int, error) { -- cgit