# io.reader

Published articles for io.reader.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Interfaces 101 : Interface Design Considerations Ep. 7

DevFeed: [Interfaces 101 : Interface Design Considerations Ep. 7](<https://devfeed.tech/articles/interfaces-101-interface-design-considerations-ep-7-22217.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/03/interfaces-101-interface-design-considerations.html>)

Published: 2023-03-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>), [IO](<https://devfeed.tech/topics/io.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [interface](<https://devfeed.tech/tags/interface.md>), [io](<https://devfeed.tech/tags/io.md>), [io-copy-function](<https://devfeed.tech/tags/io-copy-function.md>), [io-interfaces](<https://devfeed.tech/tags/io-interfaces.md>), [io-reader](<https://devfeed.tech/tags/io-reader.md>), [io-writer](<https://devfeed.tech/tags/io-writer.md>), [polymorphism](<https://devfeed.tech/tags/polymorphism.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

A video tutorial about Go interface design. It explains how interfaces express what code needs, discusses criteria for effective interfaces, and introduces Go's io.Reader and io.Writer interfaces. It also covers polymorphism through type assertions and cautions that overly large interfaces can weaken abstraction.

### Source excerpt

Introduction In episode 6, Miki built a logger package with the aim of making it as versatile as possible. To achieve this, he constructed his logger object with a function that would: accept the io.Writer interface as a parameter and perform type assertions to retrieve other interface types as needed. By building this, Miki demonstrated how polymorphism is achieved with Go by changing the type of a variable with type assertions.

## Interfaces 101 : Interface Type Assertion Ep. 6

DevFeed: [Interfaces 101 : Interface Type Assertion Ep. 6](<https://devfeed.tech/articles/interfaces-101-interface-type-assertion-ep-6-22218.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/03/interfaces-101-interface-type-assertions.html>)

Published: 2023-03-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [IO](<https://devfeed.tech/topics/io.md>), [Streams](<https://devfeed.tech/topics/streams.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [copy](<https://devfeed.tech/tags/copy.md>), [flush](<https://devfeed.tech/tags/flush.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [io](<https://devfeed.tech/tags/io.md>), [io-interface](<https://devfeed.tech/tags/io-interface.md>), [io-reader](<https://devfeed.tech/tags/io-reader.md>), [io-writer](<https://devfeed.tech/tags/io-writer.md>), [library](<https://devfeed.tech/tags/library.md>), [logger](<https://devfeed.tech/tags/logger.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [type-alias](<https://devfeed.tech/tags/type-alias.md>), [versatile](<https://devfeed.tech/tags/versatile.md>), [video](<https://devfeed.tech/tags/video.md>)

### AI overview

This video tutorial explains how to use type assertions and Go interfaces. It demonstrates io.Reader and io.Writer, io.Copy, and interface design while building a logging library that moves data from memory to stable storage.

### Source excerpt

Introduction In episode 5, Miki wrote a function that counted the number of lines in a file with interfaces. The first thing his function did was to open a file with Go's os.Open function. Miki chose this method because the variable returned by said function implements the io.Reader interface which is crucial for the next step. The remaining parts of this function consisted of a primitive type alias that satisfied the io.Writer interface and tracked the number of lines by increasing the Write method's receiver value. To put the process in motion, Miki will invoke function io.Copy to trigger his type alias' Write method and in essence, count the number of lines in the file.

## Reading XML Documents in Go

DevFeed: [Reading XML Documents in Go](<https://devfeed.tech/articles/reading-xml-documents-in-go-22050.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/06/reading-xml-documents-in-go.html>)

Published: 2013-06-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [XML](<https://devfeed.tech/topics/xml.md>), [Code](<https://devfeed.tech/topics/code.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [decoding](<https://devfeed.tech/tags/decoding.md>), [function](<https://devfeed.tech/tags/function.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [io](<https://devfeed.tech/tags/io.md>), [io-reader](<https://devfeed.tech/tags/io-reader.md>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [xml](<https://devfeed.tech/tags/xml.md>)

### AI overview

A tutorial on reading and deserializing XML documents in Go using the standard library's encoding/xml package. It explains how to define structs and XML tags, decode through an io.Reader, and return parsed nodes, while also mentioning xmlpath for greater flexibility.

### Source excerpt

I was really surprised how easy it was to read an XML document using the encoding/xml package that comes with the standard library. The package works by defining structs that map the XML document. If you need more flexibility then use Gustavo Niemeyer's xmlpath package (found here). Here is the XML document we are going to read and de-serialize: <straps> <strap key="CompanyName" value="NEWCO" /> <strap key="UseEmail" value="true" /> </straps> The first thing we need to do is define the structs we will use to map the document: type XMLStrap struct { XMLName xml.Name ̀ xml:"strap"̀ Key string ̀ xml:"key,attr"̀ Value string ̀ xml:"value,attr"̀ } type XMLStraps struct { XMLName xml.Name ̀ xml:"straps"̀ Straps []XMLStrap ̀ xml:"strap"̀ } There are two structs, one for the entire document (<straps>) and one for each individual child node (<strap>). If you look closely at the structs you may see something new. Each field has a tag associated with it. These tags are bound to each individual field. Go's reflect package allows you to access these tags. These tag formats are specific to the decoding support inside the encoding/xml package. The tags map the nodes and attributes of the XML document to the struct. The following code decodes the XML document and returns the array of strap nodes: func ReadStraps(reader io.Reader) ([]XMLStrap, error) { var xmlStraps XMLStraps if err := xml.NewDecoder(reader).Decode(&xmlStraps); err != nil { return nil, err } return xmlStraps.Straps, nil } The function takes an io.Reader. We will be passing a os.File variable into this method. The function returns an array of pointers for each strap we read from the file. First we create a XMLStraps variable and get its address. Next we create a decoder using the xml.NewDecoder method passing the io.Reader object. Then we call Decode which reads the file and de-serializes the file into the XMLStraps variable. Then we just return the array of strap values. The following completes the sample code: /* s