-
-
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
119 additions
and
77 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 ListenerConfig struct { | ||
BrokerAddressPtr atomic.Pointer[string] | ||
ListenerAddress string | ||
AdvertisedAddress string | ||
BrokerID int32 | ||
} | ||
|
||
func FromListenerConfig(listenerConfig config.ListenerConfig) *ListenerConfig { | ||
c := &ListenerConfig{ | ||
ListenerAddress: listenerConfig.ListenerAddress, | ||
AdvertisedAddress: listenerConfig.AdvertisedAddress, | ||
BrokerID: UnknownBrokerID, | ||
} | ||
c.BrokerAddressPtr.Store(&listenerConfig.BrokerAddress) | ||
return c | ||
} | ||
|
||
func NewListenerConfig(brokerAddress, listenerAddress, advertisedAddress string, brokerID int32) *ListenerConfig { | ||
c := &ListenerConfig{ | ||
ListenerAddress: listenerAddress, | ||
AdvertisedAddress: advertisedAddress, | ||
BrokerID: brokerID, | ||
} | ||
c.BrokerAddressPtr.Store(&brokerAddress) | ||
return c | ||
} | ||
func (c *ListenerConfig) ToListenerConfig() config.ListenerConfig { | ||
return config.ListenerConfig{ | ||
BrokerAddress: c.GetBrokerAddress(), | ||
ListenerAddress: c.ListenerAddress, | ||
AdvertisedAddress: c.AdvertisedAddress, | ||
} | ||
} | ||
|
||
func (c *ListenerConfig) GetBrokerAddress() string { | ||
addressPtr := c.BrokerAddressPtr.Load() | ||
if addressPtr == nil { | ||
return "" | ||
} | ||
return *addressPtr | ||
} | ||
|
||
func (c *ListenerConfig) 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