Initial commit
This commit is contained in:
35
.editorconfig
Normal file
35
.editorconfig
Normal file
@@ -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
|
||||||
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Ensure all text files use LF line endings
|
||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# игнорируем содержимое ent, кроме ent/schema
|
||||||
|
ent/*
|
||||||
|
!ent/schema
|
||||||
|
!ent/schema/**
|
||||||
|
|
||||||
|
# игнорируем маковский индекс
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# игнорируем локальную конфигурацию
|
||||||
|
.env
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# игнорируем собранное приложение
|
||||||
|
backend.run
|
||||||
|
|
||||||
|
# игнорируем отладочную информацию
|
||||||
|
src/__debug_*
|
||||||
18
.vscode_template/launch.json
Normal file
18
.vscode_template/launch.json
Normal file
@@ -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}"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
57
Makefile
Normal file
57
Makefile
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
NAMESPACE ?= <PROJECT_CHANGE_ME>
|
||||||
|
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
|
||||||
42
README.md
Normal file
42
README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# НАЗВАНИЕ ПРОЕКТА — Бэкэнд — Go 1.24
|
||||||
|
|
||||||
|
Этот репозиторий реализует сервис, который обеспечивает:
|
||||||
|
* получение и сохранение метрик, полученных от внешней организации;
|
||||||
|
* управление параметрами экспортёров метрик и планами экспорта.
|
||||||
|
|
||||||
|
## TL;DR
|
||||||
|
|
||||||
|
Создание пользователя и базы для него:
|
||||||
|
|
||||||
|
createuser USERNAME -P <top_secret>
|
||||||
|
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
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user