KubFly SDK for Go / bucket/mem
package mem
import "kubfly.io/sdk/bucket/mem"
Package mem is the memory of the process as a bucket — the io.kubfly.sdk.bucket.mem package of the Java SDK: for tests and for reading in the same process what was just written (kubfly.io/sdk/kubflytest). Linking it in registers the kind MEM (KUBFLY_BUCKET_KIND=MEM). Every Build is a new, empty bucket: the objects live as long as the bucket, so whoever writes and whoever reads share it.
Types
type Bucket
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is a bucket in memory: objects by key and their keys sorted in the order of their bytes — that of UTF-8, as S3 lists them — the same rules of keys and ranges as the other kinds. Safe for concurrent use; a write replaces an object whole, a reader sees the old object or the new one. Unlike the file system, a key may be both an object and a level of other keys (a and a/b), as in S3. No measures of operations: there is no input or output to measure.
func (*Bucket) Builder
func (s *Bucket) Builder() bucket.Builder
Builder are the settings of this bucket.
func (*Bucket) Bytes
func (s *Bucket) Bytes(ctx context.Context, key string) (util.Option[bucket.Stored[[]byte]], error)
Bytes are the bytes of an object, a copy.
func (*Bucket) BytesRange
func (s *Bucket) BytesRange(ctx context.Context, key string, offset int64, length int) (util.Option[bucket.Stored[[]byte]], error)
BytesRange is a range of the bytes of an object, a copy.
func (*Bucket) Close
func (s *Bucket) Close() error
Close keeps the objects: they stay as long as the bucket.
func (*Bucket) Create
func (s *Bucket) Create(ctx context.Context, key string, data []byte) (bool, error)
Create writes an object only if there is none with the key, in one step.
func (*Bucket) Delete
func (s *Bucket) Delete(ctx context.Context, key string) error
Delete removes an object; nothing if there is none.
func (*Bucket) Find
func (s *Bucket) Find(ctx context.Context, key string) (util.Option[bucket.Obj], error)
Find are the fields of an object.
func (*Bucket) List
func (s *Bucket) List(ctx context.Context, prefix string) iter.Seq2[bucket.Obj, error]
List are the objects of a prefix, by key.
func (*Bucket) ListFilter
func (s *Bucket) ListFilter(ctx context.Context, prefix string, filter bucket.Filter) iter.Seq2[bucket.Obj, error]
ListFilter are the objects of a prefix that match a filter, by key; every iteration reads the map anew.
func (*Bucket) Put
func (s *Bucket) Put(ctx context.Context, key string, data []byte) error
Put writes an object, a copy of the bytes.
func (*Bucket) PutStream
func (s *Bucket) PutStream(ctx context.Context, key string, data func() (io.ReadCloser, error), length int64) error
PutStream writes an object from a stream: one stream is taken; a stream of another length writes nothing.
func (*Bucket) String
func (s *Bucket) String() string
String is the kind and the count of objects.
func (*Bucket) Time
func (s *Bucket) Time() util.Option[bucket.BucketTime]
Time is None: memory has no clock of its own.
type Builder
type Builder struct {
// contains filtered or unexported fields
}
Builder is the memory as a bucket (the kind MEM): the prefix of a stand only.
func NewBuilder
func NewBuilder() Builder
NewBuilder is the kind MEM.
func (Builder) Build
func (b Builder) Build() (bucket.Bucket, error)
Build is a new, empty bucket; under the prefix of the stand, if any.
func (Builder) Env
func (b Builder) Env(envPrefix string, env map[string]string) (bucket.Builder, error)
Env is this builder filled from <ENV_PREFIX>_BUCKET_PREFIX: a bucket in memory has no other settings.
func (Builder) Kind
func (b Builder) Kind() string
Kind is the name of the kind: MEM.
func (Builder) Prefix
func (b Builder) Prefix() string
Prefix is the prefix of the stand, "" — none.
func (Builder) String
func (b Builder) String() string
String is the text form.
func (Builder) WithPrefix
func (b Builder) WithPrefix(prefix string) bucket.Builder
WithPrefix is this builder with the prefix of a stand ("" — none); checked by Build.