fsfire

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 17 Imported by: 5

README

fs

Go File system-related operations.

Installation

$ go get -u github.com/coolstina/fsfire

How to use?

It's very simple to use, just out of the box, and you can view the documentation through GoDoc.

Documentation

Index

Constants

View Source
const (
	FileSystemOfGOPATH = "GOPATH"
)
View Source
const (
	// GlobalSeparatorWithFileName File name separator.
	GlobalSeparatorWithFileName = "."
)
View Source
const (
	ZIPExtension = "zip"
)

Variables

This section is empty.

Functions

func AbsPath added in v1.1.8

func AbsPath(path string, create bool) (string, error)

AbsPath Checks whether a directory is an absolute path and can be created by creating a path that does not exist

func Characters

func Characters(data []byte) int

Characters Count the number of data characters

func CharactersForFile

func CharactersForFile(filename string) (int, error)

CharactersForFile Count the number of data characters

func CleanBlankLines

func CleanBlankLines(data []byte) []byte

CleanBlankLines clean blank lines with file.

func CleanBlankLinesForFile

func CleanBlankLinesForFile(filename string) ([]byte, error)

CleanBlankLinesForFile clean blank lines with file.

func CleanSpecificContentLines

func CleanSpecificContentLines(data []byte, findStr string) []byte

CleanSpecificContentLines clean specific content lines.

func CleanSpecificContentLinesForFile

func CleanSpecificContentLinesForFile(filename string, findStr string) ([]byte, error)

CleanSpecificContentLinesForFile clean specific content lines for file.

func ContentDispositionFilename

func ContentDispositionFilename() func(val string) string

ContentDispositionFilename Gets filename for response header Content-Disposition. Header such as Content-Disposition: attachment; filename="helloshaohua.txt"

func Copy

func Copy(src string, dst string, ops ...Option) error

Copy file to destination directory.

func CreateFile

func CreateFile(filename string, data []byte, ops ...Option) (string, error)

CreateFile Create new file, your can specific multiple options.

func CreateFilename

func CreateFilename(filename, extension string, ops ...Option) string

CreateFilename Create the filename.

func CreateZIPFileWithFilename

func CreateZIPFileWithFilename(source string) (string, error)

CreateZIPFileWithFilename CreateZIPFile Create ZIP file, return the storage path and error. source parameter specifies a file or directory.

func DirNotExists added in v1.0.5

func DirNotExists(path string) bool

DirNotExists Check whether the specified file path directory does not exists.

func DownloadFile

func DownloadFile(resp http.ResponseWriter, path string) error

DownloadFile will write download file into the HTTP response body.

func FilenameTrimPrefix added in v1.0.5

func FilenameTrimPrefix(filename, prefix string) string

FilenameTrimPrefix Trim the filename prefix.

func GetContentWithRegularExpression added in v1.0.9

func GetContentWithRegularExpression(str, pattern string, ops ...Option) ([]string, error)

GetContentWithRegularExpression Get the string content into slice's string, using a regular expression.

func GetFileContentBytesWithEmbedFS added in v1.1.4

func GetFileContentBytesWithEmbedFS(fs embed.FS, filename string) ([]byte, error)

GetFileContentBytesWithEmbedFS Get file content bytes slice with embed filesystem.

func GetFileContentStringSliceWithBuffer added in v1.1.6

func GetFileContentStringSliceWithBuffer(buffer *bytes.Buffer, ops ...Option) ([]string, error)

GetFileContentStringSliceWithBuffer Get file content string slice with bytes buffer

func GetFileContentStringSliceWithEmbedFS added in v1.1.4

func GetFileContentStringSliceWithEmbedFS(fs embed.FS, filename string, ops ...Option) ([]string, error)

GetFileContentStringSliceWithEmbedFS Get file content string slice with embed filesystem.

func GetFileContentStringSliceWithFilename added in v1.1.4

func GetFileContentStringSliceWithFilename(filename string, ops ...Option) ([]string, error)

