commit 469879cfd929ae1f5962f500f9d8f24203ca8346 Author: Ruslan Popov Date: Wed Nov 19 01:24:35 2025 +0300 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2d97ce5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,35 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab + +[.bumpversion.cfg] +indent_style = tab + +[*.{py,rst,ini}] +indent_size = 4 +indent_style = space + +[*.{html,css,json,yml}] +indent_size = 2 +indent_style = space + +[*.md] +trim_trailing_whitespace = false + +[*.txt] +trim_trailing_whitespace = false + +[nginx.conf] +indent_size = 2 +indent_style = space diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3958a77 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# Ensure all text files use LF line endings +* text=auto eol=lf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34899be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# игнорируем содержимое ent, кроме ent/schema +ent/* +!ent/schema +!ent/schema/** + +# игнорируем маковский индекс +.DS_Store + +# игнорируем локальную конфигурацию +.env +.vscode/ + +# игнорируем собранное приложение +backend.run + +# игнорируем отладочную информацию +src/__debug_* diff --git a/.vscode_template/launch.json b/.vscode_template/launch.json new file mode 100644 index 0000000..1ffb4e3 --- /dev/null +++ b/.vscode_template/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Project", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/src/main.go", + "args": [], // Аргументы командной строки, если нужны + "env": {}, // Переменные окружения, если нужны + "cwd": "${workspaceFolder}" + }, + ] +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c6716b6 --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +NAMESPACE ?= +PACKAGE := backend +SHELL := /bin/bash +REGISTRY := registry.halfakop.ru +REPOSITORY := $(NAMESPACE)/$(PACKAGE) + +SOURCE_VERSION ?= $(shell cat VERSION) +SOURCE_COMMIT ?= $(shell git rev-parse --short=8 HEAD) +GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed s,feature/,,g) + +IMAGE_NAME_TAGGED = $(REPOSITORY):$(SOURCE_VERSION) +EXEC=$(PACKAGE).run + +all: help + +help: + @echo "app - build the application" + @echo "tests - run tests" + @echo "run - run application locally" + @echo "clean - clean build environment" + +fix: + @go fix ./... + +app: fix + @go build -o ./${EXEC} ./src + +tests: build + @go test ./... + +run: + @./${EXEC} + +clean: + @rm -rf ./${EXEC}% + +release: title clean build login push + +build: + docker build --compress \ + -t $(IMAGE_NAME_TAGGED) \ + -t $(REGISTRY)/$(IMAGE_NAME_TAGGED) \ + --build-arg SOURCE_VERSION=$(SOURCE_VERSION) \ + --build-arg SOURCE_COMMIT=$(SOURCE_COMMIT) \ + ${DOCKER_OPTS} \ + -f Dockerfile . + +login: + $(call check-var-defined,DOCKER_USERNAME) + $(call check-var-defined,DOCKER_PASSWORD) + @echo ${DOCKER_PASSWORD} | \ + docker login -u ${DOCKER_USERNAME} --password-stdin $(REGISTRY) + +push: + docker push $(REGISTRY)/$(IMAGE_NAME_TAGGED) + +.PHONY: tests release build login push \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bdcd471 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# НАЗВАНИЕ ПРОЕКТА — Бэкэнд — Go 1.24 + +Этот репозиторий реализует сервис, который обеспечивает: +* получение и сохранение метрик, полученных от внешней организации; +* управление параметрами экспортёров метрик и планами экспорта. + +## TL;DR + +Создание пользователя и базы для него: + + createuser USERNAME -P + createdb --owner USERNAME DBNAME + +Проверка доступа: + + psql -U USERNAME DBNAME + +Для работы миграций надо сделать так: + + psql -d DBNAME -c 'alter schema public owner to USERNAME;' + +Затем: + +```bash +# 0) Подготовьте Postgres + переменные окружения +export DATABASE_URL='postgres://USERNAME:top_secret@localhost:5432/DBNAME?sslmode=disable' + +export PATH="$PATH:$(go env GOPATH)/bin" + +# 1) Сгенерируйте код Ent по схемам (требуется один раз, при изменении схем) + Подключите ваш ORM как сабмодуль Git. + +go install entgo.io/ent/cmd/ent@latest +ent generate ./orm/ent/schema + +# 2) Примените миграции Atlas (готовые SQL в atlas/migrations) +go install ariga.io/atlas/cmd/atlas@v0.38.0 +atlas migrate apply --dir file://orm/atlas/migrations --url "$DATABASE_URL" + +# 3) Запустите сервис +go run ./cmd/server +```