Documentation
¶
Index ¶
- Constants
- func AbsPath(path string, create bool) (string, error)
- func Characters(data []byte) int
- func CharactersForFile(filename string) (int, error)
- func CleanBlankLines(data []byte) []byte
- func CleanBlankLinesForFile(filename string) ([]byte, error)
- func CleanSpecificContentLines(data []byte, findStr string) []byte
- func CleanSpecificContentLinesForFile(filename string, findStr string) ([]byte, error)
- func ContentDispositionFilename() func(val string) string
- func Copy(src string, dst string, ops ...Option) error
- func CreateFile(filename string, data []byte, ops ...Option) (string, error)
- func CreateFilename(filename, extension string, ops ...Option) string
- func CreateZIPFileWithFilename(source string) (string, error)
- func DirNotExists(path string) bool
- func DownloadFile(resp http.ResponseWriter, path string) error
- func DownloadFileByIOReader(resp http.ResponseWriter, reader io.Reader, filename string, filesize int64) error
- func EmbedsExists(embeds embed.FS, path string) bool
- func EmbedsFileExists(embeds embed.FS, path string) bool
- func EmbedsNotExists(embeds embed.FS, path string) bool
- func Exists(path string) bool
- func FilenameTrimPrefix(filename, prefix string) string
- func GetContentWithRegularExpression(str, pattern string, ops ...Option) ([]string, error)
- func GetFileContentBytesWithEmbedFS(fs embed.FS, filename string) ([]byte, error)
- func GetFileContentStringSliceWithBuffer(buffer *bytes.Buffer, ops ...Option) ([]string, error)
- func GetFileContentStringSliceWithEmbedFS(fs embed.FS, filename string, ops ...Option) ([]string, error)
- func GetFileContentStringSliceWithFilename(filename string, ops ...Option) ([]string, error)
- func GetFileExtension(filename string, ops ...Option) string
- func GetFileOrDirectoryName(path string) (string, bool, error)
- func GetFilePathWithFileSystemPath(baseDir string, ops ...Option) (string, error)
- func GetGOPATH() string
- func GetGOPATHProjectSource() string
- func GetResponseHeader(resp http.ResponseWriter, field string) string
- func GetResponseHeaderFunc(resp http.ResponseWriter, field string, process func(val string) string) string
- func InSlice(source []interface{}, find interface{}) bool
- func IsDir(path string) (bool, error)
- func IsFile(filename string) (bool, error)
- func IsNotExists(path string) booldeprecated
- func IsNotExistsWithEmbedFS(embeds embed.FS, path string) booldeprecated
- func LastDirName(filename string) string
- func Lines(data []byte) int
- func LinesForFile(filename string) (int, error)
- func MarkContentPrefixClear(data []byte, mark string, ops ...Option) []byte
- func MarkContentSuffixClear(data []byte, mark string, ops ...Option) []byte
- func MkdirAll(path string) error
- func MustGetFilePathWithFileSystemPath(baseDir string, ops ...Option) string
- func NotExistsMkdir(path string) error
- func NotExistsMkdirAll(path string) error
- func ReadDir(path string, result []string) ([]string, error)
- func RuntimeMasterDir() string
- func Touch(filename string) error
- func Truncate(filename string, size int64) error
- func UploadFileForMultipartFields(values map[string]interface{}) (contentType string, buffer bytes.Buffer, err error)
- func UploadIsAllowMIMEWithFormFile(request *http.Request, key string, allows []string) (bool, error)
- func WriteDir(dst string, files []string, ops ...Option) error
- type FileExtension
- type FileSystemPath
- type Option
- func WithIgnoreBlankLine(ignored bool) Option
- func WithOriginalFileNameTrimPrefix(str string) Option
- func WithSpecificBaseDir(baseDir string) Option
- func WithSpecificContainsMarkString(contains bool) Option
- func WithSpecificFileExtension(extension FileExtension) Option
- func WithSpecificFileExtensionContainsDot(containsdot bool) Option
- func WithSpecificFileSystemPath(path FileSystemPath) Option
- func WithSpecificTrimOriginalFileExtension(trim bool) Option
- type VersionGithub
Constants ¶
const (
FileSystemOfGOPATH = "GOPATH"
)
const (
// GlobalSeparatorWithFileName File name separator.
GlobalSeparatorWithFileName = "."
)
const (
ZIPExtension = "zip"
)
Variables ¶
This section is empty.
Functions ¶
func AbsPath ¶
AbsPath Checks whether a directory is an absolute path and can be created by creating a path that does not exist
func CharactersForFile ¶
CharactersForFile Count the number of data characters
func CleanBlankLines ¶
CleanBlankLines clean blank lines with file.
func CleanBlankLinesForFile ¶
CleanBlankLinesForFile clean blank lines with file.
func CleanSpecificContentLines ¶
CleanSpecificContentLines clean specific content lines.
func CleanSpecificContentLinesForFile ¶
CleanSpecificContentLinesForFile clean specific content lines for file.
func ContentDispositionFilename ¶
ContentDispositionFilename Gets filename for response header Content-Disposition. Header such as Content-Disposition: attachment; filename="helloshaohua.txt"
func CreateFile ¶
CreateFile Create new file, your can specific multiple options.
func CreateFilename ¶
CreateFilename Create the filename.
func CreateZIPFileWithFilename ¶
CreateZIPFileWithFilename CreateZIPFile Create ZIP file, return the storage path and error. source parameter specifies a file or directory.
func DirNotExists ¶
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 DownloadFileByIOReader ¶
func DownloadFileByIOReader(resp http.ResponseWriter, reader io.Reader, filename string, filesize int64) error
DownloadFileByIOReader streams file content from an io.Reader to the HTTP response as a downloadable file. filesize: File size in bytes. Pass -1 to let the function attempt to determine the size automatically (only works when reader implements io.ReadSeeker).
func EmbedsExists ¶
EmbedsExists checks whether the specified file or directory exists in the embedded file system. This is a more general function that can handle both files and directories.
Parameters:
- embeds: The embedded file system instance to search in
- path: The relative path of the file or directory to check
Returns:
- true if the file or directory exists
- false if it does not exist
Example:
//go:embed static/*
var staticFS embed.FS
if EmbedsExists(staticFS, "static/css/style.css") {
// File exists
}
if EmbedsExists(staticFS, "static/images/") {
// Directory exists (note trailing slash for directories)
}
func EmbedsFileExists ¶
EmbedsFileExists checks whether the specified file exists in the embedded file system. It attempts to read the file from the embed.FS to determine its existence.
Parameters:
- embeds: The embedded file system instance to search in
- path: The relative path of the file to check (relative to the embed.FS root)
Returns:
- true if the file exists and can be read (or opened)
- false if the file does not exist or cannot be accessed
Note: This function only checks for the existence of files, not directories. Use EmbedsExists() if you need to check for both files and directories.
func EmbedsNotExists ¶
EmbedsNotExists checks whether the specified file or directory does NOT exist in the embedded file system. This is the inverse of EmbedsExists() for semantic clarity in certain contexts.
Parameters:
- embeds: The embedded file system instance to search in
- path: The relative path to check
Returns:
- true if the file or directory does NOT exist
- false if it exists
Usage note: Consider using !EmbedsExists() for better readability in most cases. This function is provided for consistency with Go's os.IsNotExist pattern.
func Exists ¶
Exists checks whether the target file or directory exists. Return TRUE if the file exists, FALSE otherwise.
func FilenameTrimPrefix ¶
FilenameTrimPrefix Trim the filename prefix.
func GetContentWithRegularExpression ¶
GetContentWithRegularExpression Get the string content into slice's string, using a regular expression.
func GetFileContentBytesWithEmbedFS ¶
GetFileContentBytesWithEmbedFS Get file content bytes slice with embed filesystem.
func GetFileContentStringSliceWithBuffer ¶
GetFileContentStringSliceWithBuffer Get file content string slice with bytes buffer
func GetFileContentStringSliceWithEmbedFS ¶
func GetFileContentStringSliceWithEmbedFS(fs embed.FS, filename string, ops ...Option) ([]string, error)
GetFileContentStringSliceWithEmbedFS Get file content string slice with embed filesystem.
func GetFileContentStringSliceWithFilename ¶
GetFileContentStringSliceWithFilename Get the file contents as a string for slice.
func GetFileExtension ¶
GetFileExtension Gets the file extension.
func GetFileOrDirectoryName ¶
GetFileOrDirectoryName Gets the file or directory name.
func GetFilePathWithFileSystemPath ¶
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 IsNotExists
deprecated
func IsNotExistsWithEmbedFS
deprecated
func LastDirName ¶
LastDirName Gets filename the last directory name.
func LinesForFile ¶
LinesForFile Count the number of data rows from file.
func MarkContentPrefixClear ¶
MarkContentPrefixClear Mark content prefix clear.
func MarkContentSuffixClear ¶
MarkContentSuffixClear Mark content suffix clear.
func NotExistsMkdir ¶
NotExistsMkdir detects whether the target folder exists. and if it does not, create the folder.
func NotExistsMkdirAll ¶
NotExistsMkdirAll Check whether the directory exists and create it if it does not
func RuntimeMasterDir ¶
func RuntimeMasterDir() string
RuntimeMasterDir returns the root path corresponding to the current directory.
func Truncate ¶
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.
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 ¶
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 ¶
func (p FileSystemPath) String() string
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithIgnoreBlankLine ¶
WithIgnoreBlankLine Specify whether blank lines are ignored.
func WithOriginalFileNameTrimPrefix ¶
WithOriginalFileNameTrimPrefix WithSpecificContainsMarkString Override the original value by trimPrefixStr string.
func WithSpecificBaseDir ¶
WithSpecificBaseDir Override the original value by specifying base directory.
func WithSpecificContainsMarkString ¶
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 ¶
WithSpecificFileExtensionContainsDot Override the original value by specifying dot.
func WithSpecificFileSystemPath ¶
func WithSpecificFileSystemPath(path FileSystemPath) Option
WithSpecificFileSystemPath Override the original value by specifying filepath.
func WithSpecificTrimOriginalFileExtension ¶
WithSpecificTrimOriginalFileExtension Override the original value by specifying trim.
type VersionGithub ¶
type VersionGithub struct {
Major string `json:"major"`
Minor string `json:"minor"`
Patch string `json:"patch"`
}
VersionGithub Github version number format.
func GetVersion ¶
func GetVersion(version string) (*VersionGithub, error)
GetVersion Get Github version information in version number format.
func (*VersionGithub) GetFullVersion ¶
func (v *VersionGithub) GetFullVersion() string
GetFullVersion Get a full version string. Such as 1.16.6, will return 1.16.6
func (*VersionGithub) GetMinorVersion ¶
func (v *VersionGithub) GetMinorVersion() string
GetMinorVersion Get a minor version string. Such as 1.16.6, will return 1.16
func (*VersionGithub) Join ¶
func (v *VersionGithub) Join(element ...string) string
Join version section, default use dot.