// WrapSubscriber adds a subscriber Wrapper to a list of options passed into the server func WrapSubscriber(w ...server.SubscriberWrapper) Option { return func(o *Options) { var wrappers []server.Option for _, wrap := range w { wrappers = append(wrappers, server.WrapSubscriber(wrap)) } // Init once o.Server.Init(wrappers...) } }
func main() { // optionally setup command line usage cmd.Init() md := server.DefaultOptions().Metadata md["datacenter"] = "local" server.DefaultServer = server.NewServer( server.WrapHandler(logWrapper), server.WrapSubscriber(logSubWrapper), server.Metadata(md), ) // Initialise Server server.Init( server.Name("go.micro.srv.example"), ) // Register Handlers server.Handle( server.NewHandler( new(handler.Example), ), ) // Register Subscribers if err := server.Subscribe( server.NewSubscriber( "topic.go.micro.srv.example", new(subscriber.Example), ), ); err != nil { log.Fatal(err) } if err := server.Subscribe( server.NewSubscriber( "topic.go.micro.srv.example", subscriber.Handler, ), ); err != nil { log.Fatal(err) } // Run server if err := server.Run(); err != nil { log.Fatal(err) } }