storage

package module
v0.0.0-...-92d10ad Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 8 Imported by: 0

README

admgo/storage

admgo/storage is a lightweight, high-performance, and modular storage library designed to handle various storage needs and functionalities efficiently. This library provides a unified interface for different storage implementations, making it a go-to choice for integrating storage-related logic in your projects.

Features

  • Modular Design: Supports multiple types of storage implementations (e.g., file-based storage, cloud storage, database storage) and is easy to extend.
  • High Performance: Optimized for speed and designed for high-concurrency scenarios.
  • Easy Integration: Simple and clear APIs to reduce integration complexity.
  • Unified Interface: Provides a uniform interface for all storage types, simplifying the process of switching or upgrading storage backends.

Quick Start

Follow these steps to quickly integrate and use the admgo/storage library.

Installation

Use Go modules to add the library to your project:

go get github.com/admgo/storage
Usage Example

Here is a simple example of using admgo/storage to initialize a storage instance, save data, and retrieve it:


package main

import (
    "github.com/admgo/storage"
)

func main() {
	p := storage.NewProvider(storage.Config{
		Provider: "aliyun",
		AliyunOssConfig: storage.AliyunOssConfig{
			AccessKeyID:        "****************************",
			AccessKeySecret:    "****************************",
			Region:             "cn-beijing",
			Bucket:             "storage",
			Prefix:             "storage",
			CredentialProvider: "static",
		},
	})
	err := p.PutObject(storage.File{
		Path:    "test/test.txt",
		Content: []byte("test"),
	})
	if err != nil {
		panic(err)
	}
}


Supported Storage Types

Currently, the admgo/storage library supports the following types of storage (with room for custom extensions):

  • Local file storage
  • Cloud storage services (e.g., AWS S3)
  • Custom storage implementations
Extending with Custom Storage

You can implement a custom storage backend by satisfying the Storage interface:

type Storage interface {
    ListObjects(prefix string) ([]Object, error)
    GetObject(path string) (Object, error)
    PutObject(f File) error
    DeleteObject(path string) error
}

Once implemented, create an instance using the storage.New() factory method.

Testing

Run all unit tests to ensure the functionality is working as expected:

go test ./...

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

If you encounter any issues or have suggestions for improvements, feel free to submit an issue or reach out to the maintainers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliyunOssConfig

type AliyunOssConfig struct {
	AccessKeyID        string `json:"accessKeyId"`
	AccessKeySecret    string `json:"access"`
	Region             string `json:"region"`
	Bucket             string `json:"bucket"`
	Prefix             string `json:"prefix"`
	CredentialProvider string `json:"credentialProvider"`
}

func (*AliyunOssConfig) Load

func (c *AliyunOssConfig) Load(filepath string) error

func (*AliyunOssConfig) MustLoad

func (c *AliyunOssConfig) MustLoad(filepath string)

type AliyunOssProvider

type AliyunOssProvider struct {
	Client *oss.Client
	// contains filtered or unexported fields
}

AliyunOssProvider is a storage provider for Aliyun Cloud OSS

func NewAliyunOssProvider

func NewAliyunOssProvider(c *AliyunOssConfig) *AliyunOssProvider

NewAliyunOssProvider creates a new instance of AliyunOssProvider

func (AliyunOssProvider) DeleteObject

func (c AliyunOssProvider) DeleteObject(path string) error

DeleteObject removes an object from Alibaba Cloud OSS bucket, at prefix

func (AliyunOssProvider) GetObject

func (c AliyunOssProvider) GetObject(path string) (Object, error)

GetObject retrieves an object from Alibaba Cloud OSS bucket, at prefix

func (AliyunOssProvider) ListObjects

func (c AliyunOssProvider) ListObjects(prefix string) ([]Object, error)

ListObjects lists all objects in Alibaba Cloud OSS bucket, at prefix

func (AliyunOssProvider) PutObject

func (c AliyunOssProvider) PutObject(f File) error

PutObject uploads an object to Alibaba Cloud OSS bucket, at prefix

type Config

type Config struct {
	Provider        string
	AliyunOssConfig AliyunOssConfig
}

type File

type File struct {
	Path    string
	Content []byte
}

type Metadata

type Metadata struct {
	Name    string
	Version string
}

type Object

type Object struct {
	MetaData Metadata
	Content  []byte
	// contains filtered or unexported fields
}

type Provider

type Provider interface {
	ListObjects(prefix string) ([]Object, error)
	GetObject(path string) (Object, error)
	PutObject(f File) error
	DeleteObject(path string) error
}

Provider is a generic interface for storage providers

func NewProvider

func NewProvider(c Config) Provider

Jump to

Keyboard shortcuts

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