Fix lint, make pipeline use psotgres

This commit is contained in:
binwiederhier
2026-02-18 21:07:31 -05:00
parent 9cc9891f49
commit 939b3d1117
5 changed files with 16 additions and 42 deletions

View File

@@ -39,7 +39,7 @@ jobs:
- name: Build web app (required for tests) - name: Build web app (required for tests)
run: make web run: make web
- name: Run tests, formatting, vetting and linting - name: Run tests, formatting, vetting and linting
run: make check run: make checkv
- name: Run coverage - name: Run coverage
run: make coverage run: make coverage
- name: Upload coverage to codecov.io - name: Upload coverage to codecov.io

View File

@@ -265,6 +265,8 @@ cli-build-results:
check: test web-fmt-check fmt-check vet web-lint lint staticcheck check: test web-fmt-check fmt-check vet web-lint lint staticcheck
checkv: testv web-fmt-check fmt-check vet web-lint lint staticcheck
test: .PHONY test: .PHONY
go test $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)') go test $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')

View File

@@ -19,10 +19,10 @@ const (
PollRequestEvent = "poll_request" PollRequestEvent = "poll_request"
) )
const ( // MessageIDLength is the length of a randomly generated message ID
MessageIDLength = 12 const MessageIDLength = 12
)
// Errors for message operations
var ( var (
ErrUnexpectedMessageType = errors.New("unexpected message type") ErrUnexpectedMessageType = errors.New("unexpected message type")
ErrMessageNotFound = errors.New("message not found") ErrMessageNotFound = errors.New("message not found")
@@ -197,6 +197,7 @@ func (t SinceMarker) ID() string {
return t.id return t.id
} }
// Common SinceMarker values for subscribing to messages
var ( var (
SinceAllMessages = SinceMarker{time.Unix(0, 0), ""} SinceAllMessages = SinceMarker{time.Unix(0, 0), ""}
SinceNoMessages = SinceMarker{time.Unix(1, 0), ""} SinceNoMessages = SinceMarker{time.Unix(1, 0), ""}

View File

@@ -19,13 +19,16 @@ const (
messageIDLength = model.MessageIDLength messageIDLength = model.MessageIDLength
) )
// Sentinel values and errors // SinceMarker aliases
var ( var (
sinceAllMessages = model.SinceAllMessages sinceAllMessages = model.SinceAllMessages
sinceNoMessages = model.SinceNoMessages sinceNoMessages = model.SinceNoMessages
sinceLatestMessage = model.SinceLatestMessage sinceLatestMessage = model.SinceLatestMessage
errUnexpectedMessageType = model.ErrUnexpectedMessageType )
errMessageNotFound = model.ErrMessageNotFound
// Error aliases
var (
errMessageNotFound = model.ErrMessageNotFound
) )
// Constructors and helpers // Constructors and helpers

View File

@@ -94,38 +94,6 @@ func nullInt64(v int64) sql.NullInt64 {
return sql.NullInt64{Int64: v, Valid: true} return sql.NullInt64{Int64: v, Valid: true}
} }
// execTx executes a function in a transaction. If the function returns an error, the transaction is rolled back.
func execTx(db *sql.DB, f func(tx *sql.Tx) error) error {
tx, err := db.Begin()
if err != nil {
return err
}
defer tx.Rollback()
if err := f(tx); err != nil {
return err
}
return tx.Commit()
}
// queryTx executes a function in a transaction and returns the result. If the function
// returns an error, the transaction is rolled back.
func queryTx[T any](db *sql.DB, f func(tx *sql.Tx) (T, error)) (T, error) {
tx, err := db.Begin()
if err != nil {
var zero T
return zero, err
}
defer tx.Rollback()
t, err := f(tx)
if err != nil {
return t, err
}
if err := tx.Commit(); err != nil {
return t, err
}
return t, nil
}
// toSQLWildcard converts a wildcard string to a SQL wildcard string. It only allows '*' as wildcards, // toSQLWildcard converts a wildcard string to a SQL wildcard string. It only allows '*' as wildcards,
// and escapes '_', assuming '\' as escape character. // and escapes '_', assuming '\' as escape character.
func toSQLWildcard(s string) string { func toSQLWildcard(s string) string {