Skip to content

Commit e2b50f7

Browse files
committed
upgrade go mods
1 parent 45a0784 commit e2b50f7

6 files changed

Lines changed: 62 additions & 55 deletions

File tree

cmd/server/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func main() {
107107

108108
// Create server
109109
prcostServer := server.New()
110+
if prcostServer == nil {
111+
logger.ErrorContext(ctx, "failed to initialize server (check cache configuration)")
112+
os.Exit(1)
113+
}
110114
prcostServer.SetCommit(GitCommit)
111115
prcostServer.SetCORSConfig(*corsOrigins, *allowAllCors)
112116
prcostServer.SetRateLimit(*rateLimit, *rateBurst)

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ module github.com/codeGROOVE-dev/prcost
33
go 1.25.4
44

55
require (
6+
github.com/codeGROOVE-dev/fido v1.10.0
7+
github.com/codeGROOVE-dev/fido/pkg/store/cloudrun v1.10.0
68
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22
79
github.com/codeGROOVE-dev/prx v0.0.0-20251109164430-90488144076d
8-
github.com/codeGROOVE-dev/sfcache v1.3.0
9-
github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun v1.3.0
1010
github.com/codeGROOVE-dev/turnclient v0.0.0-20251107215141-ee43672b3dc7
1111
golang.org/x/time v0.14.0
1212
)
1313

1414
require (
1515
github.com/codeGROOVE-dev/ds9 v0.8.0 // indirect
16+
github.com/codeGROOVE-dev/fido/pkg/store/compress v1.10.0 // indirect
17+
github.com/codeGROOVE-dev/fido/pkg/store/datastore v1.10.0 // indirect
18+
github.com/codeGROOVE-dev/fido/pkg/store/localfs v1.10.0 // indirect
1619
github.com/codeGROOVE-dev/retry v1.3.0 // indirect
17-
github.com/codeGROOVE-dev/sfcache/pkg/persist/datastore v1.3.0 // indirect
18-
github.com/codeGROOVE-dev/sfcache/pkg/persist/localfs v1.3.0 // indirect
20+
github.com/klauspost/compress v1.18.2 // indirect
21+
github.com/puzpuzpuz/xsync/v4 v4.2.0 // indirect
1922
)

go.sum

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
github.com/codeGROOVE-dev/ds9 v0.8.0 h1:A23VvL1YzUBZyXNYmF5u0R6nPcxQitPeLo8FFk6OiUs=
22
github.com/codeGROOVE-dev/ds9 v0.8.0/go.mod h1:0UDipxF1DADfqM5GtjefgB2u+EXdDgOKmxVvrSGLHoM=
3+
github.com/codeGROOVE-dev/fido v1.10.0 h1:i4Wb6LDd5nD/4Fnp47KAVUVhG1O1mN5jSRbCYPpBYjw=
4+
github.com/codeGROOVE-dev/fido v1.10.0/go.mod h1:/mqfMeKCTYTGt/Y0cWm6gh8gYBKG1w8xBsTDmu+A/pU=
5+
github.com/codeGROOVE-dev/fido/pkg/store/cloudrun v1.10.0 h1:0Wvs3JE+TI8GsEkh0jg0SglyFyIkBewPSl0PTUSVqEo=
6+
github.com/codeGROOVE-dev/fido/pkg/store/cloudrun v1.10.0/go.mod h1:MaxO6QGv89FrZB1D+stiZjRcbaMUfiw7yYGkaqOoJ2k=
7+
github.com/codeGROOVE-dev/fido/pkg/store/compress v1.10.0 h1:W3AYtR6eyPHQ8QhTsuqjNZYWk/Fev0cJiAiuw04uhlk=
8+
github.com/codeGROOVE-dev/fido/pkg/store/compress v1.10.0/go.mod h1:0hFYQ8Y6jfrYuJb8eBimYz66tg7DDuVWbZqaI944LQM=
9+
github.com/codeGROOVE-dev/fido/pkg/store/datastore v1.10.0 h1:vCsLeESGQvW7F8pJJimZhRjzWmrQg1WZgT22om9fT/Q=
10+
github.com/codeGROOVE-dev/fido/pkg/store/datastore v1.10.0/go.mod h1:LtpO9TUi92D7uLBXJu+kLWVpRmEtVRAWVB2EdzNU0JQ=
11+
github.com/codeGROOVE-dev/fido/pkg/store/localfs v1.10.0 h1:oaPwuHHBuzhsWnPm7UCxgwjz7+jG3O0JenSSgPSwqv8=
12+
github.com/codeGROOVE-dev/fido/pkg/store/localfs v1.10.0/go.mod h1:zUGzODSWykosAod0IHycxdxUOMcd2eVqd6eUdOsU73E=
313
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22 h1:gtN3rOc6YspO646BkcOxBhPjEqKUz+jl175jIqglfDg=
414
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22/go.mod h1:KV+w19ubP32PxZPE1hOtlCpTaNpF0Bpb32w5djO8UTg=
515
github.com/codeGROOVE-dev/prx v0.0.0-20251109164430-90488144076d h1:KKt93PVYR9Uga8uLPq0HoNlXVW3BTPHGBBxEb5YBxf4=
616
github.com/codeGROOVE-dev/prx v0.0.0-20251109164430-90488144076d/go.mod h1:FEy3gz9IYDXWnKWkoDSL+pWu6rujxbBSrF4w5A8QSK0=
717
github.com/codeGROOVE-dev/retry v1.3.0 h1:/+ipAWRJLL6y1R1vprYo0FSjSBvH6fE5j9LKXjpD54g=
818
github.com/codeGROOVE-dev/retry v1.3.0/go.mod h1:8OgefgV1XP7lzX2PdKlCXILsYKuz6b4ZpHa/20iLi8E=
9-
github.com/codeGROOVE-dev/sfcache v1.3.0 h1:Ew900GWXkZhMEU560kz0Nk1HvhGshiqaIASbTH+ihHg=
10-
github.com/codeGROOVE-dev/sfcache v1.3.0/go.mod h1:ksV5Y1RwKmOPZZiV0zXpsBOENGUCgO0fVgr/P8f/DJM=
11-
github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun v1.3.0 h1:Gv9O+dC5qBSILsgoDJiXmKarhv0YpXPlFqP6E+5GNhc=
12-
github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun v1.3.0/go.mod h1:tKNn82T+694Dt9A/fHGoU2dz6WWhC5vvGEIovcgjORM=
13-
github.com/codeGROOVE-dev/sfcache/pkg/persist/datastore v1.3.0 h1:4b/kQPdPqmei+nVa3REBSMoc7vuzfG6QMljd4WIT5oQ=
14-
github.com/codeGROOVE-dev/sfcache/pkg/persist/datastore v1.3.0/go.mod h1:FPHOsiIpoH4frpGpxsrdjU1WTVOQG8/D0UvW6hXW4UM=
15-
github.com/codeGROOVE-dev/sfcache/pkg/persist/localfs v1.3.0 h1:7zKbd7aHVzmbK2eEbdsf6Dknrte/o8+7I6GkNob8bGA=
16-
github.com/codeGROOVE-dev/sfcache/pkg/persist/localfs v1.3.0/go.mod h1:vHDjjehmi+yjXD+DXVG0rnc4iOBsiIknLThqpkYwA/c=
1719
github.com/codeGROOVE-dev/turnclient v0.0.0-20251107215141-ee43672b3dc7 h1:183q0bj2y/9hh/K0HZvDXI6sG7liYSRcQVgFx0GY+UA=
1820
github.com/codeGROOVE-dev/turnclient v0.0.0-20251107215141-ee43672b3dc7/go.mod h1:dVS3MlJDgL6WkfurJAyS7I9Fe1yxxoxxarjVifY5bIo=
21+
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
22+
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
23+
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
24+
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
25+
github.com/puzpuzpuz/xsync/v4 v4.2.0 h1:dlxm77dZj2c3rxq0/XNvvUKISAmovoXF4a4qM6Wvkr0=
26+
github.com/puzpuzpuz/xsync/v4 v4.2.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
1927
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
2028
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=

internal/server/server.go

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"sync"
2121
"time"
2222

23+
"github.com/codeGROOVE-dev/fido"
24+
"github.com/codeGROOVE-dev/fido/pkg/store/cloudrun"
2325
"github.com/codeGROOVE-dev/gsm"
2426
"github.com/codeGROOVE-dev/prcost/pkg/cost"
2527
"github.com/codeGROOVE-dev/prcost/pkg/github"
26-
"github.com/codeGROOVE-dev/sfcache"
27-
"github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun"
2828
"golang.org/x/time/rate"
2929
)
3030

