PACKAGES = `go list ./... | grep -v /vendor/`

.PHONY: setup dev lint mocks test update

ENVIRONMENT ?= "dev"
REDIS_HOST ?= 127.0.0.1:6379
USERS_SERVICE_HOST ?= https://users-service.dev.us-west2.twitch.tv

STATSD_HOST ?= "graphite.internal.justin.tv:8125"

DB_HOST ?= localhost
DB_PORT ?= 5432
DB_NAME ?= hallpass
DB_SSLMODE ?= disable

setup:
	createdb hallpass

dev-api:
	ENVIRONMENT=$(ENVIRONMENT) \
	REDIS_HOST=$(REDIS_HOST) \
	USERS_SERVICE_HOST=$(USERS_SERVICE_HOST) \
	STATSD_HOST=$(STATSD_HOST) \
	DB_MASTER_HOST=$(DB_HOST) \
	DB_MASTER_PORT=$(DB_PORT) \
	DB_REPLICA_HOST=$(DB_HOST) \
	DB_REPLICA_PORT=$(DB_PORT) \
	DB_NAME=$(DB_NAME) \
	DB_SSLMODE=$(DB_SSLMODE) \
	go run cmd/api/main.go

dev-worker:
	ENVIRONMENT=$(ENVIRONMENT) \
	REDIS_HOST=$(REDIS_HOST) \
	USERS_SERVICE_HOST=$(USERS_SERVICE_HOST) \
	STATSD_HOST=$(STATSD_HOST) \
	DB_MASTER_HOST=$(DB_HOST) \
	DB_MASTER_PORT=$(DB_PORT) \
	DB_NAME=$(DB_NAME) \
	DB_SSLMODE=$(DB_SSLMODE) \
	go run cmd/worker/main.go

lint:
	# Lint with Go Meta Linter
	gometalinter \
	--disable-all \
	--enable=deadcode \
	--enable=errcheck \
	--enable=goconst \
	--enable=gofmt \
	--enable=goimports \
	--enable=golint \
	--enable=ineffassign \
	--enable=misspell \
	--enable=structcheck \
	--enable=varcheck \
	--enable=vet \
	--enable=vetshadow \
	--skip=mocks \
	--tests \
	--vendor ./...

mocks:
	# Generate mocks for interfaces in internal/app/
	mockery -all -dir=internal/app/ -case=underscore -output=internal/mocks/

test:
	# Test packages excluding vendor
	go test -cover -race -v $(PACKAGES)

update:
	# Update vendor packages with Glide
	glide update --strip-vendor
	glide-vc --only-code --no-tests --use-lock-file
