https://github.com/nakabonne/modpath
Detect your module path from anywhere
https://github.com/nakabonne/modpath
go golang gomod gomodule
Last synced: 10 months ago
JSON representation
Detect your module path from anywhere
- Host: GitHub
- URL: https://github.com/nakabonne/modpath
- Owner: nakabonne
- License: mit
- Created: 2019-12-30T06:08:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-31T08:35:44.000Z (over 6 years ago)
- Last Synced: 2025-03-27T03:11:14.719Z (about 1 year ago)
- Topics: go, golang, gomod, gomodule
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# modpath
[](http://godoc.org/github.com/nakabonne/modpath)
[](https://codecov.io/gh/nakabonne/modpath)
`modpath` provides an API to detect the module path from the `go.mod` file underneath the given directory or its root.
## Installation
```
go get github.com/nakabonne/modpath
```
## Usage
```go
package main
import (
"fmt"
"github.com/nakabonne/modpath"
)
func main() {
modulePath, _ := modpath.Run("/path/to/foo/bar")
fmt.Println(modulePath) // -> "example.com/foo/bar"
}
```
### Using as a replacement for `go list -m`
Unlike `go list -m`, you can inspect any directories except for the current directory.
```console
$ cat /path/to/foo/bar/go.mod
module example.com/foo/bar
go 1.13
$ modpath /path/to/foo/bar/
example.com/foo/bar
```
If no directory is explicitly given, the module containing the current directory is emitted as `go list -m` does.