storage

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 4 Imported by: 4

README

gFly Storage - File system

Copyright © 2023, gFly
https://www.gfly.dev
All rights reserved.

gFly Storage

Usage

Install

# Storage
go get -u github.com/gflydev/storage@v1.1.0

# Local Storage
go get -u github.com/gflydev/storage/local@v1.1.0

Quick usage main.go

import (
    "github.com/gflydev/core"
    "github.com/gflydev/storage"
    // Auto initial local storage
    _ "github.com/gflydev/storage/local"	
)

func main() {
    // Create file storage with default
    fs := storage.Instance()

	// Create folder `foo/bar` and add file `hello.txt`
    if ok := fs.MakeDir("foo/bar"); ok {
        fs.Put("foo/bar/hello.txt", "Hello world")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DirFileHolder Default file holder for directory
	DirFileHolder = "dir.info"
)

Functions

func Register

func Register(name Type, storage IStorage)

Register add storage instance via unique name

Each storage type which implement IStorage interface should be registered by calling method

Types

type IStorage

type IStorage interface {

	// Put Create a file with content string
	Put(path, contents string) bool
	// PutData Create a file with content byte
	PutData(path string, contents []byte) bool
	// PutFile Create a file from another file source
	PutFile(path string, fileSource *os.File) bool
	// Delete Remove a file
	Delete(path string) bool
	// Copy Clone file to another location
	Copy(from, to string) bool
	// Move Switch file location to new place
	Move(from, to string) bool

	// Exists Check existed file
	Exists(path string) bool
	// Get Receive a file content
	Get(path string) ([]byte, error)
	// Size Get file size
	Size(path string) int64
	// LastModified Obtains last modified of file
	LastModified(path string) time.Time
	// Url Absolute URL (Public URL)
	Url(path string) string

	// MakeDir Create new directory
	MakeDir(dir string) bool
	// DeleteDir Remove empty directory
	DeleteDir(dir string) bool

	// Append Add string content to bottom file
	Append(path, data string) bool

	// GetStream returns a stream (io.ReadCloser) for the object at the given path
	// This allows for efficient streaming without loading the entire file into memory
	GetStream(path string) (io.ReadCloser, error)
}

IStorage Storage interface

func Instance

func Instance(name ...Type) IStorage

Instance receive a storage instance. Get default storage for NONE `name` argument

type Type

type Type string

func (Type) String added in v1.1.0

func (t Type) String() string

Directories

Path Synopsis
cs3 module
local module
s3 module
ws3 module

Jump to

Keyboard shortcuts

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