Actually make fucking interfaces
This commit is contained in:
@@ -8,30 +8,26 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/types"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
)
|
||||
|
||||
// CacheEntry represents a cached API response
|
||||
type CacheEntry struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
URLHash string `gorm:"uniqueIndex"`
|
||||
Response string `gorm:"type:text"`
|
||||
CachedAt time.Time `gorm:"index"`
|
||||
}
|
||||
// CacheEntry is now defined in the types package
|
||||
|
||||
// CachedESI implements ESIInterface with caching
|
||||
type CachedESI struct {
|
||||
direct ESIInterface
|
||||
db interface {
|
||||
GetCacheEntry(urlHash string) (*CacheEntry, error)
|
||||
SaveCacheEntry(entry *CacheEntry) error
|
||||
GetCacheEntry(urlHash string) (*types.CacheEntry, error)
|
||||
SaveCacheEntry(entry *types.CacheEntry) error
|
||||
}
|
||||
}
|
||||
|
||||
// NewCachedESI creates a new CachedESI instance
|
||||
func NewCachedESI(direct ESIInterface, db interface {
|
||||
GetCacheEntry(urlHash string) (*CacheEntry, error)
|
||||
SaveCacheEntry(entry *CacheEntry) error
|
||||
GetCacheEntry(urlHash string) (*types.CacheEntry, error)
|
||||
SaveCacheEntry(entry *types.CacheEntry) error
|
||||
}) *CachedESI {
|
||||
return &CachedESI{
|
||||
direct: direct,
|
||||
@@ -113,13 +109,13 @@ func (c *CachedESI) getCachedResponse(url string, fetchFunc func() (interface{},
|
||||
return result, nil
|
||||
}
|
||||
|
||||
cacheEntry = CacheEntry{
|
||||
cacheEntry = &types.CacheEntry{
|
||||
URLHash: urlHash,
|
||||
Response: string(responseBytes),
|
||||
CachedAt: time.Now(),
|
||||
}
|
||||
|
||||
if err := c.db.SaveCacheEntry(&cacheEntry); err != nil {
|
||||
if err := c.db.SaveCacheEntry(cacheEntry); err != nil {
|
||||
logger.Warning("Failed to cache response: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user