lino_s3

package module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 20 Imported by: 0

README

Lino S3

High level S3 wrapper for Go.

Usage

[Must]LoadS3(dsn string) -> LinoS3
[Must]LoadS3Bucket(dsn string) -> LinoS3Bucket
[Must]LoadS3Object(dsn string) -> LinoS3Object
[Must]LoadS3Path(dsn string) -> LinoS3Path

NewLinoS3(client *s3.Client) -> LinoS3

LinoS3
  -> UseInterceptors(...interceptors) -> LinoS3 (sub entities will inherit these interceptors)
  -> Bucket(bucketName) -> LinoS3Bucket

LinoS3Bucket
  -> UseInterceptors(...interceptors) -> LinoS3Bucket
  -> Object(key) -> LinoS3Object
  -> SubPath(subPath) -> LinoS3Path
  -> Piece(objectKey, start, end) -> LinoS3Piece
  -> PieceByKey(pieceKey) -> LinoS3Piece

LinoS3Path
  -> UseInterceptors(...interceptors) -> LinoS3Path
  -> Object(key) -> LinoS3Object
  -> SubPath(subPath) -> LinoS3Path

LinoS3Object
  -> UseInterceptors(...interceptors) -> LinoS3Path
  -> HasInterceptors() -> bool
  -> Piece(start, end) -> LinoS3Piece

  -> Get() -> *s3.GetObjectOutput
  -> Put(s3.PutObjectInput) -> *s3.PutObjectOutput
     // key and bucket in input will be overrided,so it is not necessary to set them
  -> Upload(s3manager.UploadInput) -> *s3manager.UploadOutput
  -> Delete() => *s3.DeleteObjectOutput

  -> ReadTo(io.Writer)
  -> ReadBuffer() -> buffer
  -> ReadString() -> string
  -> ReadJSON(&value) // encoding/json
  -> ReadCBOR(&value) // github.com/fxamacker/cbor/v2
  -> ReadCSV(&value)  // github.com/gocarina/gocsv

  -> WriteFrom(io.Reader, contentType? string)
  -> WriteBuffer(buffer, contentType? string)
  -> WriteString(string, contentType? string)
  -> WriteJSON(&value)
  -> WriteCBOR(&value)
  -> WriteCSV(&value)

  -> Key() -> string // pieceKey

LinoS3Piece
  -> Get() -> *s3.GetObjectOutput

  -> ReadTo(io.Writer)
  -> ReadBuffer() -> buffer
  -> ReadString() -> string
  -> ReadJSON(&value)
  -> ReadCBOR(&value)
  -> ReadCSV(&value)

  -> Key() -> string // pieceKey
interceptors
import (
  "github.com/linolabx/lino_s3"
  "github.com/linolabx/lino_s3/interceptors"
)

s3 := lino_s3.NewLinoS3(client).Bucket("bucket")
blocksDir := bucket.SubPath("blocks-v1").UseInterceptors(interceptors.Gzip)

block SomeStruct
blockObject := blocksDir.Object("somekey.gz").ReadCBOR(&block);

block.SomeField = "new value"
blockObject.WriteCBOR(&block)
utils
import "github.com/linolabx/lino_s3"

lino_s3.Hash("mykey") // "9adbe0b3033881f88ebd825bcf763b43"
lino_s3.ShardT("mykey", "{.}") // "mykey"
lino_s3.ShardT("mykey", "{hash}") // "9adbe0b3033881f88ebd825bcf763b43"
lino_s3.ShardT("mykey", "{shard.l3}/{.}") // "9a/db/e0/mykey"
lino_s3.ShardT("mykey", "{shard}/{.}") // "9a/db/e0/mykey" (defaults to shard.l3)
lino_s3.ShardT("mykey", "{shard.l4}/{.}") // "9a/db/e0/b3/mykey"
lino_s3.ShardT("mykey", "{shard.l2}/{hash}") // "9a/db/9adbe0b3033881f88ebd825bcf763b43"
lino_s3.ShardT("mykey", "{shard}/%d.%s", 1, "jpg") // "9a/db/e0/1.jpg"
structures

LinoS3Map

import (
  "github.com/linolabx/lino_s3"
  "github.com/linolabx/lino_s3/structures/lino_s3_map"
)

bucket := s3.Bucket("bucket")
obj := bucket.Object("my-map")

