| 72 | } |
| 73 | |
| 74 | func writeAppsAutoCompleteCache(ctx context.Context, apps []*scalingo.App) error { |
| 75 | fd, err := os.OpenFile(appsCacheFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) |
| 76 | if err != nil { |
| 77 | return errors.Wrapf(ctx, err, "open apps cache file %s for write", appsCacheFile) |
| 78 | } |
| 79 | defer func() { _ = fd.Close() }() |
| 80 | cache := appsCache{ |
| 81 | Apps: apps, |
| 82 | CreatedAt: time.Now(), |
| 83 | } |
| 84 | err = gob.NewEncoder(fd).Encode(&cache) |
| 85 | if err != nil { |
| 86 | return errors.Wrap(ctx, err, "encode apps cache file") |
| 87 | } |
| 88 | |
| 89 | return nil |
| 90 | } |