BINARY_NAME=gotography
BUILD_DIRECTROY=./dist

CGO_ENABLED=0

build:
	mkdir -p ${BUILD_DIRECTROY}
	CGO_ENABLED=${CGO_ENABLED} go build -ldflags "-s -w" -trimpath -o ${BUILD_DIRECTROY}/${BINARY_NAME} main.go

run: build
	${BUILD_DIRECTROY}/${BINARY_NAME}

clean:
	go clean

clean_all: clean
	rm -rd ${BUILD_DIRECTROY}

test: lint
	go clean -testcache
	go test ./...

test_database: lint
	docker compose up -d
	# Wait for a maximum of three minutes for CQL to be available
	for i in `seq 1 180`; do \
		if docker exec scylla-node1 cqlsh >/dev/null 2>&1; then \
			break; \
		fi; \
		sleep 1; \
	done
	go clean -testcache
	go test ./... -coverprofile coverage.out
	go tool cover -html coverage.out -o coverage.html
	docker compose down

test_coverage:
	go test ./... -coverprofile=coverage.out

dep:
	go mod download

lint:
	if command -v go-staticcheck; then \
		go-staticcheck ./...; \
	else \
		staticcheck ./...; \
	fi;
