Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions subrpcserver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
case *switchrpc.Config:
subCfgValue := extractReflectValue(subCfg)

subCfgValue.FieldByName("NetworkDir").Set(
reflect.ValueOf(networkDir),
)
subCfgValue.FieldByName("MacService").Set(
reflect.ValueOf(macService),
)
Comment on lines +324 to +329
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this is consistent with the rest of the function, using reflection with FieldByName is brittle and can lead to runtime panics if the field names in the switchrpc.Config struct are ever changed.

Since the subCfg variable is already typed as *switchrpc.Config, you can set the fields directly for better type safety and readability.

This would be a good refactoring to apply to the other cases in this function as well.

            subCfg.NetworkDir = networkDir
            subCfg.MacService = macService


subCfgValue.FieldByName("HtlcDispatcher").Set(
reflect.ValueOf(htlcSwitch),
)
Expand Down
Loading