@@ -128,15 +128,7 @@ func (c *EndpointConfig) OrderersConfig() []fab.OrdererConfig {
128128
129129// OrdererConfig returns the requested orderer
130130func (c * EndpointConfig ) OrdererConfig (nameOrURL string ) (* fab.OrdererConfig , bool ) {
131-
132- matchingOrdererConfig := c .tryMatchingOrdererConfig (nameOrURL , true )
133-
134- if matchingOrdererConfig == nil {
135- logger .Debugf ("Could not find Orderer for [%s] " , nameOrURL )
136- return nil , false
137- }
138-
139- return matchingOrdererConfig , true
131+ return c .tryMatchingOrdererConfig (nameOrURL , true )
140132}
141133
142134// PeersConfig Retrieves the fabric peers for the specified org from the
@@ -148,14 +140,7 @@ func (c *EndpointConfig) PeersConfig(org string) ([]fab.PeerConfig, bool) {
148140
149141// PeerConfig Retrieves a specific peer from the configuration by name or url
150142func (c * EndpointConfig ) PeerConfig (nameOrURL string ) (* fab.PeerConfig , bool ) {
151-
152- matchPeerConfig := c .tryMatchingPeerConfig (nameOrURL , true )
153- if matchPeerConfig == nil {
154- logger .Debugf ("Could not find Peer for [%s] " , nameOrURL )
155- return nil , false
156- }
157-
158- return matchPeerConfig , true
143+ return c .tryMatchingPeerConfig (nameOrURL , true )
159144}
160145
161146// NetworkConfig returns the network configuration defined in the config file
@@ -914,8 +899,8 @@ func (c *EndpointConfig) loadPeerConfigsByOrg() {
914899 peers := []fab.PeerConfig {}
915900
916901 for _ , peerName := range orgPeers {
917- p := c .tryMatchingPeerConfig (peerName , false )
918- if p == nil {
902+ p , ok := c .tryMatchingPeerConfig (peerName , false )
903+ if ! ok {
919904 continue
920905 }
921906
@@ -953,8 +938,8 @@ func (c *EndpointConfig) loadOrdererConfigs() error {
953938 ordererConfigs := []fab.OrdererConfig {}
954939 for name := range c .networkConfig .Orderers {
955940
956- matchedOrderer := c .tryMatchingOrdererConfig (name , false )
957- if matchedOrderer == nil {
941+ matchedOrderer , ok := c .tryMatchingOrdererConfig (name , false )
942+ if ! ok {
958943 continue
959944 }
960945
@@ -979,8 +964,8 @@ func (c *EndpointConfig) loadChannelPeers() error {
979964 for channelID , channelConfig := range c .networkConfig .Channels {
980965 peers := []fab.ChannelPeer {}
981966 for peerName , chPeerConfig := range channelConfig .Peers {
982- p := c .tryMatchingPeerConfig (strings .ToLower (peerName ), false )
983- if p == nil {
967+ p , ok := c .tryMatchingPeerConfig (strings .ToLower (peerName ), false )
968+ if ! ok {
984969 continue
985970 }
986971
@@ -1016,8 +1001,8 @@ func (c *EndpointConfig) loadChannelOrderers() error {
10161001 orderers := []fab.OrdererConfig {}
10171002 for _ , ordererName := range channelConfig .Orderers {
10181003
1019- orderer := c .tryMatchingOrdererConfig (strings .ToLower (ordererName ), false )
1020- if orderer == nil {
1004+ orderer , ok := c .tryMatchingOrdererConfig (strings .ToLower (ordererName ), false )
1005+ if ! ok {
10211006 return errors .Errorf ("Could not find Orderer Config for channel orderer [%s]" , ordererName )
10221007 }
10231008 orderers = append (orderers , * orderer )
@@ -1102,7 +1087,7 @@ func (c *EndpointConfig) isOrdererToBeIgnored(ordererName string) bool {
11021087 return false
11031088}
11041089
1105- func (c * EndpointConfig ) tryMatchingPeerConfig (peerSearchKey string , searchByURL bool ) * fab.PeerConfig {
1090+ func (c * EndpointConfig ) tryMatchingPeerConfig (peerSearchKey string , searchByURL bool ) ( * fab.PeerConfig , bool ) {
11061091
11071092 //loop over peer entity matchers to find the matching peer
11081093 for _ , matcher := range c .peerMatchers {
@@ -1115,14 +1100,14 @@ func (c *EndpointConfig) tryMatchingPeerConfig(peerSearchKey string, searchByURL
11151100 //direct lookup if peer matchers are not configured or no matchers matched
11161101 peerConfig , ok := c .networkConfig .Peers [strings .ToLower (peerSearchKey )]
11171102 if ok {
1118- return & peerConfig
1103+ return & peerConfig , true
11191104 }
11201105
11211106 if searchByURL {
11221107 //lookup by URL
11231108 for _ , staticPeerConfig := range c .networkConfig .Peers {
11241109 if strings .EqualFold (staticPeerConfig .URL , peerSearchKey ) {
1125- return & staticPeerConfig
1110+ return & staticPeerConfig , true
11261111 }
11271112 }
11281113 }
@@ -1136,22 +1121,22 @@ func (c *EndpointConfig) tryMatchingPeerConfig(peerSearchKey string, searchByURL
11361121 // }
11371122 //}
11381123
1139- return nil
1124+ return nil , false
11401125}
11411126
1142- func (c * EndpointConfig ) matchPeer (peerSearchKey string , matcher matcherEntry ) * fab.PeerConfig {
1127+ func (c * EndpointConfig ) matchPeer (peerSearchKey string , matcher matcherEntry ) ( * fab.PeerConfig , bool ) {
11431128
11441129 if matcher .matchConfig .IgnoreEndpoint {
11451130 logger .Debugf (" Ignoring peer `%s` since entity matcher IgnoreEndpoint flag is on" , peerSearchKey )
1146- return nil
1131+ return nil , false
11471132 }
11481133
11491134 mappedHost := c .regexMatchAndReplace (matcher .regex , peerSearchKey , matcher .matchConfig .MappedHost )
11501135
11511136 matchedPeer := c .getMappedPeer (mappedHost )
11521137 if matchedPeer == nil {
11531138 logger .Debugf ("Could not find mapped host [%s] for peer [%s]" , matcher .matchConfig .MappedHost , peerSearchKey )
1154- return nil
1139+ return nil , false
11551140 }
11561141
11571142 //URLSubstitutionExp if found use from entity matcher otherwise use from mapped host
@@ -1174,7 +1159,7 @@ func (c *EndpointConfig) matchPeer(peerSearchKey string, matcher matcherEntry) *
11741159 matchedPeer .URL = c .getDefaultMatchingURL (peerSearchKey )
11751160 }
11761161
1177- return matchedPeer
1162+ return matchedPeer , true
11781163}
11791164
11801165//getDefaultMatchingURL if search key is a URL then returns search key as URL otherwise returns empty
@@ -1206,7 +1191,7 @@ func (c *EndpointConfig) getMappedPeer(host string) *fab.PeerConfig {
12061191 return & mappedConfig
12071192}
12081193
1209- func (c * EndpointConfig ) tryMatchingOrdererConfig (ordererSearchKey string , searchByURL bool ) * fab.OrdererConfig {
1194+ func (c * EndpointConfig ) tryMatchingOrdererConfig (ordererSearchKey string , searchByURL bool ) ( * fab.OrdererConfig , bool ) {
12101195
12111196 //loop over orderer entity matchers to find the matching orderer
12121197 for _ , matcher := range c .ordererMatchers {
@@ -1219,14 +1204,14 @@ func (c *EndpointConfig) tryMatchingOrdererConfig(ordererSearchKey string, searc
12191204 //direct lookup if orderer matchers are not configured or no matchers matched
12201205 orderer , ok := c .networkConfig .Orderers [strings .ToLower (ordererSearchKey )]
12211206 if ok {
1222- return & orderer
1207+ return & orderer , true
12231208 }
12241209
12251210 if searchByURL {
12261211 //lookup by URL
12271212 for _ , ordererCfg := range c .OrderersConfig () {
12281213 if strings .EqualFold (ordererCfg .URL , ordererSearchKey ) {
1229- return & ordererCfg
1214+ return & ordererCfg , true
12301215 }
12311216 }
12321217 }
@@ -1240,14 +1225,14 @@ func (c *EndpointConfig) tryMatchingOrdererConfig(ordererSearchKey string, searc
12401225 // }
12411226 //}
12421227
1243- return nil
1228+ return nil , false
12441229}
12451230
1246- func (c * EndpointConfig ) matchOrderer (ordererSearchKey string , matcher matcherEntry ) * fab.OrdererConfig {
1231+ func (c * EndpointConfig ) matchOrderer (ordererSearchKey string , matcher matcherEntry ) ( * fab.OrdererConfig , bool ) {
12471232
12481233 if matcher .matchConfig .IgnoreEndpoint {
12491234 logger .Debugf (" Ignoring peer `%s` since entity matcher IgnoreEndpoint flag is on" , ordererSearchKey )
1250- return nil
1235+ return nil , false
12511236 }
12521237
12531238 mappedHost := c .regexMatchAndReplace (matcher .regex , ordererSearchKey , matcher .matchConfig .MappedHost )
@@ -1256,7 +1241,7 @@ func (c *EndpointConfig) matchOrderer(ordererSearchKey string, matcher matcherEn
12561241 matchedOrderer := c .getMappedOrderer (mappedHost )
12571242 if matchedOrderer == nil {
12581243 logger .Debugf ("Could not find mapped host [%s] for orderer [%s]" , matcher .matchConfig .MappedHost , ordererSearchKey )
1259- return nil
1244+ return nil , false
12601245 }
12611246
12621247 //URLSubstitutionExp if found use from entity matcher otherwise use from mapped host
@@ -1274,7 +1259,7 @@ func (c *EndpointConfig) matchOrderer(ordererSearchKey string, matcher matcherEn
12741259 matchedOrderer .URL = c .getDefaultMatchingURL (ordererSearchKey )
12751260 }
12761261
1277- return matchedOrderer
1262+ return matchedOrderer , true
12781263}
12791264
12801265func (c * EndpointConfig ) getMappedOrderer (host string ) * fab.OrdererConfig {
0 commit comments