github.com/cockroachdb/tools@v0.0.0-20230222021103-a6d27438930d/internal/jsonrpc2_v2/serve_pre116.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !go1.16 6 // +build !go1.16 7 8 package jsonrpc2 9 10 import ( 11 "errors" 12 "strings" 13 ) 14 15 // errClosed is an error with the same string as net.ErrClosed, 16 // which was added in Go 1.16. 17 var errClosed = errors.New("use of closed network connection") 18 19 // isErrClosed reports whether err ends in the same string as errClosed. 20 func isErrClosed(err error) bool { 21 // As of Go 1.16, this could be 'errors.Is(err, net.ErrClosing)', but 22 // unfortunately gopls still requires compatibility with 23 // (otherwise-unsupported) older Go versions. 24 // 25 // In the meantime, this error string has not changed on any supported Go 26 // version, and is not expected to change in the future. 27 // This is not ideal, but since the worst that could happen here is some 28 // superfluous logging, it is acceptable. 29 return strings.HasSuffix(err.Error(), "use of closed network connection") 30 }