Introduction
In episode 5, Miki wrote a perform that counted the variety of strains in a file with interfaces. The very first thing his perform did was to open a file with Go’s os.Open
perform. Miki selected this technique as a result of the variable returned by mentioned perform implements the io.Reader
interface which is essential for the following step. The remaining elements of this perform consisted of a primitive sort alias that happy the io.Author
interface and tracked the variety of strains by growing the Write
technique’s receiver worth. To place the method in movement, Miki will invoke perform io.Copy
to set off his sort alias’ Write
technique and in essence, depend the variety of strains within the file.
On this video, Miki will write a flexible logging library with Go interfaces.The primary prototype he proposes consists of a sort with an io.Author
interface subject to deal with writing knowledge for the logger. Upon finishing the primary design, Miki realizes his sort is lacking a Sync
perform, which is able to allow builders to maneuver knowledge into secure storage whereas logging. To fulfill this requirement, Miki will create a brand new interface sort with a Sync
perform. Watch and learn the way you need to use sort assertions to write down easy, but efficient, code.
Issues you’ll study on this video
- The right way to correctly carry out a sort assertion on an interface.
- The right way to transfer knowledge from reminiscence to secure storage.
- Tips about designing an interface in Go.
Video