Documentation ¶
Overview ¶
文件相关操作.
Index ¶
- Variables
- func InstallDirectory()
- func Mkdir(path string) ftype.Error
- func Path(elements ...string) string
- func ReadFile(filename string) ([]byte, ftype.Error)
- func ReadFileJson(filename string, data interface{}) ftype.Error
- func WriteFile(filename string, data []byte) ftype.Error
- func WriteFileJson(filename string, data interface{}) ftype.Error
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 Path ¶
将各个元素拼接起来合成路径.
Example ¶
println(Path(HomeDirectory, "go-farmer", "test.txt")) return
Output:
func ReadFile ¶
读文件.
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
读文件, 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 ¶
写文件, 权限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
写文件, 权限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.
Click to show internal directories.
Click to hide internal directories.