GetFileContentStringSliceWithFilename Get the file contents as a string for slice.

func GetFileExtension

func GetFileExtension(filename string, ops ...Option) string

GetFileExtension Gets the file extension.

func GetFileOrDirectoryName added in v1.1.1

func GetFileOrDirectoryName(path string) (string, bool, error)

GetFileOrDirectoryName Gets the file or directory name.

func GetFilePathWithFileSystemPath added in v1.1.0

func GetFilePathWithFileSystemPath(baseDir string, ops ...Option) (string, error)

GetFilePathWithFileSystemPath Get a file path with filesystem path.

func GetGOPATH

func GetGOPATH() string

GetGOPATH Gets the current operating system GOPATH from environment.

func GetGOPATHProjectSource

func GetGOPATHProjectSource() string

GetGOPATHProjectSource Gets the current operating system GOPATH/src from environment and filesystem.

func GetResponseHeader

func GetResponseHeader(resp http.ResponseWriter, field string) string

GetResponseHeader Gets response header field value.

func GetResponseHeaderFunc

func GetResponseHeaderFunc(resp http.ResponseWriter, field string, process func(val string) string) string

GetResponseHeaderFunc GetResponseHeader Gets response header field value, processing of response field values by attaching custom functions.

func InSlice

func InSlice(source []interface{}, find interface{}) bool

func IsDir added in v1.0.5

func IsDir(path string) (bool, error)

IsDir Checks whether the specified file name is a directory.

func IsFile added in v1.0.5

func IsFile(filename string) (bool, error)

IsFile Checks whether the specified file name is a file.

func IsNotExists

func IsNotExists(path string) bool

IsNotExists check whether the target file or directory exists. Return FALSE if the file exists, TRUE otherwise.

func IsNotExistsWithEmbedFS added in v1.1.1

func IsNotExistsWithEmbedFS(embeds embed.FS, path string) bool

IsNotExistsWithEmbedFS check whether the target file or directory exists with embed.FS. Return FALSE if the file exists, TRUE otherwise.

func LastDirName

func LastDirName(filename string) string

LastDirName Gets filename the last directory name.

func Lines

func Lines(data []byte) int

Lines Count the number of data rows

func LinesForFile

func LinesForFile(filename string) (int, error)

LinesForFile Count the number of data rows from file.

func MarkContentPrefixClear

func MarkContentPrefixClear(data []byte, mark string, ops ...Option) []byte

MarkContentPrefixClear Mark content prefix clear.

func MarkContentSuffixClear

func MarkContentSuffixClear(data []byte, mark string, ops ...Option) []byte

MarkContentSuffixClear Mark content suffix clear.

func MkdirAll

func MkdirAll(path string) error

MkdirAll creates a directory named path.

func MustGetFilePathWithFileSystemPath added in v1.1.0

func MustGetFilePathWithFileSystemPath(baseDir string, ops ...Option) string

func NotExistsMkdir

func NotExistsMkdir(path string) error

NotExistsMkdir detects whether the target folder exists. and if it does not, create the folder.

func NotExistsMkdirAll added in v1.1.8

func NotExistsMkdirAll(path string) error

NotExistsMkdirAll Check whether the directory exists and create it if it does not

func ReadDir

func ReadDir(path string, result []string) ([]string, error)

ReadDir Get the directory file name by recursive reading.

func RuntimeMasterDir

func RuntimeMasterDir() string

RuntimeMasterDir returns the root path corresponding to the current directory.

func Touch

func Touch(filename string) error

Touch Create file, if parent directory not exists, then create.

func Truncate added in v1.1.3

func Truncate(filename string, size int64) error

Truncate changes the size of the file. It does not change the I/O offset. If there is an error, it will be of type *PathError.

func UploadFileForMultipartFields

func UploadFileForMultipartFields(values map[string]interface{}) (contentType string, buffer bytes.Buffer, err error)

UploadFileForMultipartFields Mock form upload file.

func UploadIsAllowMIMEWithFormFile

