如何知道我们可以使用一个去包裹的功能?(How to know the functions we can use with a go package?)
我正在学习go语言,并在一些网络资源的帮助下编写我的第一个去程序:
package main import ( "fmt" "crypto/sha512" "encoding/base64" ) func main() { ba := []byte("HelloWorld") hasher := sha512.New() hasher.Write(ba) sha := base64.StdEncoding.EncodeToString(hasher.Sum(nil)) fmt.Printf(sha) }
它编译并按预期工作,但我不能自己编写这段代码,因为如果我查看sha256的Go包参考,我没有看到
Write()
和Sum()
方法。 哪里可以找到这种信息? 也许,我没有阅读这份好文件,或者我没有看到某种“继承”。I am learning the go language and write my first go program, with the help of some web sources:
package main import ( "fmt" "crypto/sha512" "encoding/base64" ) func main() { ba := []byte("HelloWorld") hasher := sha512.New() hasher.Write(ba) sha := base64.StdEncoding.EncodeToString(hasher.Sum(nil)) fmt.Printf(sha) }
It compiles and works as expected, but I couldn't write this code myself since if i look at the Go package reference for sha256, I don't see the
Write()
and theSum()
methods. Where to find this kind of information? Maybe, I'm not reading the good document, or there is a sort of "inheritance" I didn't see.
原文:https://stackoverflow.com/questions/35295339
更新时间:2023-08-01 21:08