在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:libp2p/go-libp2p-http开源软件地址:https://github.com/libp2p/go-libp2p-http开源编程语言:Go 100.0%开源软件介绍:go-libp2p-http
Package Instead of the regular "host:port" addressing, Table of ContentsInstallThis package is a library that uses Go modules for dependency management. UsageFull documentation can be read at Godoc. The important bits follow. A simple listener, _ := gostream.Listen(host1, p2phttp.DefaultP2PProtocol)
defer listener.Close()
go func() {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hi!"))
})
server := &http.Server{}
server.Serve(listener)
} The listener is provided by https://github.com/libp2p/go-libp2p-gostream . A client just needs to be initialized with a custom libp2p host-based transport to perform requests to such server: tr := &http.Transport{}
tr.RegisterProtocol("libp2p", p2phttp.NewTransport(clientHost))
client := &http.Client{Transport: tr}
res, err := client.Get("libp2p://Qmaoi4isbcTbFfohQyn28EiYM5CDWQx9QRCjDh3CTeiY7P/hello") ContributePRs accepted. LicenseMIT © Protocol Labs, Inc. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论