mirror of
https://github.com/itzg/mc-router.git
synced 2024-09-29 04:07:27 +02:00
Simplify fully qualified SRV records for mapping (#92)
Co-authored-by: Geoff Bourne <itzgeoff@gmail.com>
This commit is contained in:
parent
f441b148a1
commit
24381281e7
@ -43,6 +43,8 @@ type Config struct {
|
|||||||
MetricsBackend string `default:"discard" usage:"Backend to use for metrics exposure/publishing: discard,expvar,influxdb"`
|
MetricsBackend string `default:"discard" usage:"Backend to use for metrics exposure/publishing: discard,expvar,influxdb"`
|
||||||
UseProxyProtocol bool `default:"false" usage:"Send PROXY protocol to backend servers"`
|
UseProxyProtocol bool `default:"false" usage:"Send PROXY protocol to backend servers"`
|
||||||
MetricsBackendConfig MetricsBackendConfig
|
MetricsBackendConfig MetricsBackendConfig
|
||||||
|
|
||||||
|
SimplifySRV bool `default:"false" usage:"Simplify fully qualified SRV records for mapping"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -129,6 +131,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server.Routes.SimplifySRV(config.SimplifySRV)
|
||||||
|
|
||||||
err = metricsBuilder.Start(ctx)
|
err = metricsBuilder.Start(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("Unable to start metrics reporter")
|
logrus.WithError(err).Fatal("Unable to start metrics reporter")
|
||||||
|
@ -95,6 +95,7 @@ type IRoutes interface {
|
|||||||
DeleteMapping(serverAddress string) bool
|
DeleteMapping(serverAddress string) bool
|
||||||
CreateMapping(serverAddress string, backend string, waker func(ctx context.Context) error)
|
CreateMapping(serverAddress string, backend string, waker func(ctx context.Context) error)
|
||||||
SetDefaultRoute(backend string)
|
SetDefaultRoute(backend string)
|
||||||
|
SimplifySRV(srvEnabled bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var Routes IRoutes = &routesImpl{}
|
var Routes IRoutes = &routesImpl{}
|
||||||
@ -126,6 +127,7 @@ type routesImpl struct {
|
|||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
mappings map[string]mapping
|
mappings map[string]mapping
|
||||||
defaultRoute string
|
defaultRoute string
|
||||||
|
simplifySRV bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *routesImpl) SetDefaultRoute(backend string) {
|
func (r *routesImpl) SetDefaultRoute(backend string) {
|
||||||
@ -136,10 +138,31 @@ func (r *routesImpl) SetDefaultRoute(backend string) {
|
|||||||
}).Info("Using default route")
|
}).Info("Using default route")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *routesImpl) SimplifySRV(srvEnabled bool) {
|
||||||
|
r.simplifySRV = srvEnabled
|
||||||
|
}
|
||||||
|
|
||||||
func (r *routesImpl) FindBackendForServerAddress(ctx context.Context, serverAddress string) (string, string, func(ctx context.Context) error) {
|
func (r *routesImpl) FindBackendForServerAddress(ctx context.Context, serverAddress string) (string, string, func(ctx context.Context) error) {
|
||||||
r.RLock()
|
r.RLock()
|
||||||
defer r.RUnlock()
|
defer r.RUnlock()
|
||||||
|
|
||||||
|
if r.simplifySRV {
|
||||||
|
serverAddress = strings.TrimSuffix(serverAddress, ".")
|
||||||
|
parts := strings.Split(serverAddress, ".")
|
||||||
|
tcpIndex := -1
|
||||||
|
for i, part := range parts {
|
||||||
|
if part == "_tcp" {
|
||||||
|
tcpIndex = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tcpIndex != -1 {
|
||||||
|
parts = parts[tcpIndex+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
serverAddress = strings.Join(parts, ".")
|
||||||
|
}
|
||||||
|
|
||||||
addressParts := strings.Split(serverAddress, "\x00")
|
addressParts := strings.Split(serverAddress, "\x00")
|
||||||
|
|
||||||
address := strings.ToLower(addressParts[0])
|
address := strings.ToLower(addressParts[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user