Go Standard Library Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

The core concept of the functional options pattern is that the configuration API contains the functional parameters. In this case, the NewClient function accepts a various number of ConfigFunc arguments, which are then applied one by one on the defaultClient struct. This way, the default configuration is modified with huge flexibility. 

See the FromFile and FromEnv functions, which return the ConfigFunc, that is in fact, accessing the file or environmental variables.

Finally, you can check the output which applied both the configuration options and resulting Client struct that contains the values from the file and environmental variables.