1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package micro
- import (
- "context"
- "git.nspix.com/golang/micro/registry"
- )
- type (
- Options struct {
- Zone string `json:"zone"`
- Name string `json:"name"`
- Version string `json:"version"`
- EnableHttp bool `json:"enable_http"`
- EnableRPC bool `json:"enable_rpc"`
- registry registry.Registry
- Server Server
- Context context.Context
- }
- OptionMiddleware func(o *Options)
- )
- func WithName(name string, version string) OptionMiddleware {
- return func(o *Options) {
- o.Name = name
- o.Version = version
- }
- }
- func WithRegistry(r registry.Registry) OptionMiddleware {
- return func(o *Options) {
- o.registry = r
- }
- }
- func WithContext(c context.Context) OptionMiddleware {
- return func(o *Options) {
- o.Context = c
- }
- }
- func WithServer(s Server) OptionMiddleware {
- return func(o *Options) {
- o.Server = s
- }
- }
- func WithoutHttp() OptionMiddleware {
- return func(o *Options) {
- o.EnableHttp = false
- }
- }
- func WithoutRPC() OptionMiddleware {
- return func(o *Options) {
- o.EnableRPC = false
- }
- }
- func NewOptions() *Options {
- return &Options{
- Zone: "default",
- Version: "1.0.1",
- EnableHttp: true,
- EnableRPC: true,
- Context: context.Background(),
- registry: registry.DefaultRegistry,
- }
- }
|