11package config
22
33import (
4+ "bytes"
5+ "encoding/json"
46 "fmt"
57 "time"
68
@@ -10,18 +12,18 @@ import (
1012
1113// Settings holds all CLI-configurable parameters
1214type Settings struct {
13- Workers int `json:"workers"`
14- TPS float64 `json:"tps"`
15- StatsInterval Duration `json:"statsInterval"`
16- BufferSize int `json:"bufferSize"`
17- DryRun bool `json:"dryRun"`
18- Debug bool `json:"debug"`
19- TrackReceipts bool `json:"trackReceipts"`
20- TrackBlocks bool `json:"trackBlocks"`
21- TrackUserLatency bool `json:"trackUserLatency"`
22- Prewarm bool `json:"prewarm"`
23- RampUp bool `json:"rampUp"`
24- ReportPath string `json:"reportPath"`
15+ Workers int `json:"workers,omitempty "`
16+ TPS float64 `json:"tps,omitempty "`
17+ StatsInterval Duration `json:"statsInterval,omitempty "`
18+ BufferSize int `json:"bufferSize,omitempty "`
19+ DryRun bool `json:"dryRun,omitempty "`
20+ Debug bool `json:"debug,omitempty "`
21+ TrackReceipts bool `json:"trackReceipts,omitempty "`
22+ TrackBlocks bool `json:"trackBlocks,omitempty "`
23+ TrackUserLatency bool `json:"trackUserLatency,omitempty "`
24+ Prewarm bool `json:"prewarm,omitempty "`
25+ RampUp bool `json:"rampUp,omitempty "`
26+ ReportPath string `json:"reportPath,omitempty "`
2527}
2628
2729// DefaultSettings returns the default configuration values
@@ -83,15 +85,21 @@ func InitializeViper(cmd *cobra.Command) error {
8385 return nil
8486}
8587
86- // LoadConfigFile reads and merges the config file into Viper
87- func LoadConfigFile ( configFile string ) error {
88- if configFile == "" {
89- return fmt .Errorf ("config file path is required" )
88+ // LoadSettings reads and merges the config file into Viper
89+ func LoadSettings ( settings * Settings ) error {
90+ if settings == nil {
91+ return fmt .Errorf ("config settings are required" )
9092 }
9193
92- viper .SetConfigFile (configFile )
93- if err := viper .ReadInConfig (); err != nil {
94- return fmt .Errorf ("failed to read config file %s: %w" , configFile , err )
94+ // settings converted to JSON bytes
95+ settingsJSON , err := json .Marshal (settings )
96+ if err != nil {
97+ return fmt .Errorf ("failed to marshal settings: %w" , err )
98+ }
99+
100+ viper .SetConfigType ("json" )
101+ if err := viper .ReadConfig (bytes .NewBuffer (settingsJSON )); err != nil {
102+ return fmt .Errorf ("failed to read config: %w" , err )
95103 }
96104
97105 return nil
0 commit comments