Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
feat: Initial Implementation of Servicer (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
abyss-w authored Aug 30, 2021
1 parent f0e5a95 commit 35ffbc6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
6 changes: 6 additions & 0 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ type objectPageStatus struct {
func (i *objectPageStatus) ContinuationToken() string {
return i.marker
}

type storagePageStatus struct{}

func (i *storagePageStatus) ContinuationToken() string {
return ""
}
63 changes: 59 additions & 4 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,76 @@ package obs
import (
"context"

"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"

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) {
panic("not implemented")
pairs := append(opt.pairs, ps.WithName(name))

st, err := s.newStorage(pairs...)
if err != nil {
return nil, err
}

input := &obs.CreateBucketInput{
Bucket: name,
}

_, err = s.service.CreateBucket(input)
if err != nil {
return nil, err
}

return st, nil
}

func (s *Service) delete(ctx context.Context, name string, opt pairServiceDelete) (err error) {
panic("not implemented")
_, err = s.service.DeleteBucket(name)
if err != nil {
return err
}

return nil
}

func (s *Service) get(ctx context.Context, name string, opt pairServiceGet) (store Storager, err error) {
panic("not implemented")
pairs := append(opt.pairs, ps.WithName(name))

st, err := s.newStorage(pairs...)
if err != nil {
return nil, err
}

return st, nil
}

func (s *Service) list(ctx context.Context, opt pairServiceList) (sti *StoragerIterator, err error) {
panic("not implemented")
input := &storagePageStatus{}

return NewStoragerIterator(ctx, s.nexStoragePage, input), nil
}

func (s *Service) nexStoragePage(ctx context.Context, page *StoragerPage) error {
input := &obs.ListBucketsInput{
QueryLocation: true,
}

output, err := s.service.ListBuckets(input)
if err != nil {
return err
}

for _, v := range output.Buckets {
store, err := s.newStorage(ps.WithName(v.Name))
if err != nil {
return err
}

page.Data = append(page.Data, store)
}

return IterateDone
}

0 comments on commit 35ffbc6

Please sign in to comment.