add storage-groupsprovider

This commit is contained in:
A.Unger
2021-03-04 15:00:02 +01:00
parent 255fc4bc92
commit 40ff29403f
3 changed files with 43 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package command
import (
"context"
"flag"
"os"
"os/signal"
"path"
@@ -204,3 +205,43 @@ func Groups(cfg *config.Config) *cli.Command {
},
}
}
// GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree.
type GroupsProvider struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewGroupsProvider creates a new storage.GroupsProvider
func NewGroupsProvider(ctx context.Context, cfg *config.Config) GroupsProvider {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx
return GroupsProvider{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s GroupsProvider) Serve() {
f := &flag.FlagSet{}
for k := range Groups(s.cfg).Flags {
if err := Groups(s.cfg).Flags[k].Apply(f); err != nil {
return
}
}
ctx := cli.NewContext(nil, f, nil)
if Groups(s.cfg).Before != nil {
if err := Groups(s.cfg).Before(ctx); err != nil {
return
}
}
if err := Groups(s.cfg).Action(ctx); err != nil {
return
}
}
func (s GroupsProvider) Stop() {
s.cancel()
}

View File

@@ -214,7 +214,7 @@ type UsersProviderService struct {
cfg *config.Config
}
// NewUsersProviderService creates a new gateway.UsersProviderService
// NewUsersProviderService creates a new storage.UsersProviderService
func NewUsersProviderService(ctx context.Context, cfg *config.Config) UsersProviderService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx