github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/options/README.md (about) 1 # Options 2 3 Go-micro makes the use of [functional options](https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis). It's a design 4 pattern that allows the addition of new options without changing the method signature. 5 6 Each package has an [Option](https://godoc.org/github.com/micro/go-micro#Option) type 7 8 ``` 9 type Option func(*Options) 10 ``` 11 12 Options such as the [Name](https://godoc.org/github.com/micro/go-micro#Name) function exist to set a service name 13 14 The implementation is as follows 15 16 ``` 17 func Name(n string) Option { 18 return func(o *Options) { 19 o.Server.Init(server.Name(n)) 20 } 21 } 22 ``` 23 24 ## Usage 25 26 Here's an example at the top level 27 28 ``` 29 import "github.com/micro/go-micro/v2" 30 31 32 service := micro.NewService( 33 micro.Name("my.service"), 34 ) 35 ```