someMap := lino_s3_map.NewMap(obj)
someMap.Set("foo1", []byte{"bar1"})
someMap.Set("foo2", []byte{"bar2"})
// save index of items in the first bytes, and then items
someMap.Save()

// read bytes from memory
someMap.Get("foo1") // []byte{"bar1"}

// directly read required bytes from s3
pieceKey, _ := someMap.PieceKey("foo1")
bucket.PieceByKey(pieceKey).ReadBuffer() // []byte{"bar1"}

// load map index, and then read required bytes from s3
secondMap := lino_s3_map.LoadMap(obj)
secondMap.Get("foo1") // []byte{"bar1"}

// load entire map, and then read required bytes from memory
thirdMap := lino_s3_map.NewMap(obj)
thirdMap.Get("foo1") // []byte{"bar1"}

Develop

start minio, and default access key and secret key is minioadmin:minioadmin

docker run --name lino-s3-test --rm -p 9000:9000 -e MINIO_ROOT_USER=minioadmin -e MINIO_ROOT_PASSWORD=minioadmin minio/minio server /data

docker exec -it lino-s3-test mc alias set minio http://localhost:9000 minioadmin minioadmin
docker exec -it lino-s3-test mc mb minio/lino-stor

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash added in v0.0.7

func Hash(s string) string

func ShardT added in v0.0.7

func ShardT(input string, template string, values ...any) string

Types

type Interceptor

type Interceptor struct {
	PreHead    transformer[*s3.HeadObjectInput]
	PostHead   transformer[*s3.HeadObjectOutput]
	PreGet     transformer[*s3.GetObjectInput]
	PostGet    transformer[*s3.GetObjectOutput]
	PrePut     transformer[*s3.PutObjectInput]
	PostPut    transformer[*s3.PutObjectOutput]
	PreDelete  transformer[*s3.DeleteObjectInput]
	PostDelete transformer[*s3.DeleteObjectOutput]
	PreUpload  transformer[*s3.PutObjectInput]
	PostUpload transformer[*manager.UploadOutput]
}

type LinoS3

type LinoS3 struct {
	// contains filtered or unexported fields
}

func LoadS3 added in v0.0.4

func LoadS3(dsn string) (*LinoS3, error)

func MustLoadS3 added in v0.0.4

func MustLoadS3(dsn string, logger ...utils.Logger) *LinoS3

func NewLinoS3

func NewLinoS3(client *s3.Client, presignClient ...*s3.PresignClient) *LinoS3

func (*LinoS3) Bucket

func (s *LinoS3) Bucket(bucketname string) *LinoS3Bucket

func (*LinoS3) UseInterceptors

func (s *LinoS3) UseInterceptors(interceptors ...*Interceptor) *LinoS3

func (*LinoS3) UsePresignClient added in v0.0.9

func (s *LinoS3) UsePresignClient(presignClient *s3.PresignClient) *LinoS3

type LinoS3Bucket

type LinoS3Bucket struct {
	// contains filtered or unexported fields
}

func LoadS3Bucket added in v0.0.4

func LoadS3Bucket(dsn string) (*LinoS3Bucket, error)

func MustLoadS3Bucket added in v0.0.4

func MustLoadS3Bucket(dsn string, logger ...utils.Logger) *LinoS3Bucket

func (*LinoS3Bucket) Object

func (s *LinoS3Bucket) Object(key string) *LinoS3Object

func (*LinoS3Bucket) Piece added in v0.0.2

func (s *LinoS3Bucket) Piece(key string, start int64, end int64) *LinoS3Piece

func (*LinoS3Bucket) PieceByKey added in v0.0.2

func (s *LinoS3Bucket) PieceByKey(pieceKey string) (*LinoS3Piece, error)

func (*LinoS3Bucket) SubPath

func (s *LinoS3Bucket) SubPath(path string) *LinoS3Path

func (*LinoS3Bucket) UseInterceptors

func (s *LinoS3Bucket) UseInterceptors(interceptors ...*Interceptor) *LinoS3Bucket

type LinoS3Object

type LinoS3Object struct {
	// contains filtered or unexported fields
}

func LoadS3Object added in v0.0.4

func LoadS3Object(dsn string) (*LinoS3Object, error)

func MustLoadS3Object added in v0.0.4

func MustLoadS3Object(dsn string, logger ...utils.Logger) *LinoS3Object

func (*LinoS3Object) Delete

func (s *LinoS3Object) Delete() (*s3.DeleteObjectOutput, error)

func (*LinoS3Object) Get

