| 34 | } |
| 35 | |
| 36 | func (s *HashClient) Offline(ctx context.Context, resources ...*gateway.HashRelease) error { |
| 37 | s.client.Begin(ctx) |
| 38 | for _, r := range resources { |
| 39 | if len(r.HashMap) == 0 { |
| 40 | err := s.client.HDelAll(ctx, r.HashKey) |
| 41 | if err != nil { |
| 42 | s.client.Rollback(ctx) |
| 43 | return err |
| 44 | } |
| 45 | } |
| 46 | for key, _ := range r.HashMap { |
| 47 | err := s.client.HDel(ctx, r.HashKey, key) |
| 48 | if err != nil { |
| 49 | s.client.Rollback(ctx) |
| 50 | return err |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | return s.client.Commit(ctx) |
| 55 | } |
| 56 | |
| 57 | func NewHashClient(client admin_client.Client) *HashClient { |
| 58 | return &HashClient{client: client} |