address_translators.go 955 B

1234567891011121314151617181920212223242526
  1. package gocql
  2. import "net"
  3. // AddressTranslator provides a way to translate node addresses (and ports) that are
  4. // discovered or received as a node event. This can be useful in an ec2 environment,
  5. // for instance, to translate public IPs to private IPs.
  6. type AddressTranslator interface {
  7. // Translate will translate the provided address and/or port to another
  8. // address and/or port. If no translation is possible, Translate will return the
  9. // address and port provided to it.
  10. Translate(addr net.IP, port int) (net.IP, int)
  11. }
  12. type AddressTranslatorFunc func(addr net.IP, port int) (net.IP, int)
  13. func (fn AddressTranslatorFunc) Translate(addr net.IP, port int) (net.IP, int) {
  14. return fn(addr, port)
  15. }
  16. // IdentityTranslator will do nothing but return what it was provided. It is essentially a no-op.
  17. func IdentityTranslator() AddressTranslator {
  18. return AddressTranslatorFunc(func(addr net.IP, port int) (net.IP, int) {
  19. return addr, port
  20. })
  21. }