Skip to content

Commit

Permalink
Refactor seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
mantzas committed Oct 13, 2024
1 parent 61ffbd5 commit 2a6433a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions seed/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,18 @@ func (s *Seeder) Seed(cfg *config.Config) error {
var flagInfos []*flagInfo
for _, f := range cfg.Fields {
seedMap[f] = false
ss := f.Sources()
val, ok := ss[config.SourceSeed]
if ok {
err := f.Set(val, 0)
if err != nil {
return err
}
slog.Debug("seed applied", "value", f, "name", f.Name())
seedMap[f] = true

err := processSeedField(f, seedMap)
if err != nil {
return err
}

err := processEnvField(f, seedMap)
err = processEnvField(f, seedMap)
if err != nil {
return err
}

key, ok := ss[config.SourceFlag]
key, ok := f.Sources()[config.SourceFlag]
if ok {
var val string
flagSet.StringVar(&val, key, "", "")
Expand Down Expand Up @@ -149,6 +144,20 @@ func (s *Seeder) Seed(cfg *config.Config) error {
return nil
}

func processSeedField(f *config.Field, seedMap map[*config.Field]bool) error {
val, ok := f.Sources()[config.SourceSeed]
if !ok {
return nil
}
err := f.Set(val, 0)
if err != nil {
return err
}
slog.Debug("seed applied", "value", f, "name", f.Name())
seedMap[f] = true
return nil
}

func processEnvField(f *config.Field, seedMap map[*config.Field]bool) error {
key, ok := f.Sources()[config.SourceEnv]
if !ok {
Expand Down

0 comments on commit 2a6433a

Please sign in to comment.