Skip to content

Commit

Permalink
update: allow config builder skip transport module (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaukas authored Mar 15, 2024
1 parent 593f80a commit ec93ace
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ec93ace

Please sign in to comment.