This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
generated from beyondstorage/go-service-example
-
Notifications
You must be signed in to change notification settings - Fork 3
/
service.go
59 lines (51 loc) · 1.45 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package minio
import (
"context"
"github.com/minio/minio-go/v7"
ps "github.com/beyondstorage/go-storage/v4/pairs"
. "github.com/beyondstorage/go-storage/v4/types"
)
func (s *Service) create(ctx context.Context, name string, opt pairServiceCreate) (store Storager, err error) {
st, err := s.newStorage(ps.WithName(name))
if err != nil {
return nil, err
}
err = s.service.MakeBucket(ctx, name, minio.MakeBucketOptions{})
if err != nil {
return nil, err
}
return st, nil
}
func (s *Service) delete(ctx context.Context, name string, opt pairServiceDelete) (err error) {
err = s.service.RemoveBucket(ctx, name)
if err != nil {
return err
}
return nil
}
func (s *Service) get(ctx context.Context, name string, opt pairServiceGet) (store Storager, err error) {
st, err := s.newStorage(ps.WithName(name))
if err != nil {
return nil, err
}
return st, nil
}
func (s *Service) list(ctx context.Context, opt pairServiceList) (sti *StoragerIterator, err error) {
input := &storagePageStatus{}
return NewStoragerIterator(ctx, s.nextStoragePage, input), nil
}
func (s *Service) nextStoragePage(ctx context.Context, page *StoragerPage) (err error) {
input := page.Status.(*storagePageStatus)
input.buckets, err = s.service.ListBuckets(ctx)
if err != nil {
return err
}
for _, v := range input.buckets {
store, err := s.newStorage(ps.WithName(v.Name))
if err != nil {
return err
}
page.Data = append(page.Data, store)
}
return IterateDone
}