filesystem

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 5 Imported by: 0

README

filesystem

Go Report Card tests GoDoc MIT license

——The idea came from Laravel

未完结版

Installation

go get github.com/go-packagist/filesystem

Usage

package main

import (
	"fmt"
	"github.com/go-packagist/filesystem"
)

func main() {
	fs := filesystem.NewManager(&filesystem.Config{
		Default: "local",
		Disk: map[string]interface{}{
			"local": &filesystem.LocalDriveConfig{
				Root: "temp",
			},
		},
	})

	fmt.Println(fs.Disk("local").Exists("test.txt"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(path, contents string) error

func Copy

func Copy(src, dst string) error

func CopyFile

func CopyFile(src, dst string) error

func Delete

func Delete(path string) error

func Exists

func Exists(path string) bool

Exists checks if a file or directory exists

func FileInfo

func FileInfo(path string) (os.FileInfo, error)

FileInfo file info, alias Stat

func Get

func Get(path string) (string, error)

Get get file content, alias ReadFile

func Info

func Info(path string) (os.FileInfo, error)

Info file info, alias Stat

func IsDir

func IsDir(path string) bool

IsDir checks if a path is a directory

func IsFile

func IsFile(path string) bool

IsFile checks if a path is a file

func LastModified

func LastModified(path string) (time.Time, error)

func Mkdir

func Mkdir(path string) error

func Move

func Move(src, dst string) error

func Prepend

func Prepend(path, contents string) error

func Put

func Put(path, content string) error

func Read

func Read(path string) (string, error)

Read read file content, alias ReadFile

func ReadDir

func ReadDir(path string) ([]os.FileInfo, error)

ReadDir read directory

func ReadFile

func ReadFile(path string) (string, error)

ReadFile read file content

func Remove

func Remove(path string) error

func Rename

func Rename(src, dst string) error

func Size

func Size(path string) (int64, error)

Size file size

func Stat

func Stat(path string) (os.FileInfo, error)

Stat file info

func WriteFile

func WriteFile(path, content string) error

Types

type Config

type Config struct {
	Default string
	Disk    map[string]interface{}
}

type Drive

type Drive interface {
	Exists(path string) bool
	Get(path string) (string, error)
	Put(path, contents string) error
	Prepend(path, contents string) error
	Append(path, contents string) error
	Delete(path string) error
	Copy(from, to string) error
	Move(from, to string) error
	Rename(from, to string) error
	Size(path string) (int64, error)
	LastModified(path string) (time.Time, error)
	Files(directory string) ([]string, error)
	AllFiles(directory string) ([]string, error)
}

func NewLocalDrive

func NewLocalDrive(config *LocalDriveConfig) Drive

NewLocalDrive creates a new local filesystem drive.

type LocalDrive

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

LocalDrive is a local filesystem drive.

func (*LocalDrive) AllFiles

func (l *LocalDrive) AllFiles(directory string) (files []string, err error)

func (*LocalDrive) Append

func (l *LocalDrive) Append(path, contents string) error

func (*LocalDrive) Copy

func (l *LocalDrive) Copy(from, to string) error

func (*LocalDrive) Delete

func (l *LocalDrive) Delete(path string) error

func (*LocalDrive) Exists

func (l *LocalDrive) Exists(path string) bool

Exists checks if the given path exists.

func (*LocalDrive) Files

func (l *LocalDrive) Files(directory string) (files []string, err error)

func (*LocalDrive) Get

func (l *LocalDrive) Get(path string) (string, error)

Get returns the contents of the given path.

func (*LocalDrive) LastModified

func (l *LocalDrive) LastModified(path string) (time.Time, error)

func (*LocalDrive) Move

func (l *LocalDrive) Move(from, to string) error

func (*LocalDrive) Prepend

func (l *LocalDrive) Prepend(path, contents string) error

func (*LocalDrive) Put

func (l *LocalDrive) Put(path, contents string) error

Put writes the given data to the given path.

func (*LocalDrive) Rename

func (l *LocalDrive) Rename(from, to string) error

func (*LocalDrive) Size

func (l *LocalDrive) Size(path string) (int64, error)

type LocalDriveConfig

type LocalDriveConfig struct {
	Root string
}

LocalDriveConfig is the configuration for a local filesystem drive.

type Manager

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

func NewManager

func NewManager(config *Config) *Manager

NewManager creates a new filesystem manager

fs := filesystem.NewManager(&filesystem.Config{
	Default: "local",
	Disk: map[string]interface{}{
		"local": &filesystem.LocalDriveConfig{
			Root: "temp",
		},
	},
})

fmt.Println(fs.Disk("local").Exists("test.txt"))

func (*Manager) CreateLocalDrive

func (m *Manager) CreateLocalDrive(config *LocalDriveConfig) Drive

CreateLocalDrive creates a local filesystem drive

func (*Manager) Disk

func (m *Manager) Disk(name string) Drive

Disk returns a filesystem drive fs.Disk("local")

func (*Manager) Drive

func (m *Manager) Drive(name string) Drive

Drive returns a filesystem drive; alias Disk fs.Drive("local")

type PathPrefixer

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

func NewPathPrefixer

func NewPathPrefixer(prefix string) *PathPrefixer

NewPathPrefixer creates a new PathPrefixer.

func (*PathPrefixer) PrefixPath

func (p *PathPrefixer) PrefixPath(path string) string

PrefixPath Returns a prefixed directory

Jump to

Keyboard shortcuts

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