Interfaces 101 : Interface Type Assertion

preview_player
Показать описание
Episode 6! - Watch and learn how you can use type assertions to write simple, yet effective, code. -- In this video, Miki will write a versatile logging library with Go interfaces.The first prototype he proposes consists of a type with an `io.Writer` interface field to handle writing data for the logger. Upon completing the first design, Miki realizes his type is missing a `Sync` function, which will enable developers to move data into stable storage while logging. To meet this requirement, Miki will create a new interface type with a `Sync` function.

Things you will learn in this video :
- How to properly perform a type assertion on an interface.
- How to move data from memory to stable storage.
- Tips on designing an interface in Go.

--

Do you agree with the Go proverb : “the bigger the interface the weaker the abstraction”?
Comment below or tweet us on twitter & let us know, we want to hear from you! ~ If you found this video helpful, hit that like button & subscribe for more content like this.

--

Other Links:
Рекомендации по теме
Комментарии
Автор

Miki, what I don't understand is that with the s field being a NopSyncer empty struct, Sync() will always be a no-op. Nothing is being wrapped in this Sync(), so what does this accomplish? I don't see how any file sync would happen this way. Am I missing something?

amerispunk
Автор

Cool use of interfaces to make sensible logic

nkodoko