From f7bdedc149b743049a57fb513ace0db52bdbc1a6 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Mon, 4 Jul 2016 13:25:45 +0100 Subject: [PATCH] Config struct for memcache client --- app/multitenant/memcache_client.go | 23 ++++++++++++++++------- prog/app.go | 9 +++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/multitenant/memcache_client.go b/app/multitenant/memcache_client.go index 1a4738369..591de0db7 100644 --- a/app/multitenant/memcache_client.go +++ b/app/multitenant/memcache_client.go @@ -53,28 +53,37 @@ type MemcacheClient struct { wait sync.WaitGroup } +// MemcacheConfig defines how a MemcacheClient should be constructed. +type MemcacheConfig struct { + Host string + Timeout time.Duration + Service string + UpdateInterval time.Duration + Expiration int32 +} + // NewMemcacheClient creates a new MemcacheClient that gets its server list // from SRV and updates the server list on a regular basis. -func NewMemcacheClient(host string, timeout time.Duration, service string, updateInterval time.Duration, expiration int32) *MemcacheClient { +func NewMemcacheClient(config MemcacheConfig) *MemcacheClient { var servers memcache.ServerList client := memcache.NewFromSelector(&servers) - client.Timeout = timeout + client.Timeout = config.Timeout newClient := &MemcacheClient{ client: client, serverList: &servers, - expiration: expiration, - hostname: host, - service: service, + expiration: config.Expiration, + hostname: config.Host, + service: config.Service, quit: make(chan struct{}), } err := newClient.updateMemcacheServers() if err != nil { - log.Errorf("Error setting memcache servers to '%v': %v", host, err) + log.Errorf("Error setting memcache servers to '%v': %v", config.Host, err) } newClient.wait.Add(1) - go newClient.updateLoop(updateInterval) + go newClient.updateLoop(config.UpdateInterval) return newClient } diff --git a/prog/app.go b/prog/app.go index a3a02719c..1230c6b5f 100644 --- a/prog/app.go +++ b/prog/app.go @@ -110,8 +110,13 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo var memcacheClient *multitenant.MemcacheClient if memcachedHostname != "" { memcacheClient = multitenant.NewMemcacheClient( - memcachedHostname, memcachedTimeout, memcachedService, - memcacheUpdateInterval, memcacheExpiration, + multitenant.MemcacheConfig{ + Host: memcachedHostname, + Timeout: memcachedTimeout, + Expiration: memcacheExpiration, + UpdateInterval: memcacheUpdateInterval, + Service: memcachedService, + }, ) } awsCollector, err := multitenant.NewAWSCollector(