func UploadIsAllowMIMEWithFormFile(request *http.Request, key string, allows []string) (bool, error)

func WriteDir added in v1.0.5

func WriteDir(dst string, files []string, ops ...Option) error

WriteDir Write file to dst directory.

Types

type FileExtension

type FileExtension string
const (
	FileExtensionWithImageOfJPEG FileExtension = "jpeg"
	FileExtensionWithImageOfPNG  FileExtension = "png"
	FileExtensionWithImageOfGIF  FileExtension = "gif"
	FileExtensionWithImageOfBMP  FileExtension = "bmp"
)
const (
	FileExtensionWithOfficeOfExcel FileExtension = "xlsx"
	FileExtensionWithOfficeOfWord  FileExtension = "docx"
	FileExtensionWithOfficeOfCSV   FileExtension = "csv"
)
const (
	FileExtensionWithDocumentOfMarkdown FileExtension = "md"
	FileExtensionWithDocumentOfFileText FileExtension = "txt"
)

func (FileExtension) String

func (file FileExtension) String() string

type FileSystemPath added in v1.1.0

type FileSystemPath string
const (
	AssetsSavePathForDatabase FileSystemPath = "static/assets/database"
	AssetsSavePathForExcel    FileSystemPath = "static/assets/excel"
	AssetsSavePathForCSV      FileSystemPath = "static/assets/csv"
)

Assets files save path definition.

const GlobalDefaultDir FileSystemPath = "static"

func (FileSystemPath) String added in v1.1.0

func (p FileSystemPath) String() string

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithIgnoreBlankLine added in v1.0.5

func WithIgnoreBlankLine(ignored bool) Option

WithIgnoreBlankLine Specify whether blank lines are ignored.

func WithOriginalFileNameTrimPrefix added in v1.0.5

func WithOriginalFileNameTrimPrefix(str string) Option

WithOriginalFileNameTrimPrefix WithSpecificContainsMarkString Override the original value by trimPrefixStr string.

func WithSpecificBaseDir

func WithSpecificBaseDir(baseDir string) Option

WithSpecificBaseDir Override the original value by specifying base directory.

func WithSpecificContainsMarkString

func WithSpecificContainsMarkString(contains bool) Option

WithSpecificContainsMarkString Override the original value by containsMarkString mark string.

func WithSpecificFileExtension

func WithSpecificFileExtension(extension FileExtension) Option

WithSpecificFileExtension Override the original value by specifying file extension.

func WithSpecificFileExtensionContainsDot

func WithSpecificFileExtensionContainsDot(containsdot bool) Option

WithSpecificFileExtensionContainsDot Override the original value by specifying dot.

func WithSpecificFileSystemPath added in v1.1.7

func WithSpecificFileSystemPath(path FileSystemPath) Option

WithSpecificFileSystemPath Override the original value by specifying filepath.

func WithSpecificTrimOriginalFileExtension

func WithSpecificTrimOriginalFileExtension(trim bool) Option

WithSpecificTrimOriginalFileExtension Override the original value by specifying trim.

type VersionGithub added in v1.1.2

type VersionGithub struct {
	Major string `json:"major"`
	Minor string `json:"minor"`
	Patch string `json:"patch"`
}

VersionGithub Github version number format.

func GetVersion added in v1.1.2

func GetVersion(version string) (*VersionGithub, error)

GetVersion Get Github version information in version number format.

func (*VersionGithub) GetFullVersion added in v1.1.2

func (v *VersionGithub) GetFullVersion() string

GetFullVersion Get a full version string. Such as 1.16.6, will return 1.16.6

func (*VersionGithub) GetMinorVersion added in v1.1.2

func (v *VersionGithub) GetMinorVersion() string

GetMinorVersion Get a minor version string. Such as 1.16.6, will return 1.16

func (*VersionGithub) Join added in v1.1.2

func (v *VersionGithub) Join(element ...string) string

Join version section, default use dot.

Jump to

Keyboard shortcuts

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