From ec93aced5a8f0285f8adde675c40554cf5ac616c Mon Sep 17 00:00:00 2001 From: Gaukas Wang Date: Fri, 15 Mar 2024 09:49:47 -0600 Subject: [PATCH] update: allow config builder skip transport module (#62) --- config.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/config.go b/config.go index 53e60de..0329ed8 100644 --- a/config.go +++ b/config.go @@ -167,13 +167,17 @@ func (c *Config) UnmarshalJSON(data []byte) error { return err } - tmBin, err := os.ReadFile(confJson.TransportModule.BinPath) - if err != nil { - return err + // Load TMBin if not already set + if c.TransportModuleBin == nil { + tmBin, err := os.ReadFile(confJson.TransportModule.BinPath) + if err != nil { + return err + } + c.TransportModuleBin = tmBin } - c.TransportModuleBin = tmBin - if len(confJson.TransportModule.ConfigPath) > 0 { + // Load TMConfig if not already set + if c.TransportModuleConfig == nil && len(confJson.TransportModule.ConfigPath) > 0 { c.TransportModuleConfig, err = TransportModuleConfigFromFile(confJson.TransportModule.ConfigPath) if err != nil { return err @@ -244,14 +248,18 @@ func (c *Config) UnmarshalProto(b []byte) error { return err } - // Parse TransportModuleBin - c.TransportModuleBin = confProto.GetTransportModule().GetBin() - if len(c.TransportModuleBin) == 0 { - return errors.New("water: transport module binary is not provided in config") + // Parse TransportModuleBin if not already set + if c.TransportModuleBin == nil { + c.TransportModuleBin = confProto.GetTransportModule().GetBin() + if len(c.TransportModuleBin) == 0 { + return errors.New("water: transport module binary is not provided in config") + } } - // Parse TransportModuleConfig - c.TransportModuleConfig = TransportModuleConfigFromBytes(confProto.GetTransportModule().GetConfig()) + // Parse TransportModuleConfig if not already set + if c.TransportModuleConfig == nil { + c.TransportModuleConfig = TransportModuleConfigFromBytes(confProto.GetTransportModule().GetConfig()) + } // Parse NetworkListener listenerNetwork, listenerAddress := confProto.GetNetwork().GetListener().GetNetwork(), confProto.GetNetwork().GetListener().GetAddress()