Skip to content

Commit

Permalink
refactor: reduce number of args
Browse files Browse the repository at this point in the history
  • Loading branch information
rade committed Jul 26, 2017
1 parent 3ab48bc commit 6c4efbb
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions prog/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func awsConfigFromURL(url *url.URL) (*aws.Config, error) {
return config, nil
}

func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHostname, memcachedHostname string, memcachedTimeout time.Duration, memcachedService string, memcachedExpiration time.Duration, memcachedCompressionLevel int, window time.Duration, createTables bool) (app.Collector, error) {
func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHostname string,
memcacheConfig multitenant.MemcacheConfig, window time.Duration, createTables bool) (app.Collector, error) {
if collectorURL == "local" {
return app.NewCollector(window), nil
}
Expand Down Expand Up @@ -121,17 +122,8 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo
tableName := strings.TrimPrefix(parsed.Path, "/")
s3Store := multitenant.NewS3Client(s3Config, bucketName)
var memcacheClient *multitenant.MemcacheClient
if memcachedHostname != "" {
memcacheClient = multitenant.NewMemcacheClient(
multitenant.MemcacheConfig{
Host: memcachedHostname,
Timeout: memcachedTimeout,
Expiration: memcachedExpiration,
UpdateInterval: memcacheUpdateInterval,
Service: memcachedService,
CompressionLevel: memcachedCompressionLevel,
},
)
if memcacheConfig.Host != "" {
memcacheClient = multitenant.NewMemcacheClient(memcacheConfig)
}
awsCollector, err := multitenant.NewAWSCollector(
multitenant.AWSCollectorConfig{
Expand Down Expand Up @@ -238,8 +230,15 @@ func appMain(flags appFlags) {
}

collector, err := collectorFactory(
userIDer, flags.collectorURL, flags.s3URL, flags.natsHostname, flags.memcachedHostname,
flags.memcachedTimeout, flags.memcachedService, flags.memcachedExpiration, flags.memcachedCompressionLevel,
userIDer, flags.collectorURL, flags.s3URL, flags.natsHostname,
multitenant.MemcacheConfig{
Host: flags.memcachedHostname,
Timeout: flags.memcachedTimeout,
Expiration: flags.memcachedExpiration,
UpdateInterval: memcacheUpdateInterval,
Service: flags.memcachedService,
CompressionLevel: flags.memcachedCompressionLevel,
},
flags.window, flags.awsCreateTables)
if err != nil {
log.Fatalf("Error creating collector: %v", err)
Expand Down

0 comments on commit 6c4efbb

Please sign in to comment.