-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package proxy | ||
|
||
import ( | ||
"github.com/grepplabs/kafka-proxy/config" | ||
"sync/atomic" | ||
) | ||
|
||
const UnknownBrokerID = -1 | ||
|
||
type ProxyListenerConfig struct { | ||
BrokerAddressPtr atomic.Pointer[string] | ||
ListenerAddress string | ||
AdvertisedAddress string | ||
BrokerID int32 | ||
} | ||
|
||
func FromListenerConfig(listenerConfig config.ListenerConfig) *ProxyListenerConfig { | ||
c := &ProxyListenerConfig{ | ||
ListenerAddress: listenerConfig.ListenerAddress, | ||
AdvertisedAddress: listenerConfig.AdvertisedAddress, | ||
BrokerID: UnknownBrokerID, | ||
} | ||
c.BrokerAddressPtr.Store(&listenerConfig.BrokerAddress) | ||
return c | ||
} | ||
|
||
func NewProxyListenerConfig(brokerAddress, listenerAddress, advertisedAddress string, brokerID int32) *ProxyListenerConfig { | ||
c := &ProxyListenerConfig{ | ||
ListenerAddress: listenerAddress, | ||
AdvertisedAddress: advertisedAddress, | ||
BrokerID: brokerID, | ||
} | ||
c.BrokerAddressPtr.Store(&brokerAddress) | ||
return c | ||
} | ||
func (c *ProxyListenerConfig) ToListenerConfig() config.ListenerConfig { | ||
return config.ListenerConfig{ | ||
BrokerAddress: c.GetBrokerAddress(), | ||
ListenerAddress: c.ListenerAddress, | ||
AdvertisedAddress: c.AdvertisedAddress, | ||
} | ||
} | ||
|
||
func (c *ProxyListenerConfig) GetBrokerAddress() string { | ||
addressPtr := c.BrokerAddressPtr.Load() | ||
if addressPtr == nil { | ||
return "" | ||
} | ||
return *addressPtr | ||
} | ||
|
||
func (c *ProxyListenerConfig) SetBrokerAddress(address string) { | ||
c.BrokerAddressPtr.Store(&address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters