https://github.com/hmarr/pkgextract
Extract a set of Go packages that depend on one another
https://github.com/hmarr/pkgextract
Last synced: 12 months ago
JSON representation
Extract a set of Go packages that depend on one another
- Host: GitHub
- URL: https://github.com/hmarr/pkgextract
- Owner: hmarr
- Created: 2018-10-20T21:44:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-27T14:56:54.000Z (over 7 years ago)
- Last Synced: 2025-06-05T05:40:48.593Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pkgextract
A library for extracting a set of Go packages that depend on one another.
## Example
Extract the `cmd/go/internal/modload` package from [golang/go](https://github.com/golang/go), along with all the package it depends on, replacing `internal` with `_internal_` in import paths.
```go
package main
import (
"log"
"path/filepath"
"strings"
"github.com/hmarr/pkgextract"
)
func main() {
extractor := pkgextract.NewPackageExtractor(pkgextract.PackageExtractorOptions{
InitialPkg: "cmd/go/internal/modload",
OutputRoot: "./out",
ImportRewriter: func(importPath string) string {
newPath := strings.Replace(importPath, "internal", "_internal_", -1)
return filepath.Join("github.com/dependabot/gomodules-extracted", newPath)
},
Filter: func(importPath string) bool {
return strings.Contains(importPath, "internal")
},
})
if err := extractor.Run(); err != nil {
log.Fatal(err)
}
}
```