1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-30 08:06:40 +02:00
go-micro/examples/options
2021-10-12 12:55:53 +01:00
..
README.md go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00

Options

Go-micro makes the use of functional options. It's a design pattern that allows the addition of new options without changing the method signature.

Each package has an Option type

type Option func(*Options)

Options such as the Name function exist to set a service name

The implementation is as follows

func Name(n string) Option {
	return func(o *Options) {
		o.Server.Init(server.Name(n))
	}
}

Usage

Here's an example at the top level

import "go-micro.dev/v4"


service := micro.NewService(
	micro.Name("my.service"),
)