Compare commits

...

2 Commits

Author SHA1 Message Date
7639b3ded7 Feat: add README
Some checks failed
Go test / run-go-vet (push) Successful in 6s
Go test / check-swagger-up-to-date (push) Successful in 16s
Go test / run-go-test (push) Successful in 28s
Go test / cleanup-go-test (push) Successful in 14s
Go test / release-image (push) Failing after 1m57s
2025-12-09 01:45:13 +08:00
a2b00e6976 Feat: add release image workflows
Fix:
- transaction didn't do shit because of my shit code
2025-12-09 01:28:59 +08:00
4 changed files with 51 additions and 10 deletions

View File

@@ -10,8 +10,28 @@ jobs:
uses: actions/checkout@v4
- name: Run go vet
run: go vet
check-swagger-up-to-date:
runs-on: imgbuilder
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run make swagger
run: make swagger
- name: Check diff
run: |
if ! git diff --exit-code; then
echo "ERROR: swagger introduced uncommitted changes!"
echo "Please commit generated files."
git status
git diff
exit 1
else
echo "No uncommitted changes detected. OpenAPI is up-to-date."
fi
run-go-test:
needs: run-go-vet
needs:
- run-go-vet
- check-swagger-up-to-date
runs-on: imgbuilder
steps:
- name: Checkout repository
@@ -29,3 +49,14 @@ jobs:
uses: actions/checkout@v4
- name: Run make docker-clean
run: make docker-clean
release-image:
needs:
- run-go-test
runs-on: imgbuilder
steps:
- name: Build and push image
uses: https://gitea.konchin.com/action/docker@main
with:
registry-certificate: ${{ vars.ROOTCA }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

View File

@@ -16,7 +16,7 @@ swagger:
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
docker: $(TARGET)
$(COMPOSE) up -d --force-recreate --build backend
$(DOCKER) compose up -d --force-recreate --build backend
$(TARGET): $(SOURCE)
$(GO_ENV) go build -o $@

10
README.md Normal file
View File

@@ -0,0 +1,10 @@
# Golang 2025 Final Project - Backend
## How to setup the development environment
1. clone this project
2. `docker compose up -d`
## How to run
`go run . serve` or `go build && ./backend serve`

View File

@@ -61,7 +61,7 @@ func (self *BunDatabase) UpdateRefreshToken(
}
err := self.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
err := self.db.NewSelect().
err := tx.NewSelect().
Model(&ret).
WherePK().
Scan(ctx)
@@ -76,7 +76,7 @@ func (self *BunDatabase) UpdateRefreshToken(
return err
}
_, err = self.db.NewUpdate().
_, err = tx.NewUpdate().
Model((*models.Session)(nil)).
Set("refresh_token = ?", ret.RefreshToken).
Where("user_id = ?", userId).
@@ -176,7 +176,7 @@ func (self *BunDatabase) UpdateAliases(
Name: ali,
})
}
_, err := self.db.NewInsert().
_, err := tx.NewInsert().
Model(&aliases).
On("CONFLICT (name) DO NOTHING").
Exec(ctx)
@@ -191,7 +191,7 @@ func (self *BunDatabase) UpdateAliases(
ImageId: imageId,
})
}
_, err = self.db.NewInsert().
_, err = tx.NewInsert().
Model(&rels).
On(`CONFLICT ("alias_id", "image_id") DO NOTHING`).
Exec(ctx)
@@ -218,14 +218,14 @@ func (self *BunDatabase) DeleteImage(
imageId int64,
) error {
return self.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
_, err := self.db.NewDelete().
_, err := tx.NewDelete().
Model((*models.Image)(nil)).
Where("id = ?", imageId).
Exec(ctx)
if err != nil {
return err
}
_, err = self.db.NewDelete().
_, err = tx.NewDelete().
Model((*models.AliasImage)(nil)).
Where("image_id = ?", imageId).
Exec(ctx)
@@ -241,14 +241,14 @@ func (self *BunDatabase) DeleteAlias(
aliasId int64,
) error {
return self.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
_, err := self.db.NewDelete().
_, err := tx.NewDelete().
Model((*models.Alias)(nil)).
Where("id = ?", aliasId).
Exec(ctx)
if err != nil {
return err
}
_, err = self.db.NewDelete().
_, err = tx.NewDelete().
Model((*models.AliasImage)(nil)).
Where("alias_id = ?", aliasId).
Exec(ctx)