Skip to content

Commit 96fa173

Browse files
committed
chore: fix errcheck
1 parent 99d217a commit 96fa173

File tree

33 files changed

+101
-103
lines changed

33 files changed

+101
-103
lines changed

examples/autotls/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ func main() {
2626
// Create a background context
2727
ctx := context.Background()
2828

29-
log.SetLogLevel("*", "error")
30-
log.SetLogLevel("autotls-example", "debug") // Set the log level for the example to debug
31-
log.SetLogLevel("basichost", "info") // Set the log level for the basichost package to info
32-
log.SetLogLevel("autotls", "debug") // Set the log level for the autotls-example package to debug
33-
log.SetLogLevel("p2p-forge", "debug") // Set the log level for the p2pforge package to debug
34-
log.SetLogLevel("nat", "debug") // Set the log level for the libp2p nat package to debug
29+
_ = log.SetLogLevel("*", "error")
30+
_ = log.SetLogLevel("autotls-example", "debug") // Set the log level for the example to debug
31+
_ = log.SetLogLevel("basichost", "info") // Set the log level for the basichost package to info
32+
_ = log.SetLogLevel("autotls", "debug") // Set the log level for the autotls-example package to debug
33+
_ = log.SetLogLevel("p2p-forge", "debug") // Set the log level for the p2pforge package to debug
34+
_ = log.SetLogLevel("nat", "debug") // Set the log level for the libp2p nat package to debug
3535

3636
certLoaded := make(chan bool, 1) // Create a channel to signal when the cert is loaded
3737

@@ -72,7 +72,7 @@ func main() {
7272
}
7373

7474
// Start the cert manager
75-
certManager.Start()
75+
_ = certManager.Start()
7676
defer certManager.Stop()
7777

7878
// Load or generate a persistent peer identity key
@@ -131,7 +131,7 @@ func main() {
131131
panic(err)
132132
}
133133

134-
go dht.Bootstrap(ctx)
134+
go func() { _ = dht.Bootstrap(ctx) }()
135135

136136
logger.Info("Addresses: ", h.Addrs())
137137

examples/chat-with-rendezvous/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func writeData(rw *bufio.ReadWriter) {
8181

8282
func main() {
8383
log.SetAllLoggers(log.LevelWarn)
84-
log.SetLogLevel("rendezvous", "info")
84+
_ = log.SetLogLevel("rendezvous", "info")
8585
help := flag.Bool("h", false, "Display Help")
8686
config, err := ParseFlags()
8787
if err != nil {

examples/chat/chat.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func writeData(rw *bufio.ReadWriter) {
8787
return
8888
}
8989

90-
rw.WriteString(fmt.Sprintf("%s\n", sendData))
91-
rw.Flush()
90+
_, _ = rw.WriteString(fmt.Sprintf("%s\n", sendData))
91+
_ = rw.Flush()
9292
}
9393
}
9494

@@ -167,7 +167,7 @@ func makeHost(port int, randomness io.Reader) (host.Host, error) {
167167
)
168168
}
169169

170-
func startPeer(ctx context.Context, h host.Host, streamHandler network.StreamHandler) {
170+
func startPeer(_ context.Context, h host.Host, streamHandler network.StreamHandler) {
171171
// Set a function as stream handler.
172172
// This function is called when a peer connects, and starts a stream with this protocol.
173173
// Only applies on the receiving side.
@@ -193,7 +193,7 @@ func startPeer(ctx context.Context, h host.Host, streamHandler network.StreamHan
193193
log.Println()
194194
}
195195

196-
func startPeerAndConnect(ctx context.Context, h host.Host, destination string) (*bufio.ReadWriter, error) {
196+
func startPeerAndConnect(_ context.Context, h host.Host, destination string) (*bufio.ReadWriter, error) {
197197
log.Println("This node's multiaddresses:")
198198
for _, la := range h.Addrs() {
199199
log.Printf(" - %v\n", la)

examples/chat/chat_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func TestMain(t *testing.T) {
6464
return
6565
}
6666

67-
rw.WriteString("test message")
68-
rw.Flush()
67+
_, _ = rw.WriteString("test message")
68+
_ = rw.Flush()
6969
}()
7070

7171
<-ctx.Done()

examples/echo/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func getHostAddress(ha host.Host) string {
9696
return addr.Encapsulate(hostAddr).String()
9797
}
9898

99-
func startListener(ctx context.Context, ha host.Host, listenPort int, insecure bool) {
99+
func startListener(_ context.Context, ha host.Host, listenPort int, insecure bool) {
100100
fullAddr := getHostAddress(ha)
101101
log.Printf("I am %s\n", fullAddr)
102102

@@ -106,9 +106,9 @@ func startListener(ctx context.Context, ha host.Host, listenPort int, insecure b
106106
log.Println("listener received new stream")
107107
if err := doEcho(s); err != nil {
108108
log.Println(err)
109-
s.Reset()
109+
_ = s.Reset()
110110
} else {
111-
s.Close()
111+
_ = s.Close()
112112
}
113113
})
114114

@@ -121,7 +121,7 @@ func startListener(ctx context.Context, ha host.Host, listenPort int, insecure b
121121
}
122122
}
123123

124-
func runSender(ctx context.Context, ha host.Host, targetPeer string) {
124+
func runSender(_ context.Context, ha host.Host, targetPeer string) {
125125
fullAddr := getHostAddress(ha)
126126
log.Printf("I am %s\n", fullAddr)
127127

examples/http-proxy/proxy.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe
8181
// on the stream, before closing it.
8282
func streamHandler(stream network.Stream) {
8383
// Remember to close the stream when we are done.
84-
defer stream.Close()
84+
defer func() { _ = stream.Close() }()
8585

8686
// Create a new buffered reader, as ReadRequest needs one.
8787
// The buffered reader reads from our stream, on which we
@@ -90,11 +90,11 @@ func streamHandler(stream network.Stream) {
9090
// Read the HTTP request from the buffer
9191
req, err := http.ReadRequest(buf)
9292
if err != nil {
93-
stream.Reset()
93+
_ = stream.Reset()
9494
log.Println(err)
9595
return
9696
}
97-
defer req.Body.Close()
97+
defer func() { _ = req.Body.Close() }()
9898

9999
// We need to reset these fields in the request
100100
// URL as they are not maintained.
@@ -114,14 +114,14 @@ func streamHandler(stream network.Stream) {
114114
fmt.Printf("Making request to %s\n", req.URL)
115115
resp, err := http.DefaultTransport.RoundTrip(outreq)
116116
if err != nil {
117-
stream.Reset()
117+
_ = stream.Reset()
118118
log.Println(err)
119119
return
120120
}
121121

122122
// resp.Write writes whatever response we obtained for our
123123
// request back to the stream.
124-
resp.Write(stream)
124+
_ = resp.Write(stream)
125125
}
126126

127127
// Serve listens on the ProxyService's proxy address. This effectively
@@ -130,7 +130,7 @@ func (p *ProxyService) Serve() {
130130
_, serveArgs, _ := manet.DialArgs(p.proxyAddr)
131131
fmt.Println("proxy listening on ", serveArgs)
132132
if p.dest != "" {
133-
http.ListenAndServe(serveArgs, p)
133+
_ = http.ListenAndServe(serveArgs, p)
134134
}
135135
}
136136

@@ -154,12 +154,12 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
154154
http.Error(w, err.Error(), http.StatusInternalServerError)
155155
return
156156
}
157-
defer stream.Close()
157+
defer func() { _ = stream.Close() }()
158158

159159
// r.Write() writes the HTTP request to the stream.
160160
err = r.Write(stream)
161161
if err != nil {
162-
stream.Reset()
162+
_ = stream.Reset()
163163
log.Println(err)
164164
http.Error(w, err.Error(), http.StatusServiceUnavailable)
165165
return
@@ -170,7 +170,7 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
170170
buf := bufio.NewReader(stream)
171171
resp, err := http.ReadResponse(buf, r)
172172
if err != nil {
173-
stream.Reset()
173+
_ = stream.Reset()
174174
log.Println(err)
175175
http.Error(w, err.Error(), http.StatusServiceUnavailable)
176176
return
@@ -187,8 +187,8 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
187187
w.WriteHeader(resp.StatusCode)
188188

189189
// Finally copy the body
190-
io.Copy(w, resp.Body)
191-
resp.Body.Close()
190+
_, _ = io.Copy(w, resp.Body)
191+
_ = resp.Body.Close()
192192
}
193193

194194
// addAddrToPeerstore parses a peer multiaddress and adds
@@ -225,7 +225,7 @@ func addAddrToPeerstore(h host.Host, addr string) peer.ID {
225225
const help = `
226226
This example creates a simple HTTP Proxy using two libp2p peers. The first peer
227227
provides an HTTP server locally which tunnels the HTTP requests with libp2p
228-
to a remote peer. The remote peer performs the requests and
228+
to a remote peer. The remote peer performs the requests and
229229
send the sends the response back.
230230
231231
Usage: Start remote peer first with: ./proxy

examples/ipfs-camp-2019/01-Transports/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func main() {
1313
panic(err)
1414
}
1515

16-
host.Close()
16+
_ = host.Close()
1717
}

examples/ipfs-camp-2019/02-Multiaddrs/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ func main() {
2222

2323
// TODO: with our host made, let's connect to our bootstrap peer
2424

25-
host.Close()
25+
_ = host.Close()
2626
}

examples/ipfs-camp-2019/03-Muxing-Encryption/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
if err != nil {
3131
panic(err)
3232
}
33-
defer host.Close()
33+
defer func() { _ = host.Close() }()
3434

3535
for _, addr := range host.Addrs() {
3636
fmt.Println("Listening on", addr)

examples/ipfs-camp-2019/05-Discovery/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func main() {
7878

7979
select {
8080
case <-stop:
81-
host.Close()
81+
_ = host.Close()
8282
os.Exit(0)
8383
case <-donec:
84-
host.Close()
84+
_ = host.Close()
8585
}
8686
}

examples/ipfs-camp-2019/05-Discovery/protocol.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const chatProtocol = "/libp2p/chat/1.0.0"
1616
func chatHandler(s network.Stream) {
1717
data, err := io.ReadAll(s)
1818
if err != nil {
19-
fmt.Fprintln(os.Stderr, err)
19+
_, _ = fmt.Fprintln(os.Stderr, err)
2020
}
2121
fmt.Println("Received:", string(data))
2222
}
@@ -34,7 +34,7 @@ func chatSend(msg string, s network.Stream) error {
3434
if err = w.Flush(); err != nil {
3535
return err
3636
}
37-
s.Close()
37+
_ = s.Close()
3838
data, err := io.ReadAll(s)
3939
if err != nil {
4040
return err
@@ -54,7 +54,7 @@ func chatInputLoop(ctx context.Context, h host.Host, donec chan struct{}) {
5454
s, err := h.NewStream(ctx, peer, chatProtocol)
5555
defer func() {
5656
if err != nil {
57-
fmt.Fprintln(os.Stderr, err)
57+
_, _ = fmt.Fprintln(os.Stderr, err)
5858
}
5959
}()
6060
if err != nil {

examples/ipfs-camp-2019/06-Pubsub/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type discoveryNotifee struct {
3232
func (m *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
3333
if m.h.Network().Connectedness(pi.ID) != network.Connected {
3434
fmt.Printf("Found %s!\n", pi.ID.ShortString())
35-
m.h.Connect(m.ctx, pi)
35+
_ = m.h.Connect(m.ctx, pi)
3636
}
3737
}
3838

@@ -93,7 +93,7 @@ func main() {
9393

9494
err = host.Connect(ctx, *targetInfo)
9595
if err != nil {
96-
fmt.Fprintf(os.Stderr, "connecting to bootstrap: %s", err)
96+
_, _ = fmt.Fprintf(os.Stderr, "connecting to bootstrap: %s", err)
9797
} else {
9898
fmt.Println("Connected to", targetInfo.ID)
9999
}
@@ -127,9 +127,9 @@ func main() {
127127

128128
select {
129129
case <-stop:
130-
host.Close()
130+
_ = host.Close()
131131
os.Exit(0)
132132
case <-donec:
133-
host.Close()
133+
_ = host.Close()
134134
}
135135
}

examples/ipfs-camp-2019/06-Pubsub/protocol.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const chatProtocol = "/libp2p/chat/1.0.0"
1818
func chatHandler(s network.Stream) {
1919
data, err := io.ReadAll(s)
2020
if err != nil {
21-
fmt.Fprintln(os.Stderr, err)
21+
_, _ = fmt.Fprintln(os.Stderr, err)
2222
}
2323
fmt.Println("Received:", string(data))
2424
}
@@ -38,7 +38,7 @@ func chatSend(msg string, s network.Stream) error {
3838
if err = w.Flush(); err != nil {
3939
return err
4040
}
41-
s.Close()
41+
_ = s.Close()
4242
data, err := io.ReadAll(s)
4343
if err != nil {
4444
return err
@@ -58,7 +58,7 @@ func chatInputLoop(ctx context.Context, h host.Host, donec chan struct{}) {
5858
s, err := h.NewStream(ctx, peer, chatProtocol)
5959
defer func() {
6060
if err != nil {
61-
fmt.Fprintln(os.Stderr, err)
61+
_, _ = fmt.Fprintln(os.Stderr, err)
6262
}
6363
}()
6464
if err != nil {

examples/ipfs-camp-2019/07-Messaging/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type mdnsNotifee struct {
2929
}
3030

3131
func (m *mdnsNotifee) HandlePeerFound(pi peer.AddrInfo) {
32-
m.h.Connect(m.ctx, pi)
32+
_ = m.h.Connect(m.ctx, pi)
3333
}
3434

3535
func main() {
@@ -77,7 +77,7 @@ func main() {
7777
if err != nil {
7878
panic(err)
7979
}
80-
defer topic.Close()
80+
defer func() { _ = topic.Close() }()
8181
sub, err := topic.Subscribe()
8282
if err != nil {
8383
panic(err)
@@ -126,9 +126,9 @@ func main() {
126126

127127
select {
128128
case <-stop:
129-
host.Close()
129+
_ = host.Close()
130130
os.Exit(0)
131131
case <-donec:
132-
host.Close()
132+
_ = host.Close()
133133
}
134134
}

examples/ipfs-camp-2019/07-Messaging/protocol.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func chatInputLoop(ctx context.Context, topic *pubsub.Topic, donec chan struct{}
1919
msgId := make([]byte, 10)
2020
_, err := rand.Read(msgId)
2121
if err != nil {
22-
fmt.Fprintln(os.Stderr, err)
22+
_, _ = fmt.Fprintln(os.Stderr, err)
2323
continue
2424
}
2525
now := time.Now().Unix()
@@ -33,12 +33,12 @@ func chatInputLoop(ctx context.Context, topic *pubsub.Topic, donec chan struct{}
3333
}
3434
msgBytes, err := proto.Marshal(req)
3535
if err != nil {
36-
fmt.Fprintln(os.Stderr, err)
36+
_, _ = fmt.Fprintln(os.Stderr, err)
3737
continue
3838
}
3939
err = topic.Publish(ctx, msgBytes)
4040
if err != nil {
41-
fmt.Fprintln(os.Stderr, err)
41+
_, _ = fmt.Fprintln(os.Stderr, err)
4242
continue
4343
}
4444
}

0 commit comments

Comments
 (0)