@@ -283,7 +283,7 @@ var (
283
283
284
284
DefaultAuths = map [string ]func (... auth.Option ) auth.Auth {}
285
285
286
- DefaultProfiles = map [string ]func (... profile.Option ) profile.Profile {
286
+ DefaultDebugProfiles = map [string ]func (... profile.Option ) profile.Profile {
287
287
"http" : http .NewProfile ,
288
288
"pprof" : pprof .NewProfile ,
289
289
}
@@ -323,7 +323,7 @@ func newCmd(opts ...Option) Cmd {
323
323
Stores : DefaultStores ,
324
324
Tracers : DefaultTracers ,
325
325
Auths : DefaultAuths ,
326
- DebugProfiles : DefaultProfiles ,
326
+ DebugProfiles : DefaultDebugProfiles ,
327
327
Configs : DefaultConfigs ,
328
328
Caches : DefaultCaches ,
329
329
}
@@ -364,12 +364,11 @@ func (c *cmd) Options() Options {
364
364
}
365
365
366
366
func (c * cmd ) Before (ctx * cli.Context ) error {
367
- fmt .Println ("cmd.Before" )
368
367
// If flags are set then use them otherwise do nothing
369
368
var serverOpts []server.Option
370
369
var clientOpts []client.Option
371
370
// --- Profile Grouping Extension ---
372
- // Check for new profile flag/env (not just debug profiler)
371
+
373
372
profileName := ctx .String ("profile" )
374
373
if profileName == "" {
375
374
profileName = os .Getenv ("MICRO_PROFILE" )
@@ -388,24 +387,25 @@ func (c *cmd) Before(ctx *cli.Context) error {
388
387
transport .DefaultTransport = imported .Transport
389
388
case "nats" :
390
389
imported := mprofile .NatsProfile ()
391
- * c .opts .Registry = imported .Registry
392
- // these need to move out to a function so they can be merged with below ctx.String("Registry")
393
- serverOpts = append (serverOpts , server .Registry (* c .opts .Registry ))
394
- clientOpts = append (clientOpts , client .Registry (* c .opts .Registry ))
395
- registry .DefaultRegistry = imported .Registry
396
-
397
- * c .opts .Broker = imported .Broker
398
- broker .DefaultBroker = imported .Broker
399
- serverOpts = append (serverOpts , server .Broker (* c .opts .Broker ))
400
- clientOpts = append (clientOpts , client .Broker (* c .opts .Broker ))
401
-
402
- * c .opts .Store = imported .Store
403
- store .DefaultStore = imported .Store
404
- * c .opts .Transport = imported .Transport
405
-
406
- transport .DefaultTransport = imported .Transport
407
- serverOpts = append (serverOpts , server .Transport (* c .opts .Transport ))
408
- clientOpts = append (clientOpts , client .Transport (* c .opts .Transport ))
390
+ // Set the registry
391
+ sopts , clopts := c .setRegistry (imported .Registry )
392
+ serverOpts = append (serverOpts , sopts ... )
393
+ clientOpts = append (clientOpts , clopts ... )
394
+
395
+ // set the store
396
+ sopts , clopts = c .setStore (imported .Store )
397
+ serverOpts = append (serverOpts , sopts ... )
398
+ clientOpts = append (clientOpts , clopts ... )
399
+
400
+ // set the transport
401
+ sopts , clopts = c .setTransport (imported .Transport )
402
+ serverOpts = append (serverOpts , sopts ... )
403
+ clientOpts = append (clientOpts , clopts ... )
404
+
405
+ // Set the broker
406
+ sopts , clopts = c .setBroker (imported .Broker )
407
+ serverOpts = append (serverOpts , sopts ... )
408
+ clientOpts = append (clientOpts , clopts ... )
409
409
410
410
// Add more profiles as needed
411
411
default :
@@ -486,20 +486,9 @@ func (c *cmd) Before(ctx *cli.Context) error {
486
486
return fmt .Errorf ("Registry %s not found" , name )
487
487
}
488
488
489
- * c .opts .Registry = r ()
490
- serverOpts = append (serverOpts , server .Registry (* c .opts .Registry ))
491
- clientOpts = append (clientOpts , client .Registry (* c .opts .Registry ))
492
-
493
- if err := (* c .opts .Selector ).Init (selector .Registry (* c .opts .Registry )); err != nil {
494
- logger .Fatalf ("Error configuring registry: %v" , err )
495
- }
496
-
497
- clientOpts = append (clientOpts , client .Selector (* c .opts .Selector ))
498
-
499
- if err := (* c .opts .Broker ).Init (broker .Registry (* c .opts .Registry )); err != nil {
500
- logger .Fatalf ("Error configuring broker: %v" , err )
501
- }
502
- registry .DefaultRegistry = * c .opts .Registry
489
+ sopts , clopts := c .setRegistry (r ())
490
+ serverOpts = append (serverOpts , sopts ... )
491
+ clientOpts = append (clientOpts , clopts ... )
503
492
}
504
493
505
494
// Set the debug profile
@@ -518,11 +507,9 @@ func (c *cmd) Before(ctx *cli.Context) error {
518
507
if ! ok {
519
508
return fmt .Errorf ("Broker %s not found" , name )
520
509
}
521
-
522
- * c .opts .Broker = b ()
523
- serverOpts = append (serverOpts , server .Broker (* c .opts .Broker ))
524
- clientOpts = append (clientOpts , client .Broker (* c .opts .Broker ))
525
- broker .DefaultBroker = * c .opts .Broker
510
+ sopts , clopts := c .setBroker (b ())
511
+ serverOpts = append (serverOpts , sopts ... )
512
+ clientOpts = append (clientOpts , clopts ... )
526
513
}
527
514
528
515
// Set the selector
@@ -546,10 +533,10 @@ func (c *cmd) Before(ctx *cli.Context) error {
546
533
return fmt .Errorf ("Transport %s not found" , name )
547
534
}
548
535
549
- * c . opts . Transport = t ( )
550
- serverOpts = append (serverOpts , server . Transport ( * c . opts . Transport ) )
551
- clientOpts = append (clientOpts , client . Transport ( * c . opts . Transport ) )
552
- transport . DefaultTransport = * c . opts . Transport
536
+ sopts , clopts := c . setTransport ( t () )
537
+ serverOpts = append (serverOpts , sopts ... )
538
+ clientOpts = append (clientOpts , clopts ... )
539
+
553
540
}
554
541
555
542
// Parse the server options
@@ -695,6 +682,54 @@ func (c *cmd) Before(ctx *cli.Context) error {
695
682
return nil
696
683
}
697
684
685
+ func (c * cmd ) setRegistry (r registry.Registry ) ([]server.Option , []client.Option ) {
686
+ var serverOpts []server.Option
687
+ var clientOpts []client.Option
688
+ * c .opts .Registry = r
689
+ serverOpts = append (serverOpts , server .Registry (* c .opts .Registry ))
690
+ clientOpts = append (clientOpts , client .Registry (* c .opts .Registry ))
691
+
692
+ if err := (* c .opts .Selector ).Init (selector .Registry (* c .opts .Registry )); err != nil {
693
+ logger .Fatalf ("Error configuring registry: %v" , err )
694
+ }
695
+
696
+ clientOpts = append (clientOpts , client .Selector (* c .opts .Selector ))
697
+
698
+ if err := (* c .opts .Broker ).Init (broker .Registry (* c .opts .Registry )); err != nil {
699
+ logger .Fatalf ("Error configuring broker: %v" , err )
700
+ }
701
+ registry .DefaultRegistry = * c .opts .Registry
702
+ return serverOpts , clientOpts
703
+ }
704
+
705
+ func (c * cmd ) setBroker (b broker.Broker ) ([]server.Option , []client.Option ) {
706
+ var serverOpts []server.Option
707
+ var clientOpts []client.Option
708
+ * c .opts .Broker = b
709
+ serverOpts = append (serverOpts , server .Broker (* c .opts .Broker ))
710
+ clientOpts = append (clientOpts , client .Broker (* c .opts .Broker ))
711
+ broker .DefaultBroker = * c .opts .Broker
712
+ return serverOpts , clientOpts
713
+ }
714
+
715
+ func (c * cmd ) setStore (s store.Store ) ([]server.Option , []client.Option ) {
716
+ var serverOpts []server.Option
717
+ var clientOpts []client.Option
718
+ * c .opts .Store = s
719
+ store .DefaultStore = * c .opts .Store
720
+ return serverOpts , clientOpts
721
+ }
722
+
723
+ func (c * cmd ) setTransport (t transport.Transport ) ([]server.Option , []client.Option ) {
724
+ var serverOpts []server.Option
725
+ var clientOpts []client.Option
726
+ * c .opts .Transport = t
727
+ serverOpts = append (serverOpts , server .Transport (* c .opts .Transport ))
728
+ clientOpts = append (clientOpts , client .Transport (* c .opts .Transport ))
729
+ transport .DefaultTransport = * c .opts .Transport
730
+ return serverOpts , clientOpts
731
+ }
732
+
698
733
func (c * cmd ) Init (opts ... Option ) error {
699
734
for _ , o := range opts {
700
735
o (& c .opts )
0 commit comments