如何使用 Go Modules 打印我项目中使用的许可证?
How to print the licenses used in my project using Go Modules?
出于法律原因,我需要我的项目使用的依赖项(直接库和瞬态库)的许可证列表(例如 MIT、Apache)。我只知道how to print a list of dependencies without licenses.
有没有办法打印带有 Go 模块许可证的依赖项列表?类似于在 npm (NPM License Checker) and Gradle (Gradle License Report) 中所做的。
谢谢!
你试过了吗github.com/google/go-licenses?
运行
go get -v github.com/google/go-licenses
go build github.com/google/go-licenses
./go-licenses csv .
这至少给了你一些信息。
有点冗长:
所以我创建了一个测试项目:
package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
)
func main() {
log.Warn("Warn")
foo := make(map[string]bool)
foo["bar"] = true
j, _ := json.MarshalIndent(foo, " ", " ")
fmt.Println(string(j))
}
我做的:
me@dattan:~/testing/blabla$ go mod init example.com/test
go: creating new go.mod: module example.com/test
me@dattan:~/testing/blabla$ go build
go: finding module for package github.com/sirupsen/logrus
go: downloading github.com/sirupsen/logrus v1.5.0
go: found github.com/sirupsen/logrus in github.com/sirupsen/logrus v1.5.0
go: downloading golang.org/x/sys v0.0.0-20190422165155-953cdadca894
me@dattan:~/testing/blabla$ go get -v github.com/google/go-licenses
go: downloading github.com/google/go-licenses v0.0.0-20200227160636-0fa8c766a591
... [lots of downloads, that's why -v to see it's not dead]
github.com/google/go-licenses
me@dattan:~/testing/blabla$ go build github.com/google/go-licenses
me@dattan:~/testing/blabla$ ./go-licenses csv .
E0406 23:03:48.578291 32389 library.go:108] Failed to find license for example.com/test: no file/directory matching regexp "^(LICEN(S|C)E|COPYING|README|NOTICE)(\..+)?$" found for /home/me/testing/blabla
E0406 23:03:48.627889 32389 csv.go:84] Error discovering URL for "/home/me/go/pkg/mod/golang.org/x/sys@v0.0.0-20191119060738-e882bf8e40c2/LICENSE":
- unsupported package host "golang.org" for "golang.org/x/sys/unix"
example.com/test,Unknown,Unknown
github.com/sirupsen/logrus,https://github.com/sirupsen/logrus/blob/master/LICENSE,MIT
golang.org/x/sys/unix,Unknown,BSD-3-Clause
还有最后几行,并不完美,但它确实看到 logrus 是 MIT 并向许可证提供了 link。我缺少 LICENSE 文件的测试包当然失败了。
根据评论编辑
虽然以上对我有用,但这些是提问者需要执行的命令:
go build ./...
./go-licenses csv ./...
出于法律原因,我需要我的项目使用的依赖项(直接库和瞬态库)的许可证列表(例如 MIT、Apache)。我只知道how to print a list of dependencies without licenses.
有没有办法打印带有 Go 模块许可证的依赖项列表?类似于在 npm (NPM License Checker) and Gradle (Gradle License Report) 中所做的。 谢谢!
你试过了吗github.com/google/go-licenses?
运行
go get -v github.com/google/go-licenses
go build github.com/google/go-licenses
./go-licenses csv .
这至少给了你一些信息。
有点冗长: 所以我创建了一个测试项目:
package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
)
func main() {
log.Warn("Warn")
foo := make(map[string]bool)
foo["bar"] = true
j, _ := json.MarshalIndent(foo, " ", " ")
fmt.Println(string(j))
}
我做的:
me@dattan:~/testing/blabla$ go mod init example.com/test
go: creating new go.mod: module example.com/test
me@dattan:~/testing/blabla$ go build
go: finding module for package github.com/sirupsen/logrus
go: downloading github.com/sirupsen/logrus v1.5.0
go: found github.com/sirupsen/logrus in github.com/sirupsen/logrus v1.5.0
go: downloading golang.org/x/sys v0.0.0-20190422165155-953cdadca894
me@dattan:~/testing/blabla$ go get -v github.com/google/go-licenses
go: downloading github.com/google/go-licenses v0.0.0-20200227160636-0fa8c766a591
... [lots of downloads, that's why -v to see it's not dead]
github.com/google/go-licenses
me@dattan:~/testing/blabla$ go build github.com/google/go-licenses
me@dattan:~/testing/blabla$ ./go-licenses csv .
E0406 23:03:48.578291 32389 library.go:108] Failed to find license for example.com/test: no file/directory matching regexp "^(LICEN(S|C)E|COPYING|README|NOTICE)(\..+)?$" found for /home/me/testing/blabla
E0406 23:03:48.627889 32389 csv.go:84] Error discovering URL for "/home/me/go/pkg/mod/golang.org/x/sys@v0.0.0-20191119060738-e882bf8e40c2/LICENSE":
- unsupported package host "golang.org" for "golang.org/x/sys/unix"
example.com/test,Unknown,Unknown
github.com/sirupsen/logrus,https://github.com/sirupsen/logrus/blob/master/LICENSE,MIT
golang.org/x/sys/unix,Unknown,BSD-3-Clause
还有最后几行,并不完美,但它确实看到 logrus 是 MIT 并向许可证提供了 link。我缺少 LICENSE 文件的测试包当然失败了。
根据评论编辑 虽然以上对我有用,但这些是提问者需要执行的命令:
go build ./...
./go-licenses csv ./...