The Secret Life of Go: Interfaces in Practice
dev.to·1d·
Discuss: DEV
🐹golang
Preview
Report Post

How to replace three redundant functions with one io.Reader.


Chapter 18: The Universal Adapter

The archive was quiet, except for the rhythmic thrum-click of the pneumatic tube system delivering requests to the front desk. Ethan had his headphones on, typing furiously.

"You are typing very fast," Eleanor observed, pausing at his desk with a cart full of magnetic tapes. "That usually means you are copying and pasting."

Ethan pulled off his headphones, looking guilty. "I’m building a log analyzer. It needs to read logs from three places: a local file archive, a live HTTP stream from the server, and sometimes just a raw string for testing."

He pointed to his code. "I wrote three functions."

// 1. Read from a file
func AnalyzeFile(filename string) error...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help