func (s *LinoS3Object) Get() (*s3.GetObjectOutput, error)

func (*LinoS3Object) HasInterceptors added in v0.0.2

func (s *LinoS3Object) HasInterceptors() bool

func (*LinoS3Object) Head

func (s *LinoS3Object) Head() (*s3.HeadObjectOutput, error)

func (*LinoS3Object) Key added in v0.0.2

func (s *LinoS3Object) Key() string

func (*LinoS3Object) Piece added in v0.0.2

func (s *LinoS3Object) Piece(start int64, end int64) *LinoS3Piece

func (*LinoS3Object) PresignGet added in v0.0.5

func (s *LinoS3Object) PresignGet(optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error)

func (*LinoS3Object) PresignPut added in v0.0.5

func (s *LinoS3Object) PresignPut(input s3.PutObjectInput, optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error)

func (*LinoS3Object) Put

func (*LinoS3Object) ReadBuffer

func (s *LinoS3Object) ReadBuffer() ([]byte, error)

func (*LinoS3Object) ReadCBOR

func (s *LinoS3Object) ReadCBOR(v interface{}) error

func (*LinoS3Object) ReadCSV

func (s *LinoS3Object) ReadCSV(v interface{}) error

func (*LinoS3Object) ReadJSON

func (s *LinoS3Object) ReadJSON(v interface{}) error

func (*LinoS3Object) ReadString

func (s *LinoS3Object) ReadString() (string, error)

func (*LinoS3Object) ReadTo

func (s *LinoS3Object) ReadTo(writer io.WriteCloser) error

func (*LinoS3Object) Upload

func (s *LinoS3Object) Upload(input s3.PutObjectInput) (*manager.UploadOutput, error)

func (*LinoS3Object) UseInterceptors

func (s *LinoS3Object) UseInterceptors(interceptors ...*Interceptor) *LinoS3Object

func (*LinoS3Object) WriteBuffer

func (s *LinoS3Object) WriteBuffer(data []byte, contentType ...string) error

func (*LinoS3Object) WriteCBOR

func (s *LinoS3Object) WriteCBOR(v interface{}) error

func (*LinoS3Object) WriteCSV

func (s *LinoS3Object) WriteCSV(v interface{}) error

func (*LinoS3Object) WriteFrom

func (s *LinoS3Object) WriteFrom(reader io.ReadCloser, contentType ...string) error

func (*LinoS3Object) WriteJSON

func (s *LinoS3Object) WriteJSON(v interface{}) error

func (*LinoS3Object) WriteString

func (s *LinoS3Object) WriteString(_string string, contentType ...string) error

type LinoS3Path

type LinoS3Path struct {
	// contains filtered or unexported fields
}

func LoadS3Path added in v0.0.4

func LoadS3Path(dsn string) (*LinoS3Path, error)

func MustLoadS3Path added in v0.0.4

func MustLoadS3Path(dsn string, logger ...utils.Logger) *LinoS3Path

func (*LinoS3Path) Object

func (s *LinoS3Path) Object(key string) *LinoS3Object

func (*LinoS3Path) SubPath

func (s *LinoS3Path) SubPath(path string) *LinoS3Path

func (*LinoS3Path) UseInterceptors

func (s *LinoS3Path) UseInterceptors(interceptors ...*Interceptor) *LinoS3Path

type LinoS3Piece added in v0.0.2

type LinoS3Piece struct {
	// contains filtered or unexported fields
}

func (*LinoS3Piece) Get added in v0.0.2

func (s *LinoS3Piece) Get() (*s3.GetObjectOutput, error)

func (*LinoS3Piece) Key added in v0.0.2

func (s *LinoS3Piece) Key() string

func (*LinoS3Piece) ReadBuffer added in v0.0.2

func (s *LinoS3Piece) ReadBuffer() ([]byte, error)

func (*LinoS3Piece) ReadCBOR added in v0.0.2

func (s *LinoS3Piece) ReadCBOR(v interface{}) error

func (*LinoS3Piece) ReadJSON added in v0.0.2

func (s *LinoS3Piece) ReadJSON(v interface{}) error

func (*LinoS3Piece) ReadString added in v0.0.2

func (s *LinoS3Piece) ReadString() (string, error)

func (*LinoS3Piece) ReadTo added in v0.0.2

func (s *LinoS3Piece) ReadTo(writer io.WriteCloser) error

Directories

Path Synopsis
structures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL