Repository: allegro/marathon-consul
Pull request #293 (2019-07-12 12:13:15)

Upgrade linter to golangci-lint, bump Go to 1.12 for Travis
Remove deprecated gometalinter

coveralls: 
[![Coverage Status](https://coveralls.io/builds/24529516/badge)](https://coveralls.io/builds/24529516)

Coverage remained the same at 90.61% when pulling **a8cdb6fcaaad6ec511ffce748b680b8e1251aa05 on AlfredBroda:feature/linter-upgrade** into **149a59e4e26d44cbaa7d28c6792107a919d26a51 on allegro:master**.


Patch:
diff --git a/.travis.yml b/.travis.yml
index fca7cfb..7e02437 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,7 @@ dist: trusty
 sudo: false
 
 go:
-  - 1.9
+  - 1.12
 before_install:
   - gem install fpm
   - go get github.com/mattn/goveralls
diff --git a/Makefile b/Makefile
index 44be0b4..3541a03 100644
--- a/Makefile
+++ b/Makefile
@@ -32,11 +32,11 @@ deps:
 	@which goimports > /dev/null || \
         (go get golang.org/x/tools/cmd/goimports)
 
-build-deps: deps format test check
+build-deps: deps format
 	@mkdir -p bin/
 
-build: build-deps
-	go build $(LD_FLAGS) -o bin/marathon-consul
+build: check build-deps test
+	CGO_ENABLED=0 go build $(LD_FLAGS) -o bin/marathon-consul
 
 build-linux: build-deps
 	CGO_ENABLED=0 GOOS=linux go build -a -tags netgo $(LD_FLAGS) -o bin/marathon-consul
@@ -51,11 +51,11 @@ $(TEST_TARGETS):
 	go test -coverprofile=coverage/$(shell basename $@).coverprofile $(TESTARGS) $@
 
 check-deps: deps
-	@which gometalinter > /dev/null || \
-        (go get github.com/alecthomas/gometalinter && gometalinter --install)
+	@which golangci-lint > /dev/null || \
+		(go get -u github.com/golangci/golangci-lint/cmd/golangci-lint)
 
-check: check-deps $(SOURCES) test
-	gometalinter ./... --deadline  720s --vendor -D dupl -D gotype -D errcheck -D gas -D golint -D aligncheck -D vetshadow -D maligned -D gosec -E gofmt
+check: check-deps $(SOURCES)
+	golangci-lint run --config=golangcilinter.yaml ./...
 
 format:
 	goimports -w -l $(APP_SOURCES)
diff --git a/apps/app.go b/apps/app.go
index 9d62ccd..369248d 100644
--- a/apps/app.go
+++ b/apps/app.go
@@ -190,6 +190,6 @@ func (app App) extractPortDefinitions() []PortDefinition {
 	} else {
 		appPortDefinitions = app.PortDefinitions
 	}
-	
+
 	return appPortDefinitions
 }
diff --git a/consul/consul.go b/consul/consul.go
index d0d91ab..601306e 100644
--- a/consul/consul.go
+++ b/consul/consul.go
@@ -6,12 +6,13 @@ import (
 	"net/url"
 	"strings"
 
+	consulAPI "github.com/hashicorp/consul/api"
+	log "github.com/sirupsen/logrus"
+
 	"github.com/allegro/marathon-consul/apps"
 	"github.com/allegro/marathon-consul/metrics"
 	"github.com/allegro/marathon-consul/service"
 	"github.com/allegro/marathon-consul/utils"
-	consulapi "github.com/hashicorp/consul/api"
-	log "github.com/sirupsen/logrus"
 )
 
 type Consul struct {
@@ -20,7 +21,7 @@ type Consul struct {
 	ignoredHealthCheckTypes []string
 }
 
-type ServicesProvider func(agent *consulapi.Client) ([]*service.Service, error)
+type ServicesProvider func(agent *consulAPI.Client) ([]*service.Service, error)
 
 func New(config Config) *Consul {
 	return &Consul{
@@ -31,7 +32,7 @@ func New(config Config) *Consul {
 }
 
 func (c *Consul) GetServices(name string) ([]*service.Service, error) {
-	return c.getServicesUsingProviderWithRetriesOnAgentFailure(func(agent *consulapi.Client) ([]*service.Service, error) {
+	return c.getServicesUsingProviderWithRetriesOnAgentFailure(func(agent *consulAPI.Client) ([]*service.Service, error) {
 		return c.getServicesUsingAgent(name, agent)
 	})
 }
@@ -62,7 +63,7 @@ func (c *Consul) getServicesUsingProviderWithRetriesOnAgentFailure(provide Servi
 	return nil, errors.New("An error occurred getting services from Consul. Giving up")
 }
 
-func (c *Consul) getServicesUsingAgent(name string, agent *consulapi.Client) ([]*service.Service, error) {
+func (c *Consul) getServicesUsingAgent(name string, agent *consulAPI.Client) ([]*service.Service, error) {
 	dcAwareQueries, err := dcAwareQueriesForAllDCs(agent)
 	if err != nil {
 		return nil, err
@@ -79,15 +80,15 @@ func (c *Consul) getServicesUsingAgent(name string, agent *consulapi.Client) ([]
 	return allServices, nil
 }
 
-func dcAwareQueriesForAllDCs(agent *consulapi.Client) ([]*consulapi.QueryOptions, error) {
+func dcAwareQueriesForAllDCs(agent *consulAPI.Client) ([]*consulAPI.QueryOptions, error) {
 	datacenters, err := agent.Catalog().Datacenters()
 	if err != nil {
 		return nil, err
 	}
 
-	var queries []*consulapi.QueryOptions
+	var queries []*consulAPI.QueryOptions
 	for _, dc := range datacenters {
-		queries = append(queries, &consulapi.QueryOptions{
+		queries = append(queries, &consulAPI.QueryOptions{
 			Datacenter: dc,
 		})
 	}
@@ -99,7 +100,7 @@ func (c *Consul) GetAllServices() ([]*service.Service, error) {
 	return c.getServicesUsingProviderWithRetriesOnAgentFailure(c.getAllServices)
 }
 
-func (c *Consul) getAllServices(agent *consulapi.Client) ([]*service.Service, error) {
+func (c *Consul) getAllServices(agent *consulAPI.Client) ([]*service.Service, error) {
 	dcAwareQueries, err := dcAwareQueriesForAllDCs(agent)
 	if err != nil {
 		return nil, err
@@ -124,17 +125,17 @@ func (c *Consul) getAllServices(agent *consulapi.Client) ([]*service.Service, er
 	return allInstances, nil
 }
 
-func consulServiceToService(consulService *consulapi.CatalogService) *service.Service {
+func consulServiceToService(consulService *consulAPI.CatalogService) *service.Service {
 	return &service.Service{
-		ID:   service.ServiceId(consulService.ServiceID),
-		Name: consulService.ServiceName,
-		Tags: consulService.ServiceTags,
-		RegisteringAgentAddress: consulService.Address,
-		EnableTagOverride:       consulService.ServiceEnableTagOverride,
+		ID:                service.ID(consulService.ServiceID),
+		Name:              consulService.ServiceName,
+		Tags:              consulService.ServiceTags,
+		AgentAddress:      consulService.Address,
+		EnableTagOverride: consulService.ServiceEnableTagOverride,
 	}
 }
 
-func consulServicesToServices(consulServices []*consulapi.CatalogService) []*service.Service {
+func consulServicesToServices(consulServices []*consulAPI.CatalogService) []*service.Service {
 	var allServices []*service.Service
 	for _, c := range consulServices {
 		allServices = append(allServices, consulServiceToService(c))
@@ -168,7 +169,7 @@ func (c *Consul) Register(task *apps.Task, app *apps.App) error {
 	return err
 }
 
-func (c *Consul) registerMultipleServices(services []*consulapi.AgentServiceRegistration) error {
+func (c *Consul) registerMultipleServices(services []*consulAPI.AgentServiceRegistration) error {
 	var registerErrors []error
 	for _, s := range services {
 		registerErr := c.register(s)
@@ -180,7 +181,7 @@ func (c *Consul) registerMultipleServices(services []*consulapi.AgentServiceRegi
 	return utils.MergeErrorsOrNil(registerErrors, "registering services")
 }
 
-func (c *Consul) register(service *consulapi.AgentServiceRegistration) error {
+func (c *Consul) register(service *consulAPI.AgentServiceRegistration) error {
 	agent, err := c.agents.GetAgent(service.Address)
 	if err != nil {
 		return err
@@ -229,7 +230,7 @@ func (c *Consul) deregisterMultipleServices(services []*service.Service, taskID
 }
 
 func (c *Consul) findServicesByTaskID(searchedTaskID apps.TaskID) ([]*service.Service, error) {
-	return c.getServicesUsingProviderWithRetriesOnAgentFailure(func(agent *consulapi.Client) ([]*service.Service, error) {
+	return c.getServicesUsingProviderWithRetriesOnAgentFailure(func(agent *consulAPI.Client) ([]*service.Service, error) {
 		dcAwareQueries, err := dcAwareQueriesForAllDCs(agent)
 		if err != nil {
 			return nil, err
@@ -268,23 +269,23 @@ func (c *Consul) Deregister(toDeregister *service.Service) error {
 }
 
 func (c *Consul) deregister(toDeregister *service.Service) error {
-	agent, err := c.agents.GetAgent(toDeregister.RegisteringAgentAddress)
+	agent, err := c.agents.GetAgent(toDeregister.AgentAddress)
 	if err != nil {
 		return err
 	}
 
 	client := agent.Client
 
-	log.WithField("Id", toDeregister.ID).WithField("Address", toDeregister.RegisteringAgentAddress).Info("Deregistering")
+	log.WithField("Id", toDeregister.ID).WithField("Address", toDeregister.AgentAddress).Info("Deregistering")
 
 	err = client.Agent().ServiceDeregister(toDeregister.ID.String())
 	if err != nil {
-		log.WithError(err).WithField("Id", toDeregister.ID).WithField("Address", toDeregister.RegisteringAgentAddress).Error("Unable to deregister")
+		log.WithError(err).WithField("Id", toDeregister.ID).WithField("Address", toDeregister.AgentAddress).Error("Unable to deregister")
 	}
 	return err
 }
 
-func (c *Consul) marathonTaskToConsulServices(task *apps.Task, app *apps.App) ([]*consulapi.AgentServiceRegistration, error) {
+func (c *Consul) marathonTaskToConsulServices(task *apps.Task, app *apps.App) ([]*consulAPI.AgentServiceRegistration, error) {
 	IP, err := utils.HostToIPv4(task.Host)
 	if err != nil {
 		return nil, err
@@ -292,11 +293,11 @@ func (c *Consul) marathonTaskToConsulServices(task *apps.Task, app *apps.App) ([
 	serviceAddress := IP.String()
 	checks := c.marathonToConsulChecks(task, app.HealthChecks, serviceAddress)
 
-	var registrations []*consulapi.AgentServiceRegistration
+	var registrations []*consulAPI.AgentServiceRegistration
 	for _, intent := range app.RegistrationIntents(task, c.config.ConsulNameSeparator) {
 		tags := append([]string{c.config.Tag}, intent.Tags...)
 		tags = append(tags, service.MarathonTaskTag(task.ID))
-		registrations = append(registrations, &consulapi.AgentServiceRegistration{
+		registrations = append(registrations, &consulAPI.AgentServiceRegistration{
 			ID:                c.serviceID(task, intent.Name, intent.Port),
 			Name:              intent.Name,
 			Port:              intent.Port,
@@ -313,8 +314,8 @@ func (c *Consul) serviceID(task *apps.Task, name string, port int) string {
 	return fmt.Sprintf("%s_%s_%d", task.ID, name, port)
 }
 
-func (c *Consul) marathonToConsulChecks(task *apps.Task, healthChecks []apps.HealthCheck, serviceAddress string) consulapi.AgentServiceChecks {
-	var checks = make(consulapi.AgentServiceChecks, 0, len(healthChecks))
+func (c *Consul) marathonToConsulChecks(task *apps.Task, healthChecks []apps.HealthCheck, serviceAddress string) consulAPI.AgentServiceChecks {
+	var checks = make(consulAPI.AgentServiceChecks, 0, len(healthChecks))
 	for _, check := range healthChecks {
 		if contains(c.ignoredHealthCheckTypes, check.Protocol) {
 			log.WithField("Id", task.AppID.String()).WithField("Address", serviceAddress).
@@ -337,8 +338,8 @@ func (c *Consul) marathonToConsulChecks(task *apps.Task, healthChecks []apps.Hea
 	return checks
 }
 
-func marathonToConsulCheck(task *apps.Task, check apps.HealthCheck, serviceAddress string, port int) *consulapi.AgentServiceCheck {
-	consulCheck := &consulapi.AgentServiceCheck{
+func marathonToConsulCheck(task *apps.Task, check apps.HealthCheck, serviceAddress string, port int) *consulAPI.AgentServiceCheck {
+	consulCheck := &consulAPI.AgentServiceCheck{
 		Interval: fmt.Sprintf("%ds", check.IntervalSeconds),
 		Timeout:  fmt.Sprintf("%ds", check.TimeoutSeconds),
 		Status:   "passing",
@@ -350,7 +351,8 @@ func marathonToConsulCheck(task *apps.Task, check apps.HealthCheck, serviceAddre
 		if check.Path != "" {
 			path = check.Path
 		}
-		if parsedURL, err := url.ParseRequestURI(path); err == nil {
+		parsedURL, err := url.ParseRequestURI(path)
+		if err == nil {
 			if check.Protocol == "HTTP" || check.Protocol == "MESOS_HTTP" {
 				parsedURL.Scheme = "http"
 			} else {
@@ -359,12 +361,11 @@ func marathonToConsulCheck(task *apps.Task, check apps.HealthCheck, serviceAddre
 			parsedURL.Host = fmt.Sprintf("%s:%d", serviceAddress, port)
 			consulCheck.HTTP = parsedURL.String()
 			return consulCheck
-		} else {
-			log.WithError(err).
-				WithField("Id", task.AppID.String()).
-				WithField("Address", serviceAddress).
-				Warnf("Could not parse provided path: %s", path)
 		}
+		log.WithError(err).
+			WithField("Id", task.AppID.String()).
+			WithField("Address", serviceAddress).
+			Warnf("Could not parse provided path: %s", path)
 	case "TCP", "MESOS_TCP":
 		consulCheck.TCP = fmt.Sprintf("%s:%d", serviceAddress, port)
 		return consulCheck
diff --git a/consul/consul_stub.go b/consul/consul_stub.go
index 877eb53..e9ddeec 100644
--- a/consul/consul_stub.go
+++ b/consul/consul_stub.go
@@ -12,11 +12,11 @@ import (
 // TODO this should be a service registry stub in the service package, requires abstracting from AgentServiceRegistration
 type Stub struct {
 	sync.RWMutex
-	services                   map[service.ServiceId]*consulapi.AgentServiceRegistration
+	services                   map[service.ID]*consulapi.AgentServiceRegistration
 	failGetServicesForNames    map[string]bool
 	failRegisterForIDs         map[apps.TaskID]bool
 	failDeregisterByTaskForIDs map[apps.TaskID]bool
-	failDeregisterForIDs       map[service.ServiceId]bool
+	failDeregisterForIDs       map[service.ID]bool
 	consul                     *Consul
 }
 
@@ -26,11 +26,11 @@ func NewConsulStub() *Stub {
 
 func NewConsulStubWithTag(tag string) *Stub {
 	return &Stub{
-		services:                   make(map[service.ServiceId]*consulapi.AgentServiceRegistration),
+		services:                   make(map[service.ID]*consulapi.AgentServiceRegistration),
 		failGetServicesForNames:    make(map[string]bool),
 		failRegisterForIDs:         make(map[apps.TaskID]bool),
 		failDeregisterByTaskForIDs: make(map[apps.TaskID]bool),
-		failDeregisterForIDs:       make(map[service.ServiceId]bool),
+		failDeregisterForIDs:       make(map[service.ID]bool),
 		consul:                     New(Config{Tag: tag, ConsulNameSeparator: "."}),
 	}
 }
@@ -41,10 +41,10 @@ func (c *Stub) GetAllServices() ([]*service.Service, error) {
 	var allServices []*service.Service
 	for _, s := range c.services {
 		allServices = append(allServices, &service.Service{
-			ID:   service.ServiceId(s.ID),
-			Name: s.Name,
-			Tags: s.Tags,
-			RegisteringAgentAddress: s.Address,
+			ID:           service.ID(s.ID),
+			Name:         s.Name,
+			Tags:         s.Tags,
+			AgentAddress: s.Address,
 		})
 	}
 	return allServices, nil
@@ -62,7 +62,7 @@ func (c *Stub) FailDeregisterByTaskForID(taskID apps.TaskID) {
 	c.failDeregisterByTaskForIDs[taskID] = true
 }
 
-func (c *Stub) FailDeregisterForID(serviceID service.ServiceId) {
+func (c *Stub) FailDeregisterForID(serviceID service.ID) {
 	c.failDeregisterForIDs[serviceID] = true
 }
 
@@ -76,10 +76,10 @@ func (c *Stub) GetServices(name string) ([]*service.Service, error) {
 	for _, s := range c.services {
 		if s.Name == name && contains(s.Tags, c.consul.config.Tag) {
 			services = append(services, &service.Service{
-				ID:   service.ServiceId(s.ID),
-				Name: s.Name,
-				Tags: s.Tags,
-				RegisteringAgentAddress: s.Address,
+				ID:           service.ID(s.ID),
+				Name:         s.Name,
+				Tags:         s.Tags,
+				AgentAddress: s.Address,
 			})
 		}
 	}
@@ -97,7 +97,7 @@ func (c *Stub) Register(task *apps.Task, app *apps.App) error {
 		return err
 	}
 	for _, r := range serviceRegistrations {
-		c.services[service.ServiceId(r.ID)] = r
+		c.services[service.ID(r.ID)] = r
 	}
 	return nil
 }
@@ -114,7 +114,7 @@ func (c *Stub) RegisterWithoutMarathonTaskTag(task *apps.Task, app *apps.App) {
 			Tags:    intent.Tags,
 			Checks:  consulapi.AgentServiceChecks{},
 		}
-		c.services[service.ServiceId(serviceRegistration.ID)] = &serviceRegistration
+		c.services[service.ID(serviceRegistration.ID)] = &serviceRegistration
 	}
 }
 
@@ -122,7 +122,7 @@ func (c *Stub) RegisterOnlyFirstRegistrationIntent(task *apps.Task, app *apps.Ap
 	c.Lock()
 	defer c.Unlock()
 	serviceRegistrations, _ := c.consul.marathonTaskToConsulServices(task, app)
-	c.services[service.ServiceId(serviceRegistrations[0].ID)] = serviceRegistrations[0]
+	c.services[service.ID(serviceRegistrations[0].ID)] = serviceRegistrations[0]
 }
 
 func (c *Stub) DeregisterByTask(taskID apps.TaskID) error {
@@ -132,7 +132,7 @@ func (c *Stub) DeregisterByTask(taskID apps.TaskID) error {
 		return fmt.Errorf("Consul stub programmed to fail when deregistering task of id %s", taskID.String())
 	}
 	for _, x := range c.servicesMatchingTask(taskID) {
-		delete(c.services, service.ServiceId(x.ID))
+		delete(c.services, service.ID(x.ID))
 	}
 	return nil
 }
@@ -161,7 +161,7 @@ func (c *Stub) RegisteredTaskIDs(serviceName string) []apps.TaskID {
 	services, _ := c.GetServices(serviceName)
 	taskIds := []apps.TaskID{}
 	for _, s := range services {
-		taskID, _ := s.TaskId()
+		taskID, _ := s.TaskID()
 		taskIds = append(taskIds, taskID)
 	}
 	return taskIds
diff --git a/events/event_handler.go b/events/event_handler.go
index ac20354..a7e816c 100644
--- a/events/event_handler.go
+++ b/events/event_handler.go
@@ -6,11 +6,12 @@ import (
 	"fmt"
 	"time"
 
+	log "github.com/sirupsen/logrus"
+
 	"github.com/allegro/marathon-consul/apps"
 	"github.com/allegro/marathon-consul/marathon"
 	"github.com/allegro/marathon-consul/metrics"
 	"github.com/allegro/marathon-consul/service"
-	log "github.com/sirupsen/logrus"
 )
 
 type Event struct {
@@ -19,9 +20,9 @@ type Event struct {
 	Body      []byte
 }
 
-type eventHandler struct {
+type EventHandler struct {
 	id              int
-	serviceRegistry service.ServiceRegistry
+	serviceRegistry service.Registry
 	marathon        marathon.Marathoner
 	eventQueue      <-chan Event
 }
@@ -34,8 +35,8 @@ const (
 	EmptyEventType               = ""
 )
 
-func NewEventHandler(id int, serviceRegistry service.ServiceRegistry, marathon marathon.Marathoner, eventQueue <-chan Event) *eventHandler {
-	return &eventHandler{
+func NewEventHandler(id int, serviceRegistry service.Registry, marathon marathon.Marathoner, eventQueue <-chan Event) *EventHandler {
+	return &EventHandler{
 		id:              id,
 		serviceRegistry: serviceRegistry,
 		marathon:        marathon,
@@ -43,7 +44,7 @@ func NewEventHandler(id int, serviceRegistry service.ServiceRegistry, marathon m
 	}
 }
 
-func (fh *eventHandler) Start() chan<- StopEvent {
+func (fh *EventHandler) Start() chan<- StopEvent {
 	var e Event
 	process := func() {
 		err := fh.handleEvent(e.EventType, e.Body)
@@ -82,7 +83,7 @@ func (fh *eventHandler) Start() chan<- StopEvent {
 	return quitChan
 }
 
-func (fh *eventHandler) handleEvent(eventType string, body []byte) error {
+func (fh *EventHandler) handleEvent(eventType string, body []byte) error {
 
 	body = replaceTaskIDWithID(body)
 
@@ -105,7 +106,7 @@ func (fh *eventHandler) handleEvent(eventType string, body []byte) error {
 	}
 }
 
-func (fh *eventHandler) handleHealthyTask(body []byte) error {
+func (fh *EventHandler) handleHealthyTask(body []byte) error {
 	taskHealthChange, err := ParseTaskHealthChange(body)
 	if err != nil {
 		log.WithError(err).Error("Body generated error")
@@ -155,7 +156,7 @@ func (fh *eventHandler) handleHealthyTask(body []byte) error {
 	return nil
 }
 
-func (fh *eventHandler) handleStatusEvent(body []byte) error {
+func (fh *EventHandler) handleStatusEvent(body []byte) error {
 	task, err := apps.ParseTask(body)
 	if err != nil {
 		log.WithError(err).WithField("Body", body).Error("Could not parse event body")
@@ -181,7 +182,7 @@ func (fh *eventHandler) handleStatusEvent(body []byte) error {
 	}
 }
 
-func (fh *eventHandler) deregister(taskID apps.TaskID) error {
+func (fh *EventHandler) deregister(taskID apps.TaskID) error {
 	err := fh.serviceRegistry.DeregisterByTask(taskID)
 	if err != nil {
 		log.WithField("Id", taskID).WithError(err).Error("There was a problem deregistering task")
diff --git a/events/task_health_change.go b/events/task_health_change.go
index 496c444..74a98ff 100644
--- a/events/task_health_change.go
+++ b/events/task_health_change.go
@@ -21,13 +21,13 @@ type TaskHealthChange struct {
 
 // Regular expression to extract runSpecId from instanceId
 // See: https://github.com/mesosphere/marathon/blob/v1.4.0-RC4/src/main/scala/mesosphere/marathon/core/instance/Instance.scala#L244
-var instanceIdRegex = regexp.MustCompile(`^(.+)\.(instance-|marathon-)([^\.]+)$`)
+var instanceIDRegex = regexp.MustCompile(`^(.+)\.(instance-|marathon-)([^\.]+)$`)
 
 func (t TaskHealthChange) TaskID() apps.TaskID {
 	if t.ID != "" {
 		return t.ID
 	}
-	return apps.TaskID(instanceIdRegex.ReplaceAllString(t.InstanceID, "$1.$3"))
+	return apps.TaskID(instanceIDRegex.ReplaceAllString(t.InstanceID, "$1.$3"))
 }
 
 func ParseTaskHealthChange(event []byte) (*TaskHealthChange, error) {
diff --git a/golangcilinter.yaml b/golangcilinter.yaml
new file mode 100644
index 0000000..e6f9678
--- /dev/null
+++ b/golangcilinter.yaml
@@ -0,0 +1,19 @@
+run:
+  aggregate: true
+  concurrency: 2
+  cyclo: 14
+  deadline: "300s"
+  skip-files:
+  - ".*_string.go"
+  - ".*_test.go"
+linters:
+  disable-all: true
+  enable:
+    - deadcode
+    - errcheck
+    - gocyclo
+    - goimports
+    - golint
+    - gosimple
+    - govet
+
diff --git a/metrics/metrics.go b/metrics/metrics.go
index 6e77bdc..ff45131 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -12,7 +12,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/cyberdelia/go-metrics-graphite"
+	graphite "github.com/cyberdelia/go-metrics-graphite"
 	"github.com/rcrowley/go-metrics"
 	log "github.com/sirupsen/logrus"
 )
@@ -102,8 +102,8 @@ func defaultPrefix() (string, error) {
 }
 
 func initStdout(interval time.Duration) error {
-	logger := logger.New(os.Stderr, "localhost: ", logger.Lmicroseconds)
-	go metrics.Log(metrics.DefaultRegistry, interval, logger)
+	loggerInstance := logger.New(os.Stderr, "localhost: ", logger.Lmicroseconds)
+	go metrics.Log(metrics.DefaultRegistry, interval, loggerInstance)
 	return nil
 }
 
diff --git a/metrics/system_metrics.go b/metrics/system_metrics.go
index 2cc77fb..0601cad 100644
--- a/metrics/system_metrics.go
+++ b/metrics/system_metrics.go
@@ -12,10 +12,10 @@ const totalPauseGauge = "runtime.mem.pause_total_ns"
 const lastPauseGauge = "runtime.mem.last_pause"
 
 func collectSystemMetrics() {
-	metrics.Register(allocGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.Alloc) }})
-	metrics.Register(heapObjectsGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.HeapObjects) }})
-	metrics.Register(totalPauseGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.PauseTotalNs) }})
-	metrics.Register(lastPauseGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.PauseNs[(memStats.NumGC+255)%256]) }})
+	_ = metrics.Register(allocGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.Alloc) }})
+	_ = metrics.Register(heapObjectsGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.HeapObjects) }})
+	_ = metrics.Register(totalPauseGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.PauseTotalNs) }})
+	_ = metrics.Register(lastPauseGauge, baseGauge{value: func(memStats runtime.MemStats) int64 { return int64(memStats.PauseNs[(memStats.NumGC+255)%256]) }})
 }
 
 type baseGauge struct {
diff --git a/service/service.go b/service/service.go
index e9fc093..02eafd5 100644
--- a/service/service.go
+++ b/service/service.go
@@ -8,21 +8,21 @@ import (
 	"github.com/allegro/marathon-consul/apps"
 )
 
-type ServiceId string
+type ID string
 
-func (id ServiceId) String() string {
+func (id ID) String() string {
 	return string(id)
 }
 
 type Service struct {
-	ID                      ServiceId
-	Name                    string
-	Tags                    []string
-	RegisteringAgentAddress string
-	EnableTagOverride       bool
+	ID                ID
+	Name              string
+	Tags              []string
+	AgentAddress      string
+	EnableTagOverride bool
 }
 
-func (s *Service) TaskId() (apps.TaskID, error) {
+func (s *Service) TaskID() (apps.TaskID, error) {
 	for _, tag := range s.Tags {
 		if strings.HasPrefix(tag, "marathon-task:") {
 			return apps.TaskID(strings.TrimPrefix(tag, "marathon-task:")), nil
@@ -31,14 +31,14 @@ func (s *Service) TaskId() (apps.TaskID, error) {
 	return apps.TaskID(""), errors.New("marathon-task tag missing")
 }
 
-func MarathonTaskTag(taskId apps.TaskID) string {
-	return fmt.Sprintf("marathon-task:%s", taskId)
+func MarathonTaskTag(taskID apps.TaskID) string {
+	return fmt.Sprintf("marathon-task:%s", taskID)
 }
 
-type ServiceRegistry interface {
+type Registry interface {
 	GetAllServices() ([]*Service, error)
 	GetServices(name string) ([]*Service, error)
 	Register(task *apps.Task, app *apps.App) error
-	DeregisterByTask(taskId apps.TaskID) error
+	DeregisterByTask(taskID apps.TaskID) error
 	Deregister(toDeregister *Service) error
 }
diff --git a/sse/sse.go b/sse/sse.go
index 9d8c829..15e4676 100644
--- a/sse/sse.go
+++ b/sse/sse.go
@@ -5,17 +5,18 @@ import (
 	"net/http"
 	"time"
 
+	log "github.com/sirupsen/logrus"
+
 	"github.com/allegro/marathon-consul/events"
 	"github.com/allegro/marathon-consul/marathon"
 	"github.com/allegro/marathon-consul/service"
 	"github.com/allegro/marathon-consul/web"
-	log "github.com/sirupsen/logrus"
 )
 
 type Stop func()
 type Handler func(w http.ResponseWriter, r *http.Request)
 
-func NewHandler(config Config, webConfig web.Config, marathon marathon.Marathoner, serviceOperations service.ServiceRegistry) (Stop, error) {
+func NewHandler(config Config, webConfig web.Config, marathon marathon.Marathoner, serviceOperations service.Registry) (Stop, error) {
 	stopChannels := make([]chan<- events.StopEvent, webConfig.WorkersCount)
 	stopFunc := stop(stopChannels)
 	eventQueue := make(chan events.Event, webConfig.QueueSize)
diff --git a/sse/sse_handler.go b/sse/sse_handler.go
index 2d12d5d..3e4296d 100644
--- a/sse/sse_handler.go
+++ b/sse/sse_handler.go
@@ -5,22 +5,23 @@ import (
 	"io"
 	"time"
 
+	log "github.com/sirupsen/logrus"
+
 	"github.com/allegro/marathon-consul/events"
 	"github.com/allegro/marathon-consul/marathon"
 	"github.com/allegro/marathon-consul/metrics"
-	log "github.com/sirupsen/logrus"
 )
 
-// SSEHandler defines handler for marathon event stream, opening and closing
+// HandlerSSE defines handler for marathon event stream, opening and closing
 // subscription
-type SSEHandler struct {
+type HandlerSSE struct {
 	config      Config
 	eventQueue  chan events.Event
 	Streamer    *marathon.Streamer
 	maxLineSize int64
 }
 
-func newSSEHandler(eventQueue chan events.Event, service marathon.Marathoner, maxLineSize int64, config Config) (*SSEHandler, error) {
+func newSSEHandler(eventQueue chan events.Event, service marathon.Marathoner, maxLineSize int64, config Config) (*HandlerSSE, error) {
 
 	streamer, err := service.EventStream(
 		[]string{events.StatusUpdateEventType, events.HealthStatusChangedEventType},
@@ -31,7 +32,7 @@ func newSSEHandler(eventQueue chan events.Event, service marathon.Marathoner, ma
 		return nil, fmt.Errorf("Unable to start Streamer: %s", err)
 	}
 
-	return &SSEHandler{
+	return &HandlerSSE{
 		config:      config,
 		eventQueue:  eventQueue,
 		Streamer:    streamer,
@@ -40,7 +41,7 @@ func newSSEHandler(eventQueue chan events.Event, service marathon.Marathoner, ma
 }
 
 // Open connection to marathon v2/events
-func (h *SSEHandler) start() (chan<- events.StopEvent, error) {
+func (h *HandlerSSE) start() (chan<- events.StopEvent, error) {
 	if err := h.Streamer.Start(); err != nil {
 		return nil, fmt.Errorf("Cannot start Streamer: %s", err)
 	}
@@ -67,7 +68,7 @@ func (h *SSEHandler) start() (chan<- events.StopEvent, error) {
 	return stopChan, nil
 }
 
-func (h *SSEHandler) handle() {
+func (h *HandlerSSE) handle() {
 	e, err := events.ParseSSEEvent(h.Streamer.Scanner)
 	if err != nil {
 		if err == io.EOF {
@@ -89,7 +90,7 @@ func (h *SSEHandler) handle() {
 	h.enqueueEvent(e)
 }
 
-func (h *SSEHandler) enqueueEvent(e events.SSEEvent) {
+func (h *HandlerSSE) enqueueEvent(e events.SSEEvent) {
 	select {
 	case h.eventQueue <- events.Event{Timestamp: time.Now(), EventType: e.Type, Body: e.Body}:
 		metrics.Mark("events.read.accept")
@@ -100,6 +101,6 @@ func (h *SSEHandler) enqueueEvent(e events.SSEEvent) {
 }
 
 // Close connections managed by context
-func (h *SSEHandler) stop() {
+func (h *HandlerSSE) stop() {
 	h.Streamer.Stop()
 }
diff --git a/sync/sync.go b/sync/sync.go
index 7cb05d6..0c9ff86 100644
--- a/sync/sync.go
+++ b/sync/sync.go
@@ -14,13 +14,13 @@ import (
 type Sync struct {
 	config              Config
 	marathon            marathon.Marathoner
-	serviceRegistry     service.ServiceRegistry
+	serviceRegistry     service.Registry
 	syncStartedListener startedListener
 }
 
 type startedListener func(apps []*apps.App)
 
-func New(config Config, marathon marathon.Marathoner, serviceRegistry service.ServiceRegistry, syncStartedListener startedListener) *Sync {
+func New(config Config, marathon marathon.Marathoner, serviceRegistry service.Registry, syncStartedListener startedListener) *Sync {
 	return &Sync{config, marathon, serviceRegistry, syncStartedListener}
 }
 
@@ -109,10 +109,10 @@ func (s *Sync) deregisterConsulServicesNotFoundInMarathon(marathonApps []*apps.A
 	for _, service := range services {
 		logFields := log.Fields{
 			"Id":      service.ID,
-			"Address": service.RegisteringAgentAddress,
+			"Address": service.AgentAddress,
 			"Sync":    true,
 		}
-		if taskIDInTag, err := service.TaskId(); err != nil {
+		if taskIDInTag, err := service.TaskID(); err != nil {
 			log.WithField("Id", service.ID).WithError(err).
 				Warn("Couldn't extract marathon task id, deregistering since sync should have reregistered it already")
 			if err := s.serviceRegistry.Deregister(service); err != nil {
@@ -190,7 +190,7 @@ func (s *Sync) registerAppTasksNotFoundInConsul(marathonApps []*apps.App, servic
 func taskIdsInConsulServices(services []*service.Service) map[apps.TaskID]int {
 	serviceCounters := make(map[apps.TaskID]int)
 	for _, service := range services {
-		if taskID, err := service.TaskId(); err == nil {
+		if taskID, err := service.TaskID(); err == nil {
 			serviceCounters[taskID]++
 		}
 	}


Test patch:
diff --git a/consul/consul_test.go b/consul/consul_test.go
index 17f6df3..790c504 100644
--- a/consul/consul_test.go
+++ b/consul/consul_test.go
@@ -68,10 +68,10 @@ func TestRegister_ForInvalidHost(t *testing.T) {
 
 	// when
 	err = consul.Deregister(&service.Service{
-		ID:   service.ServiceId("someId"),
-		Name: "service",
-		Tags: []string{},
-		RegisteringAgentAddress: "",
+		ID:           service.ID("someId"),
+		Name:         "service",
+		Tags:         []string{},
+		AgentAddress: "",
 	})
 
 	// then
@@ -870,7 +870,7 @@ func TestMarathonTaskToConsulServiceMapping(t *testing.T) {
 			Status:   "passing",
 		},
 		{
-			Args:   []string{"echo 1"},
+			Args:     []string{"echo 1"},
 			Interval: "30s",
 			Timeout:  "20s",
 			Status:   "passing",
diff --git a/consul/consul_test_server.go b/consul/consul_test_server.go
index 46ae5ca..d45dab5 100644
--- a/consul/consul_test_server.go
+++ b/consul/consul_test_server.go
@@ -6,9 +6,10 @@ import (
 	"testing"
 	"time"
 
-	timeutil "github.com/allegro/marathon-consul/time"
 	"github.com/hashicorp/consul/testutil"
 	"github.com/stretchr/testify/assert"
+
+	timeutil "github.com/allegro/marathon-consul/time"
 )
 
 func CreateTestServer(t *testing.T) *testutil.TestServer {
@@ -56,7 +57,7 @@ func getPorts(number int) ([]int, error) {
 	listener := make([]*net.TCPListener, number)
 	defer func() {
 		for _, l := range listener {
-			l.Close()
+			_ = l.Close()
 		}
 
 	}()
@@ -100,7 +101,7 @@ func FailingClient() *Consul {
 	}
 	consul := New(config)
 	// initialize the agents cache with a single client pointing at provided location
-	consul.AddAgent(host)
+	_ = consul.AddAgent(host)
 	return consul
 }
 
@@ -118,7 +119,7 @@ func consulClientAtAddress(host string, port int, local bool) *Consul {
 	}
 	consul := New(config)
 	// initialize the agents cache with a single client pointing at provided location
-	consul.AddAgent(host)
+	_ = consul.AddAgent(host)
 	return consul
 }
 
@@ -133,6 +134,6 @@ func secureConsulClientAtAddress(host string, port int) *Consul {
 	}
 	consul := New(config)
 	// initialize the agents cache with a single client pointing at provided location
-	consul.AddAgent(host)
+	_ = consul.AddAgent(host)
 	return consul
 }
diff --git a/events/event_handler_test.go b/events/event_handler_test.go
index 32ac587..c613a7e 100644
--- a/events/event_handler_test.go
+++ b/events/event_handler_test.go
@@ -14,11 +14,11 @@ import (
 )
 
 type handlerStubs struct {
-	serviceRegistry service.ServiceRegistry
+	serviceRegistry service.Registry
 	marathon        marathon.Marathoner
 }
 
-// Creates eventHandler and returns nonbuffered event queue that has to be used to send events to handler and
+// Creates EventHandler and returns nonbuffered event queue that has to be used to send events to handler and
 // function that can be used as a synchronization point to wait until previous event has been processed.
 // Under the hood synchronization function simply sends a stop signal to the handlers stopChan.
 func testEventHandler(stubs handlerStubs) (chan<- Event, func()) {
diff --git a/marathon/marathon_test.go b/marathon/marathon_test.go
index bba7504..c96dab1 100644
--- a/marathon/marathon_test.go
+++ b/marathon/marathon_test.go
@@ -7,6 +7,7 @@ import (
 	"net/url"
 	"os"
 	"testing"
+
 	"github.com/stretchr/testify/assert"
 )
 
diff --git a/service/service_test.go b/service/service_test.go
index 4e1310e..5f17d5a 100644
--- a/service/service_test.go
+++ b/service/service_test.go
@@ -16,14 +16,14 @@ func TestServiceTaskId(t *testing.T) {
 	t.Parallel()
 	// given
 	service := Service{
-		ID:   "123",
-		Name: "abc",
-		Tags: []string{MarathonTaskTag("my-task")},
-		RegisteringAgentAddress: "localhost",
+		ID:           "123",
+		Name:         "abc",
+		Tags:         []string{MarathonTaskTag("my-task")},
+		AgentAddress: "localhost",
 	}
 
 	// when
-	id, err := service.TaskId()
+	id, err := service.TaskID()
 
 	// then
 	assert.Equal(t, apps.TaskID("my-task"), id)
@@ -34,14 +34,14 @@ func TestServiceTaskId_NoMarathonTaskTag(t *testing.T) {
 	t.Parallel()
 	// given
 	service := Service{
-		ID:   "123",
-		Name: "abc",
-		Tags: []string{},
-		RegisteringAgentAddress: "localhost",
+		ID:           "123",
+		Name:         "abc",
+		Tags:         []string{},
+		AgentAddress: "localhost",
 	}
 
 	// when
-	_, err := service.TaskId()
+	_, err := service.TaskID()
 
 	// then
 	assert.Error(t, err)
diff --git a/sync/sync_bench_test.go b/sync/sync_bench_test.go
index 019f67b..cc8ad5a 100644
--- a/sync/sync_bench_test.go
+++ b/sync/sync_bench_test.go
@@ -62,10 +62,10 @@ func instances(appsCount, instancesCount int) []*service.Service {
 		app := ConsulApp(fmt.Sprintf("consul/service/no_%d", i), instancesCount)
 		for _, task := range app.Tasks {
 			createdInstances[i] = &service.Service{
-				ID:   service.ServiceId(task.ID.String()),
-				Name: app.ID.String(),
-				Tags: []string{"marathon"},
-				RegisteringAgentAddress: task.Host,
+				ID:           service.ID(task.ID.String()),
+				Name:         app.ID.String(),
+				Tags:         []string{"marathon"},
+				AgentAddress: task.Host,
 			}
 		}
 	}
diff --git a/sync/sync_test.go b/sync/sync_test.go
index 843de20..230c246 100644
--- a/sync/sync_test.go
+++ b/sync/sync_test.go
@@ -439,7 +439,7 @@ func TestSync_WithConsulProblems(t *testing.T) {
 	assert.Error(t, err)
 }
 
-func newSyncWithDefaultConfig(marathon marathon.Marathoner, serviceRegistry service.ServiceRegistry) *Sync {
+func newSyncWithDefaultConfig(marathon marathon.Marathoner, serviceRegistry service.Registry) *Sync {
 	return New(Config{Enabled: true, Leader: "localhost:8080"}, marathon, serviceRegistry, noopSyncStartedListener)
 }