Skip to content

Commit eed9826

Browse files
committed
feat: re-add profiles
1 parent a03ab5f commit eed9826

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

cmd/cmd.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cmd
44
import (
55
"fmt"
66
"math/rand"
7+
"os"
78
"sort"
89
"strings"
910
"time"
@@ -32,6 +33,7 @@ import (
3233
"go-micro.dev/v5/store"
3334
"go-micro.dev/v5/store/mysql"
3435
"go-micro.dev/v5/transport"
36+
profileconfig "go-micro.dev/v5/profileconfig"
3537
)
3638

3739
type Cmd interface {
@@ -437,6 +439,32 @@ func (c *cmd) Before(ctx *cli.Context) error {
437439
}
438440
}
439441

442+
// --- Profile Grouping Extension ---
443+
// Check for new profile flag/env (not just debug profiler)
444+
profileName := ctx.String("profile")
445+
if profileName == "" {
446+
profileName = os.Getenv("MICRO_PROFILE")
447+
}
448+
if profileName != "" {
449+
switch profileName {
450+
case "local":
451+
imported := profileconfig.LocalProfile()
452+
*c.opts.Registry = imported.Registry
453+
*c.opts.Broker = imported.Broker
454+
*c.opts.Store = imported.Store
455+
*c.opts.Transport = imported.Transport
456+
case "nats":
457+
imported := profileconfig.NatsProfile()
458+
*c.opts.Registry = imported.Registry
459+
*c.opts.Broker = imported.Broker
460+
*c.opts.Store = imported.Store
461+
*c.opts.Transport = imported.Transport
462+
// Add more profiles as needed
463+
default:
464+
return fmt.Errorf("unsupported profile: %s", profileName)
465+
}
466+
}
467+
440468
// Set the profile
441469
if name := ctx.String("profile"); len(name) > 0 {
442470
p, ok := c.opts.Profiles[name]

profile.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Package profileconfig provides grouped plugin profiles for go-micro
2+
package profileconfig
3+
4+
import (
5+
"os"
6+
"go-micro.dev/v5/broker"
7+
"go-micro.dev/v5/broker/http"
8+
"go-micro.dev/v5/broker/nats"
9+
"go-micro.dev/v5/registry"
10+
"go-micro.dev/v5/registry/mdns"
11+
"go-micro.dev/v5/registry/nats"
12+
"go-micro.dev/v5/store"
13+
"go-micro.dev/v5/store/file"
14+
"go-micro.dev/v5/transport"
15+
"go-micro.dev/v5/transport/http"
16+
)
17+
18+
type ProfileConfig struct {
19+
Registry registry.Registry
20+
Broker broker.Broker
21+
Store store.Store
22+
Transport transport.Transport
23+
}
24+
25+
func LocalProfile() ProfileConfig {
26+
return ProfileConfig{
27+
Registry: mdns.NewRegistry(),
28+
Broker: http.NewBroker(),
29+
Store: file.NewStore(),
30+
Transport: http.NewTransport(),
31+
}
32+
}
33+
34+
func NatsProfile() ProfileConfig {
35+
addr := os.Getenv("MICRO_NATS_ADDRESS")
36+
return ProfileConfig{
37+
Registry: nats.NewRegistry(registry.Addrs(addr)),
38+
Broker: nats.NewBroker(broker.Addrs(addr)),
39+
Store: file.NewStore(), // or nats-backed store if available
40+
Transport: http.NewTransport(), // or nats transport if available
41+
}
42+
}
43+
44+
// Add more profiles as needed, e.g. grpc

0 commit comments

Comments
 (0)