ffile

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

文件相关操作.

Index

Examples

Constants

This section is empty.

Variables

View Source
var HomeDirectory string

用户主目录.

View Source
var PathListSeparator string = string(os.PathListSeparator)

多路径分隔符. 比如, linux下是':'.

View Source
var PathSeparator string = string(os.PathSeparator)

路径分隔符.

Functions

func InstallDirectory

func InstallDirectory()

在主目录下添加目录farmer/ , 包含子目录bin/ etc/ include/ lib/ share/ src/

Example
InstallDirectory()
return
Output:

func Mkdir

func Mkdir(path string) ftype.Error

创建目录, 权限0775.

Example
Mkdir("/tmp/tttt")
return
Output:

func Path

func Path(elements ...string) string

将各个元素拼接起来合成路径.

Example
println(Path(HomeDirectory, "go-farmer", "test.txt"))
return
Output:

func ReadFile

func ReadFile(filename string) ([]byte, ftype.Error)

读文件.

Example
content, e := ReadFile("/tmp/go-farmer-test.txt")
fassert.CheckError(e, "读文件/tmp/go-farmer-test.txt")
println(string(content))
return
Output:

func ReadFileJson added in v5.1.0

func ReadFileJson(
	filename string,
	data interface{}) ftype.Error

读文件, json格式. @data - 同json.Unmarshal()的参数.

Example
type T struct {
	A string
	B int64
}
var a T
e := ReadFileJson("/tmp/go-farmer-test-json.txt", &a)
fassert.CheckError(e, "读文件/tmp/go-farmer-test-json.txt")
println(a.A)
println(a.B)
return
Output:

func WriteFile

func WriteFile(filename string, data []byte) ftype.Error

写文件, 权限0664.

Example
e := WriteFile("/tmp/go-farmer-test.txt", []byte("hello world."))
fassert.CheckError(e, "写文件/tmp/go-farmer-test.txt")
return
Output:

func WriteFileJson added in v5.1.0

func WriteFileJson(
	filename string,
	data interface{}) ftype.Error

写文件, 权限0664, json格式.

Example
type T struct {
	A string
	B int64
}
var a T
a.A = "hello world"
a.B = 10086
e := WriteFileJson("/tmp/go-farmer-test-json.txt", a)
fassert.CheckError(e, "写文件/tmp/go-farmer-test-json.txt")
return
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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