MCPcopy Create free account
hub / github.com/Scalingo/cli / appsAutoCompleteCache

Function appsAutoCompleteCache

cmd/autocomplete/apps.go:55–72  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

53}
54
55func appsAutoCompleteCache(ctx context.Context) ([]*scalingo.App, error) {
56 fd, err := os.Open(appsCacheFile)
57 if err != nil {
58 return nil, errors.Wrapf(ctx, err, "open apps cache file %s", appsCacheFile)
59 }
60 defer fd.Close()
61 var cache appsCache
62 err = gob.NewDecoder(fd).Decode(&cache)
63 if err != nil {
64 return nil, errors.Wrap(ctx, err, "decode apps cache file")
65 }
66
67 if time.Since(cache.CreatedAt).Seconds() > appsCacheDuration {
68 return nil, errExpiredCache
69 }
70
71 return cache.Apps, nil
72}
73
74func writeAppsAutoCompleteCache(ctx context.Context, apps []*scalingo.App) error {
75 fd, err := os.OpenFile(appsCacheFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)

Callers 1

appsListFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected