Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomasheller/gopath
Get GOPATH or default (Go 1.8+)
https://github.com/thomasheller/gopath
go golang gopath home home-directory
Last synced: 2 days ago
JSON representation
Get GOPATH or default (Go 1.8+)
- Host: GitHub
- URL: https://github.com/thomasheller/gopath
- Owner: thomasheller
- License: mit
- Created: 2017-03-26T15:37:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-26T15:51:24.000Z (over 7 years ago)
- Last Synced: 2024-10-11T05:43:37.218Z (25 days ago)
- Topics: go, golang, gopath, home, home-directory
- Language: Go
- Size: 1.95 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - gopath
README
# gopath
gopath returns the current user's `GOPATH`, compatible with Go 1.8+
That is, it returns the value of the environment variable `GOPATH`,
and if that is not set, the directory named `go` in the user's home
directory.What "home directory" means is platform-specific. gopath uses
[mitchellh/go-homedir](https://github.com/mitchellh/go-homedir) to
find out what the user's home directory is.## Example
```go
package mainimport (
"fmt"
"log""github.com/thomasheller/gopath"
)func main() {
p, err := gopath.Get()
if err != nil {
log.Fatalf("Error getting GOPATH: %v", err)
}fmt.Println(p)
// Output:
// /home/user/go (or whatever GOPATH is set)
}
```For convenience, gopath also provides a function to join the `GOPATH`
with one or more path elements, like `filepath.Join`:```go
package mainimport (
"fmt"
"log""github.com/thomasheller/gopath"
)func main() {
p, err := gopath.Join("src/github.com/thomasheller/gopath")
if err != nil {
log.Fatalf("Error getting GOPATH: %v", err)
}fmt.Println(p)
// Output:
// /home/user/go/src/github.com/thomasheller/gopath (or whatever GOPATH is set)
}
```