Proper context.Context usage

This commit is contained in:
Caleb Gardner
2024-10-24 00:00:08 -05:00
parent fcab9458ee
commit 6965917e76
19 changed files with 126 additions and 118 deletions
+15 -12
View File
@@ -1,6 +1,9 @@
package backend
import "errors"
import (
"context"
"errors"
)
var (
ErrNotFound = errors.New("no matches found in table")
@@ -11,28 +14,28 @@ type IDStruct interface {
}
type Table[T IDStruct] interface {
Get(ID string) (data *T, err error)
Find(values map[string]any) ([]T, error)
Insert(data T) error
Remove(ID string) error
FullUpdate(ID string, data T) error
PartUpdate(ID string, update map[string]any) error
Get(ctx context.Context, ID string) (data *T, err error)
Find(ctx context.Context, values map[string]any) ([]T, error)
Insert(ctx context.Context, data T) error
Remove(ctx context.Context, ID string) error
FullUpdate(ctx context.Context, ID string, data T) error
PartUpdate(ctx context.Context, ID string, update map[string]any) error
}
type CountTable interface {
Table[CountLog]
// Remove all Log items that have a CountLog.Date value less then the given value.
RemoveOldLogs(date int) error
RemoveOldLogs(ctx context.Context, date int) error
// Get count. If platform is an empty string or "all", the full count should be given
Count(platform string) (int, error)
Count(ctx context.Context, platform string) (int, error)
}
type CrashTable interface {
Table[CrashReport]
// Move a crash type to archive. Crashes that match the archived crash will be automatically removed from the CrashTable.
Archive(ArchivedCrash) error
IsArchived(IndividualCrash) bool
Archive(context.Context, ArchivedCrash) error
IsArchived(context.Context, IndividualCrash) bool
// Add the IndividualCrash report to the crash table. If a CrashReport exists that matches, then it gets added to CrashReport.Individual.
// If an IndividualCrash exists that is a perfect match, Count is incremented instead of adding it to the array.
InsertCrash(IndividualCrash) error
InsertCrash(context.Context, IndividualCrash) error
}