@@ -78,11 +78,11 @@ type Server struct {
7878
allowAllCors bool
7979
validateTokens bool
8080
r2rCallout bool
81-
// Caching using sfcache (memory + optional persistence).
82-
githubCache *sfcache.TieredCache[string, any] // Unified 72h cache for all GitHub queries
83-
prDataCache *sfcache.TieredCache[string, cost.PRData] // 6-day cache for PR detail data
84-
calcResultCache *sfcache.TieredCache[string, cost.Breakdown] // 6-day cache for calculation results
85-
githubClient *github.Client // Cached GitHub API client
81+
// Caching using fido (memory + optional persistence).
82+
githubCache *fido.TieredCache[string, any] // Unified 72h cache for all GitHub queries
83+
prDataCache *fido.TieredCache[string, cost.PRData] // 6-day cache for PR detail data
84+
calcResultCache *fido.TieredCache[string, cost.Breakdown] // 6-day cache for calculation results
85+
githubClient *github.Client // Cached GitHub API client
8686
}
8787

8888
// CalculateRequest represents a request to calculate PR costs.
@@ -179,17 +179,17 @@ func New() *Server {
179179
dbName = "prcost"
180180
}
181181

182-
// Initialize caches with sfcache (automatically handles memory + persistence).
182+
// Initialize caches with fido (automatically handles memory + persistence).
183183
// cloudrun.New uses Cloud Datastore when K_SERVICE is set (Cloud Run/Knative), local files otherwise.
184184
// Single unified cache with 72-hour TTL for all GitHub query results.
185185
githubPersist, err := cloudrun.New[string, any](ctx, dbName)
186186
if err != nil {
187-
logger.ErrorContext(ctx, "Failed to initialize GitHub cache persistence", "error", err)
187+
logger.ErrorContext(ctx, "Failed to initialize GitHub cache persistence", "error", err, "db", dbName)
188188
return nil
189189
}
190-
githubCache, err := sfcache.NewTiered[string, any](githubPersist,
191-
sfcache.TTL(72*time.Hour),
192-
sfcache.Size(2000),
190+
githubCache, err := fido.NewTiered[string, any](githubPersist,
191+
fido.TTL(72*time.Hour),
192+
fido.Size(2000),
193193
)
194194
if err != nil {
195195
logger.ErrorContext(ctx, "Failed to initialize GitHub cache", "error", err)
@@ -199,12 +199,12 @@ func New() *Server {
199199
// Separate caches for non-GitHub data with 6-day TTL
200200
prDataPersist, err := cloudrun.New[string, cost.PRData](ctx, dbName)
201201
if err != nil {
202-
logger.ErrorContext(ctx, "Failed to initialize PR data cache persistence", "error", err)
202+
logger.ErrorContext(ctx, "Failed to initialize PR data cache persistence", "error", err, "db", dbName)
203203
return nil
204204
}
205-
prDataCache, err := sfcache.NewTiered[string, cost.PRData](prDataPersist,
206-
sfcache.TTL(6*24*time.Hour),
207-
sfcache.Size(1000),
205+
prDataCache, err := fido.NewTiered[string, cost.PRData](prDataPersist,
206+
fido.TTL(6*24*time.Hour),
207+
fido.Size(1000),
208208
)
209209
if err != nil {
210210
logger.ErrorContext(ctx, "Failed to initialize PR data cache", "error", err)
@@ -213,12 +213,12 @@ func New() *Server {
213213

214214
calcResultPersist, err := cloudrun.New[string, cost.Breakdown](ctx, dbName)
215215
if err != nil {
216-
logger.ErrorContext(ctx, "Failed to initialize calc result cache persistence", "error", err)
216+
logger.ErrorContext(ctx, "Failed to initialize calc result cache persistence", "error", err, "db", dbName)
217217
return nil
218218
}
219-
calcResultCache, err := sfcache.NewTiered[string, cost.Breakdown](calcResultPersist,
220-
sfcache.TTL(6*24*time.Hour),
221-
sfcache.Size(1000),
219+
calcResultCache, err := fido.NewTiered[string, cost.Breakdown](calcResultPersist,
220+
fido.TTL(6*24*time.Hour),
221+
fido.Size(1000),
222222
)
223223
if err != nil {
224224
logger.ErrorContext(ctx, "Failed to initialize calc result cache", "error", err)
@@ -357,9 +357,9 @@ func (s *Server) limiter(ctx context.Context, ip string) *rate.Limiter {
357357
return lim
358358
}
359359

360-
// simpleCache implements github.Cache interface using a single sfcache[string, any].
360+
// simpleCache implements github.Cache interface using a single fido.TieredCache[string, any].
361361
type simpleCache struct {
362-
cache *sfcache.TieredCache[string, any]
362+
cache *fido.TieredCache[string, any]
363363
logger *slog.Logger
364364
}
365365

@@ -370,44 +370,37 @@ func (s *simpleCache) Get(ctx context.Context, key string) (any, bool) {
370370
s.logger.WarnContext(ctx, "Cache error", "key", key, "error", err)
371371
return nil, false
372372
}
373-
if found {
374-
s.logger.DebugContext(ctx, "Cache hit", "key", key)
375-
}
376373
return val, found
377374
}
378375

379376
func (s *simpleCache) Set(ctx context.Context, key string, value any) {
380377
key = sanitizeCacheKey(key)
381-
if err := s.cache.Set(ctx, key, value, 0); err != nil {
378+
if err := s.cache.Set(ctx, key, value); err != nil {
382379
s.logger.WarnContext(ctx, "Failed to cache value", "key", key, "error", err)
383380
}
384381
}
385382

386-
// cachedPRData retrieves cached PR data using sfcache.
383+
// cachedPRData retrieves cached PR data using fido.
387384
func (s *Server) cachedPRData(ctx context.Context, key string) (cost.PRData, bool) {
388385
key = sanitizeCacheKey(key)
389386
prData, found, err := s.prDataCache.Get(ctx, key)
390387
if err != nil {
391388
s.logger.WarnContext(ctx, "PR data cache error", "key", key, "error", err)
392389
return cost.PRData{}, false
393390
}
394-
if found {
395-
s.logger.DebugContext(ctx, "PR data cache hit", "key", key)
396-
}
397391
return prData, found
398392
}
399393

400-
// cachePRData stores PR data using sfcache.
394+
// cachePRData stores PR data using fido.
401395
func (s *Server) cachePRData(ctx context.Context, key string, prData cost.PRData) {
402396
key = sanitizeCacheKey(key)
403-
// Uses the default TTL configured during initialization (6 days)
404-
if err := s.prDataCache.Set(ctx, key, prData, 0); err != nil {
397+
if err := s.prDataCache.Set(ctx, key, prData); err != nil {
405398
s.logger.WarnContext(ctx, "Failed to cache PR data", "key", key, "error", err)
406399
}
407400
}
408401

409-
// sanitizeCacheKey replaces characters not allowed by sfcache persistence layer.
410-
// sfcache only allows: alphanumeric, dash, underscore, period, colon.
402+
// sanitizeCacheKey replaces characters not allowed by fido persistence layer.
403+
// fido only allows: alphanumeric, dash, underscore, period, colon.
411404
// We replace: / with _ and = with -.
412405
func sanitizeCacheKey(key string) string {
413406
key = strings.ReplaceAll(key, "/", "_")
@@ -429,7 +422,7 @@ func configHash(cfg cost.Config) string {
429422
cfg.DeliveryDelayFactor)
430423
}
431424

432-
// cachedCalcResult retrieves cached calculation result using sfcache.
425+
// cachedCalcResult retrieves cached calculation result using fido.
433426
func (s *Server) cachedCalcResult(ctx context.Context, prURL string, cfg cost.Config) (cost.Breakdown, bool) {
434427
key := sanitizeCacheKey(fmt.Sprintf("calc:%s:%s", prURL, configHash(cfg)))
435428
breakdown, found, err := s.calcResultCache.Get(ctx, key)
@@ -440,11 +433,10 @@ func (s *Server) cachedCalcResult(ctx context.Context, prURL string, cfg cost.Co
440433
return breakdown, found
441434
}
442435

443-
// cacheCalcResult stores calculation result using sfcache.
436+
// cacheCalcResult stores calculation result using fido.
444437
func (s *Server) cacheCalcResult(ctx context.Context, prURL string, cfg cost.Config, b *cost.Breakdown) {
445438
key := sanitizeCacheKey(fmt.Sprintf("calc:%s:%s", prURL, configHash(cfg)))
446-
// Uses the default TTL configured during initialization (6 days)
447-
if err := s.calcResultCache.Set(ctx, key, *b, 0); err != nil {
439+
if err := s.calcResultCache.Set(ctx, key, *b); err != nil {
448440
s.logger.WarnContext(ctx, "Failed to cache calc result", "key", key, "error", err)
449441
}
450442
}
@@ -466,7 +458,7 @@ func (s *Server) SetTokenValidation(appID string, keyFile string) error {
466458
// Shutdown gracefully shuts down the server.
467459
func (s *Server) Shutdown() {
468460
ctx := context.Background()
469-
// Close sfcache instances to flush any pending writes.
461+
// Close fido instances to flush any pending writes.
470462
if s.githubCache != nil {
471463
if err := s.githubCache.Close(); err != nil {
472464
s.logger.WarnContext(ctx, "Failed to close GitHub cache", "error", err)

internal/server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ func TestProcessRequestWithMock(t *testing.T) {
19431943

19441944
// Store in cache to simulate successful fetch
19451945
//nolint:errcheck // test setup - errors don't matter
1946-
_ = s.prDataCache.Set(ctx, "https://github.com/test/repo/pull/123", *mockData, 0)
1946+
_ = s.prDataCache.Set(ctx, "https://github.com/test/repo/pull/123", *mockData)
19471947

19481948
req := &CalculateRequest{
19491949
URL: "https://github.com/test/repo/pull/123",
@@ -2455,7 +2455,7 @@ func TestCachedPRDataMissCache(t *testing.T) {
24552455
}
24562456

24572457
// TestCachedPRQueryBadType and TestCachedPRDataBadType removed:
2458-
// sfcache uses generic types, so type mismatches are impossible at compile time.
2458+
// fido uses generic types, so type mismatches are impossible at compile time.
24592459

24602460
func TestLimiterCleanupLarge(t *testing.T) {
24612461
s := New()

pkg/github/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// Cache is a simple interface for caching any type of data.
19-
// The server provides this via sfcache, with proper TTLs for each data type.
19+
// The server provides this via fido, with proper TTLs for each data type.
2020
type Cache interface {
2121
Get(ctx context.Context, key string) (any, bool)
2222
Set(ctx context.Context, key string, value any)

0 commit comments

Comments
 (0)