1
0
Fork 0
forked from jriou/coller

Several fixes and features

- Commit database transactions
- Listen to all interfaces by default
- Use logger in collerd
- Add docker-compose file with PostgreSQL

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-08-26 12:28:32 +02:00
parent 01031a24ab
commit 7d7614637b
Signed by: jriou
GPG key ID: 9A099EDA51316854
7 changed files with 45 additions and 6 deletions

View file

@ -93,6 +93,7 @@ func (d *Database) StartExpireThread() {
func (d *Database) Get(id string) (*Note, error) {
var note Note
trx := d.db.Where("id = ?", id).Find(&note)
defer trx.Commit()
if trx.Error != nil {
d.logger.Warn("could not find note", slog.Any("error", trx.Error))
return nil, trx.Error
@ -134,6 +135,7 @@ func (d *Database) Create(content []byte, password string, encrypted bool, expir
note.Encrypted = true
}
trx := d.db.Create(note)
defer trx.Commit()
if trx.Error != nil {
d.logger.Warn("could not create note", slog.Any("error", trx.Error))
return nil, trx.Error
@ -143,6 +145,7 @@ func (d *Database) Create(content []byte, password string, encrypted bool, expir
func (d *Database) Delete(id string) error {
trx := d.db.Where("id = ?", id).Delete(&Note{})
defer trx.Commit()
if trx.Error != nil {
d.logger.Error("could not delete note", slog.Any("error", trx.Error))
return trx.Error