# io.writer

Published articles for io.writer.

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

## JSON - The Fine Print: Part 2 - Emitting JSON

DevFeed: [JSON - The Fine Print: Part 2 - Emitting JSON](<https://devfeed.tech/articles/json-the-fine-print-part-2-emitting-json-22267.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-part-2.html>)

Published: 2025-02-04T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [JSON](<https://devfeed.tech/topics/json.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>), [Structured-data](<https://devfeed.tech/topics/structured-data.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [api-layers](<https://devfeed.tech/tags/api-layers.md>), [code](<https://devfeed.tech/tags/code.md>), [common-serialization-errors](<https://devfeed.tech/tags/common-serialization-errors.md>), [data](<https://devfeed.tech/tags/data.md>), [data-serialization](<https://devfeed.tech/tags/data-serialization.md>), [data-structure-separation](<https://devfeed.tech/tags/data-structure-separation.md>), [data-transmission](<https://devfeed.tech/tags/data-transmission.md>), [data-validation](<https://devfeed.tech/tags/data-validation.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [function](<https://devfeed.tech/tags/function.md>), [go-json-types](<https://devfeed.tech/tags/go-json-types.md>), [go-language-serialization](<https://devfeed.tech/tags/go-language-serialization.md>), [go-language-validation](<https://devfeed.tech/tags/go-language-validation.md>), [go-type-mapping](<https://devfeed.tech/tags/go-type-mapping.md>), [http](<https://devfeed.tech/tags/http.md>), [io](<https://devfeed.tech/tags/io.md>), [io-writer](<https://devfeed.tech/tags/io-writer.md>), [json](<https://devfeed.tech/tags/json.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-go-mapping](<https://devfeed.tech/tags/json-go-mapping.md>), [json-marshaling](<https://devfeed.tech/tags/json-marshaling.md>), [json-unmarshaling](<https://devfeed.tech/tags/json-unmarshaling.md>), [json-validation](<https://devfeed.tech/tags/json-validation.md>), [map](<https://devfeed.tech/tags/map.md>), [passing-serialized-data](<https://devfeed.tech/tags/passing-serialized-data.md>), [properties](<https://devfeed.tech/tags/properties.md>), [rest-apis](<https://devfeed.tech/tags/rest-apis.md>), [schema](<https://devfeed.tech/tags/schema.md>), [schema-less-data-format](<https://devfeed.tech/tags/schema-less-data-format.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [serialization-mistakes](<https://devfeed.tech/tags/serialization-mistakes.md>), [serialization-protocols](<https://devfeed.tech/tags/serialization-protocols.md>), [standard](<https://devfeed.tech/tags/standard.md>), [structure](<https://devfeed.tech/tags/structure.md>), [writing](<https://devfeed.tech/tags/writing.md>)

### AI overview

This tutorial explains how to emit JSON in Go using the encoding/json package. It compares json.Marshal, which returns bytes, with json.Encoder, which writes to an io.Writer, and discusses error handling in HTTP handlers. It also demonstrates marshaling maps and structs and using field tags to control JSON property names.

### Source excerpt

Introduction In part 1 we took a high-level view on serialization and JSON. In this part, we'll roll our sleeves and start working with JSON, focused on emitting JSON. You might think this is a basic topic, but there is much more to it than just calling json.Marshal. json.Marshal vs json.Encoder The encoding/json package has two main APIs: Marshal and NewEncoder. The Marshal function returns a []byte while the NewEncoder function will write to an io.Writer. The question is: When should you use one API over the other?

## 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.

## Interfaces 101 : Determine LOC with io.Writer Ep. 5

DevFeed: [Interfaces 101 : Determine LOC with io.Writer Ep. 5](<https://devfeed.tech/articles/interfaces-101-determine-loc-with-io-writer-ep-5-22212.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/02/interfaces-101-determine-loc-with-iowriter.html>)

Published: 2023-02-27T00: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>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [IO](<https://devfeed.tech/topics/io.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [implement](<https://devfeed.tech/tags/implement.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interface-implementation](<https://devfeed.tech/tags/interface-implementation.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [io](<https://devfeed.tech/tags/io.md>), [io-writer](<https://devfeed.tech/tags/io-writer.md>), [stringer](<https://devfeed.tech/tags/stringer.md>), [video](<https://devfeed.tech/tags/video.md>), [writer](<https://devfeed.tech/tags/writer.md>)

### AI overview

A video tutorial demonstrates how to implement a Go interface using a type alias, pass a variable as an interface to a function, and repurpose the interface to count lines of code with io.Writer.

### Source excerpt

Introduction In episode 4, Miki defined an enumerated type that satisfied Go's fmt.Stringer interface. By implementing the fmt.Stringer interface, Miki can specify how his enumerators were printed within a formatted string and in this case, he expected the values to be displayed as a predetermined text value. Miki also pointed out how using the value of the method's receiver within the Stringer method can result in a recursive loop.

## Using The Log Package In Go

DevFeed: [Using The Log Package In Go](<https://devfeed.tech/articles/using-the-log-package-in-go-22083.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/11/using-log-package-in-go.html>)

Published: 2013-11-05T00: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>), [Logging](<https://devfeed.tech/topics/logging.md>), [IO](<https://devfeed.tech/topics/io.md>), [Linux](<https://devfeed.tech/topics/linux.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>), [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-writer](<https://devfeed.tech/tags/io-writer.md>), [linux](<https://devfeed.tech/tags/linux.md>), [logging](<https://devfeed.tech/tags/logging.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

### AI overview

A tutorial on using Go's standard log package to create multiple loggers and direct messages to standard output, standard error, discarded output, files, or other io.Writer destinations.

### Source excerpt

Linux is unique to Windows in many ways, and writing programs in Linux is no exception. The use of standard out, standard err and null devices is not only a good idea but it's the law. If your programs are going to be logging information, it is best to follow the destination conventions. This way your programs will work with all of the Mac/Linux tooling and hosted environments. Go has a package in the standard library called log and a type called logger. Using the log package will give you everything you need to be a good citizen. You will be able to write to all the standard devices, custom files or any destination that support the io.Writer interface. I have provided a really simple sample that will get you started with using logger: