Documentation
¶
Overview ¶
S3 like native Golang storage.
This package provides a simple storage system, similar to Amazon S3. It allows to store and retrieve data by key. Data is stored in a directory, with each key being a file. The package provides functions to set, get, and delete data. It also provides an iterator to traverse over all data in the storage.
Index ¶
- type S3Lite
- func (s *S3Lite) Close()
- func (s *S3Lite) Del(key string) (err error)
- func (s *S3Lite) Dir(key string) (dir string)
- func (s *S3Lite) Get(key string) (value []byte, err error)
- func (s *S3Lite) IsFolder(key string) bool
- func (s *S3Lite) List(prefix string) iter.Seq[string]
- func (s *S3Lite) Set(key string, value []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type S3Lite ¶
type S3Lite struct {
// contains filtered or unexported fields
}
S3Lite is a wrapper for Badger database.
func New ¶
New creates a new S3 object.
The dbPath argument is the path to the directory where the Badger database files will be stored.
If the database connection can't be opened, an error is returned.
Example: s, err := s3.New("/path/to/db")
if err != nil {
log.Fatal(err)
}
func (*S3Lite) Del ¶
Del deletes a key-value pair from the database.
Parameters:
- key: the key to delete from the database.
Returns:
- error: an error if the Del operation fails.
Example: s, err := s3.New("/path/to/db")
if err != nil {
log.Fatal(err)
}
err = s.Del("key")
if err != nil {
log.Fatal(err)
}
func (*S3Lite) Get ¶
Get retrieves a value by its key from the database.
Parameters:
- key: the key to get from the database.
Returns:
- value: the value retrieved from the database.
- error: an error if the Get operation fails.
Example: s, err := s3.New("/path/to/db", "bucket")
if err != nil {
log.Fatal(err)
}
value, err := s.Get("key")
if err != nil {
log.Fatal(err)
}
func (*S3Lite) List ¶
List returns an iterator for all keys with given prefix.
The iterator yields each key that starts with the given prefix. The keys are yielded in lexicographical order.
Example: s, err := s3.New("/path/to/db", "bucket")
if err != nil {
log.Fatal(err)
}
keysIter, err := s.List("prefix")
if err != nil {
log.Fatal(err)
}
for keysIter.Next() {
key := keysIter.Value()
fmt.Println(key)
}
func (*S3Lite) Set ¶
Set sets a key-value pair in the database.
Parameters:
- key: the key to set in the database.
- value: the value to set in the database.
Returns:
- error: an error if the Set operation fails.
Example:
s, err := s3.New("/path/to/db")
if err != nil {
log.Fatal(err)
}
err = s.Set("key", []byte("value"))
if err != nil {
log.Fatal(err)
}