func Join(paths ...string) string
func ExampleJoin() {
// init
var (
dirPath = gfile.TempDir("gfile_example_basic_dir")
filePath = "file1"
)
// Joins string array paths with file separator of current system.
joinString := gfile.Join(dirPath, filePath)
fmt.Println(joinString)
// Output:
// /tmp/gfile_example_basic_dir/file1
}
func Abs(path string) string
func ExampleAbs() {
// init
var (
path = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
)
// Get an absolute representation of path.
fmt.Println(gfile.Abs(path))
// Output:
// /tmp/gfile_example_basic_dir/file1
}
func RealPath(path string) string
func ExampleRealPath() {
// init
var (
realPath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
worryPath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "worryFile")
)
// fetch an absolute representation of path.
fmt.Println(gfile.RealPath(realPath))
fmt.Println(gfile.RealPath(worryPath))
// Output:
// /tmp/gfile_example_basic_dir/file1
//
}
func SelfName() string
func ExampleSelfName() {
// Get file name of current running process
fmt.Println(gfile.SelfName())
// May Output:
// ___github_com_gogf_gf_v2_os_gfile__ExampleSelfName
}
func Basename(path string) string
func ExampleBasename() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the last element of path, which contains file extension.
fmt.Println(gfile.Basename(path))
// Output:
// file.log
}
func Name(path string) string
func ExampleName() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the last element of path without file extension.
fmt.Println(gfile.Name(path))
// Output:
// file
}
func Dir(path string) string
func ExampleDir() {
// init
var (
path = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
)
// Get all but the last element of path, typically the path's directory.
fmt.Println(gfile.Dir(path))
// Output:
// /tmp/gfile_example_basic_dir
}
func Ext(path string) string
func ExampleExt() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the file name extension used by path.
fmt.Println(gfile.Ext(path))
// Output:
// .log
}
func ExtName(path string) string
func ExampleExtName() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the file name extension used by path but the result does not contains symbol '.'.
fmt.Println(gfile.ExtName(path))
// Output:
// log
}
func MainPkgPath() string
func Test() {
fmt.Println("main pkg path on main :", gfile.MainPkgPath())
char := make(chan int, 1)
go func() {
fmt.Println("main pkg path on goroutine :", gfile.MainPkgPath())
char <- 1
}()
select {
case <-char:
}
// Output:
// /xxx/xx/xxx/xx
// /xxx/xx/xxx/xx
}
// 二进制包
$ ./testDemo
main pkg path on main : /xxx/xx/xxx/xx
main pkg path on goroutine : /xxx/xx/xxx/xx
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。