O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The sample code illustrates the lazy loading of the data while accessing the container structure. As the data should be loaded only once, the Once struct from the sync package is used in the method Pop. The Once implements only one method called Do which consumes the func with no arguments and the function is executed only once per Once instance, during the execution.

The Do method calls blocks until the first run is done. This fact corresponds with the fact that Once is intended to be used for initialization.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required