Skip to content

go-basic/homedir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

homedir

用于检测用户的主目录的Go库

用法

go get github.com/go-basic/homedir

用法非常简单,只需调用' homedir.Dir() '来获取用户主目录

使用' homedir.Expand() '将路径中的' ~ '展开到home目录中。

如: HOME=/custom/path/

homedir.Expand("~/foo/bar") 输出 /custom/path/foo/bar

示例

package main

import (
	"fmt"
	"github.com/go-basic/homedir"
)

func main()  {
	dir,err := homedir.Dir()
	if err != nil {
		panic(err)
    }
	fmt.Println(dir)

	foo,_ := homedir.Expand("~/foo")
	fmt.Println(foo)
}

About

用于检测用户的主目录的Go库

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages