forked from goproxy/goproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goproxy.go
829 lines (724 loc) · 18.7 KB
/
goproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/*
Package goproxy implements a minimalist Go module proxy handler.
*/
package goproxy
import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"math/rand"
"net/http"
"net/url"
"os"
"path"
"strconv"
"strings"
"sync"
"time"
"golang.org/x/mod/sumdb"
)
// Goproxy is the top-level struct of this project.
//
// Note that the Goproxy will still follow your environment variables. Which
// means you can set GOPROXY to serve the Goproxy itself under other proxies,
// and by setting GONOPROXY and GOPRIVATE to instruct which modules the Goproxy
// should fetch directly instead of using those proxies. And you can also set
// GOSUMDB, GONOSUMDB and GOPRIVATE to instruct how the Goproxy should verify
// the modules it just fetched. All of the above environment variables have been
// built-in support, which means less external command calls and a significant
// performance boost.
//
// For requests downloading large numbers of modules (e.g. for bulk static
// analysis), the Goproxy supports a non-standard header, "Disable-Module-Fetch:
// true" that instructs it to return only cached content.
//
// Make sure that all fields of the Goproxy have been finalized before calling
// any of its methods.
type Goproxy struct {
// GoBinName is the name of the Go binary.
//
// If the GoBinName is empty, the "go" is used.
//
// Note that the version of the Go binary targeted by the GoBinName must
// be at least v1.11.
GoBinName string
// GoBinEnv is the environment of the Go binary. Each entry is of the
// form "key=value".
//
// If the GoBinEnv is nil, the [os.Environ] is used.
//
// If the GoBinEnv contains duplicate environment keys, only the last
// value in the slice for each duplicate key is used.
//
// Note that GOPROXY, GONOPROXY, GOSUMDB, GONOSUMDB and GOPRIVATE have
// been built-in support. Which means they can be set even the version
// of the Go binary targeted by the [Goproxy.GoBinName] is before v1.13.
GoBinEnv []string
// GoBinMaxWorkers is the maximum number of commands allowed for the Go
// binary to execute at the same time.
//
// If the GoBinMaxWorkers is zero, there is no limit.
GoBinMaxWorkers int
// PathPrefix is the prefix of all request paths. It will be used to
// trim the request paths via the [strings.TrimPrefix].
//
// If the PathPrefix is not empty, it must start with "/", and usually
// should also end with "/".
PathPrefix string
// Cacher is the [Cacher] that used to cache module files.
//
// If the Cacher is nil, the module files will be temporarily stored on
// the local disk and discarded as the request ends.
Cacher Cacher
// CacherMaxCacheBytes is the maximum number of bytes allowed for the
// [Goproxy.Cacher] to store a cache.
//
// If the CacherMaxCacheBytes is zero, there is no limit.
CacherMaxCacheBytes int
// ProxiedSUMDBs is the list of proxied checksum databases (see
// https://go.dev/design/25530-sumdb#proxying-a-checksum-database). Each
// entry is of the form "<sumdb-name>" or "<sumdb-name> <sumdb-URL>".
// The first form is a shorthand for the second form, in which case the
// corresponding <sumdb-URL> will be the <sumdb-name> itself as a host
// with an "https" scheme.
//
// If the ProxiedSUMDBs contains duplicate checksum database names, only
// the last value in the slice for each duplicate checksum database name
// is used.
ProxiedSUMDBs []string
// Transport is used to perform all requests except those started by
// calling the Go binary targeted by the [Goproxy.GoBinName].
//
// If the Transport is nil, the [http.DefaultTransport] is used.
Transport http.RoundTripper
// TempDir is the directory for storing temporary files.
//
// If the TempDir is empty, the [os.TempDir] is used.
TempDir string
// ErrorLogger is the [log.Logger] that logs errors that occur while
// proxying.
//
// If the ErrorLogger is nil, logging is done via the [log] package's
// standard logger.
ErrorLogger *log.Logger
initOnce sync.Once
goBinName string
goBinEnv []string
goBinEnvGOPROXY string
goBinEnvGONOPROXY string
goBinEnvGOSUMDB string
goBinEnvGONOSUMDB string
goBinWorkerChan chan struct{}
proxiedSUMDBs map[string]*url.URL
httpClient *http.Client
sumdbClient *sumdb.Client
}
// init initializes the g.
func (g *Goproxy) init() {
g.goBinName = g.GoBinName
if g.goBinName == "" {
g.goBinName = "go"
}
goBinEnv := g.GoBinEnv
if goBinEnv == nil {
goBinEnv = os.Environ()
}
var goBinEnvGOPRIVATE string
for _, env := range goBinEnv {
if envParts := strings.SplitN(env, "=", 2); len(envParts) == 2 {
switch strings.TrimSpace(envParts[0]) {
case "GO111MODULE":
case "GOPROXY":
g.goBinEnvGOPROXY = envParts[1]
case "GONOPROXY":
g.goBinEnvGONOPROXY = envParts[1]
case "GOSUMDB":
g.goBinEnvGOSUMDB = envParts[1]
case "GONOSUMDB":
g.goBinEnvGONOSUMDB = envParts[1]
case "GOPRIVATE":
goBinEnvGOPRIVATE = envParts[1]
default:
g.goBinEnv = append(g.goBinEnv, fmt.Sprintf(
"%s=%s",
envParts[0],
envParts[1],
))
}
}
}
g.goBinEnv = append(
g.goBinEnv,
"GO111MODULE=on",
"GOPROXY=direct",
"GONOPROXY=",
"GOSUMDB=off",
"GONOSUMDB=",
"GOPRIVATE=",
)
var goBinEnvGOPROXY string
for goproxy := g.goBinEnvGOPROXY; goproxy != ""; {
var proxy, sep string
if i := strings.IndexAny(goproxy, ",|"); i >= 0 {
proxy = goproxy[:i]
sep = string(goproxy[i])
goproxy = goproxy[i+1:]
if goproxy == "" {
sep = ""
}
} else {
proxy = goproxy
goproxy = ""
}
proxy = strings.TrimSpace(proxy)
switch proxy {
case "":
continue
case "direct", "off":
sep = ""
goproxy = ""
}
goBinEnvGOPROXY = fmt.Sprint(goBinEnvGOPROXY, proxy, sep)
}
if goBinEnvGOPROXY != "" {
g.goBinEnvGOPROXY = goBinEnvGOPROXY
} else if g.goBinEnvGOPROXY == "" {
g.goBinEnvGOPROXY = "https://proxy.golang.org,direct"
} else {
g.goBinEnvGOPROXY = "off"
}
g.goBinEnvGOSUMDB = strings.TrimSpace(g.goBinEnvGOSUMDB)
if g.goBinEnvGOSUMDB == "" {
g.goBinEnvGOSUMDB = "sum.golang.org"
}
if g.goBinEnvGONOPROXY == "" {
g.goBinEnvGONOPROXY = goBinEnvGOPRIVATE
}
var goBinEnvGONOPROXYParts []string
for _, noproxy := range strings.Split(g.goBinEnvGONOPROXY, ",") {
if noproxy = strings.TrimSpace(noproxy); noproxy != "" {
goBinEnvGONOPROXYParts = append(
goBinEnvGONOPROXYParts,
noproxy,
)
}
}
if len(goBinEnvGONOPROXYParts) > 0 {
g.goBinEnvGONOPROXY = strings.Join(goBinEnvGONOPROXYParts, ",")
}
if g.goBinEnvGONOSUMDB == "" {
g.goBinEnvGONOSUMDB = goBinEnvGOPRIVATE
}
var goBinEnvGONOSUMDBParts []string
for _, nosumdb := range strings.Split(g.goBinEnvGONOSUMDB, ",") {
if nosumdb = strings.TrimSpace(nosumdb); nosumdb != "" {
goBinEnvGONOSUMDBParts = append(
goBinEnvGONOSUMDBParts,
nosumdb,
)
}
}
if len(goBinEnvGONOSUMDBParts) > 0 {
g.goBinEnvGONOSUMDB = strings.Join(goBinEnvGONOSUMDBParts, ",")
}
if g.GoBinMaxWorkers != 0 {
g.goBinWorkerChan = make(chan struct{}, g.GoBinMaxWorkers)
}
g.proxiedSUMDBs = map[string]*url.URL{}
for _, proxiedSUMDB := range g.ProxiedSUMDBs {
sumdbParts := strings.Fields(proxiedSUMDB)
if len(sumdbParts) == 0 {
continue
}
sumdbName := sumdbParts[0]
rawSUMDBURL := sumdbName
if len(sumdbParts) > 1 {
rawSUMDBURL = sumdbParts[1]
}
sumdbURL, err := parseRawURL(rawSUMDBURL)
if err != nil {
continue
}
g.proxiedSUMDBs[sumdbName] = sumdbURL
}
g.httpClient = &http.Client{Transport: g.Transport}
g.sumdbClient = sumdb.NewClient(&sumdbClientOps{
envGOPROXY: g.goBinEnvGOPROXY,
envGOSUMDB: g.goBinEnvGOSUMDB,
httpClient: g.httpClient,
})
}
// ServeHTTP implements the [http.Handler].
func (g *Goproxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
g.initOnce.Do(g.init)
switch req.Method {
case http.MethodGet, http.MethodHead:
default:
responseMethodNotAllowed(rw, req, 86400)
return
}
name, _ := url.PathUnescape(req.URL.Path)
if name == "" ||
name[0] != '/' ||
name[len(name)-1] == '/' ||
strings.Contains(name, "..") {
responseNotFound(rw, req, 86400)
return
}
name = path.Clean(name)
if g.PathPrefix != "" {
name = strings.TrimPrefix(name, g.PathPrefix)
} else {
name = strings.TrimPrefix(name, "/")
}
tempDir, err := ioutil.TempDir(g.TempDir, "goproxy")
if err != nil {
g.logErrorf("failed to create temporary directory: %v", err)
responseInternalServerError(rw, req)
return
}
defer os.RemoveAll(tempDir)
if strings.HasPrefix(name, "sumdb/") {
g.serveSUMDB(rw, req, name, tempDir)
return
}
g.serveFetch(rw, req, name, tempDir)
}
// serveFetch serves fetch requests.
func (g *Goproxy) serveFetch(
rw http.ResponseWriter,
req *http.Request,
name string,
tempDir string,
) {
f, err := newFetch(g, name, tempDir)
if err != nil {
responseNotFound(rw, req, 86400, err)
return
}
var isDownload bool
switch f.ops {
case fetchOpsDownloadInfo, fetchOpsDownloadMod, fetchOpsDownloadZip:
isDownload = true
}
noFetch, _ := strconv.ParseBool(req.Header.Get("Disable-Module-Fetch"))
if noFetch {
var cacheControlMaxAge int
if isDownload {
cacheControlMaxAge = 604800
} else {
cacheControlMaxAge = 60
}
g.serveCache(
rw,
req,
f.name,
f.contentType,
cacheControlMaxAge,
func() {
responseNotFound(
rw,
req,
60,
"temporarily unavailable",
)
},
)
return
}
if isDownload {
g.serveCache(rw, req, f.name, f.contentType, 604800, func() {
g.serveFetchDownload(rw, req, f)
})
return
}
fr, err := f.do(req.Context())
if err != nil {
g.serveCache(rw, req, f.name, f.contentType, 60, func() {
g.logErrorf(
"failed to %s module version: %s: %v",
f.ops,
f.name,
err,
)
responseError(rw, req, err, true)
})
return
}
content, err := fr.Open()
if err != nil {
g.logErrorf("failed to open fetch result: %s: %v", f.name, err)
responseInternalServerError(rw, req)
return
}
defer content.Close()
if err := g.putCache(req.Context(), f.name, content); err != nil {
g.logErrorf("failed to cache module file: %s: %v", f.name, err)
responseInternalServerError(rw, req)
return
} else if _, err := content.Seek(0, io.SeekStart); err != nil {
g.logErrorf(
"failed to seek fetch result content: %s: %v",
f.name,
err,
)
responseInternalServerError(rw, req)
return
}
responseSuccess(rw, req, content, f.contentType, 60)
}
// serveFetchDownload serves fetch download requests.
func (g *Goproxy) serveFetchDownload(
rw http.ResponseWriter,
req *http.Request,
f *fetch,
) {
fr, err := f.do(req.Context())
if err != nil {
g.logErrorf(
"failed to download module version: %s: %v",
f.name,
err,
)
responseError(rw, req, err, false)
return
}
nameWithoutExt := strings.TrimSuffix(f.name, path.Ext(f.name))
for _, cache := range []struct{ nameExt, localFile string }{
{".info", fr.Info},
{".mod", fr.GoMod},
{".zip", fr.Zip},
} {
if cache.localFile == "" {
continue
}
if err := g.putCacheFile(
req.Context(),
fmt.Sprint(nameWithoutExt, cache.nameExt),
cache.localFile,
); err != nil {
g.logErrorf(
"failed to cache module file: %s: %v",
f.name,
err,
)
responseInternalServerError(rw, req)
return
}
}
content, err := fr.Open()
if err != nil {
g.logErrorf("failed to open fetch result: %s: %v", f.name, err)
responseInternalServerError(rw, req)
return
}
defer content.Close()
responseSuccess(rw, req, content, f.contentType, 604800)
}
// serveSUMDB serves checksum database proxy requests.
func (g *Goproxy) serveSUMDB(
rw http.ResponseWriter,
req *http.Request,
name string,
tempDir string,
) {
sumdbURL, err := parseRawURL(strings.TrimPrefix(name, "sumdb/"))
if err != nil {
responseNotFound(rw, req, 86400)
return
}
proxiedSUMDBURL, ok := g.proxiedSUMDBs[sumdbURL.Host]
if !ok {
responseNotFound(rw, req, 86400)
return
}
var (
contentType string
cacheControlMaxAge int
)
if sumdbURL.Path == "/supported" {
setResponseCacheControlHeader(rw, 86400)
rw.WriteHeader(http.StatusOK)
return
} else if sumdbURL.Path == "/latest" {
contentType = "text/plain; charset=utf-8"
cacheControlMaxAge = 3600
} else if strings.HasPrefix(sumdbURL.Path, "/lookup/") {
contentType = "text/plain; charset=utf-8"
cacheControlMaxAge = 86400
} else if strings.HasPrefix(sumdbURL.Path, "/tile/") {
contentType = "application/octet-stream"
cacheControlMaxAge = 86400
} else {
responseNotFound(rw, req, 86400)
return
}
tempFile, err := ioutil.TempFile(tempDir, "")
if err != nil {
g.logErrorf("failed to create temporary file: %v", err)
responseInternalServerError(rw, req)
return
}
if err := httpGet(
req.Context(),
g.httpClient,
appendURL(proxiedSUMDBURL, sumdbURL.Path).String(),
tempFile,
); err != nil {
g.serveCache(
rw,
req,
name,
contentType,
cacheControlMaxAge,
func() {
g.logErrorf(
"failed to proxy checksum database: "+
"%s: %v",
name,
err,
)
responseError(rw, req, err, true)
},
)
return
}
if err := tempFile.Close(); err != nil {
g.logErrorf("failed to close temporary file: %v", err)
responseInternalServerError(rw, req)
return
}
if err := g.putCacheFile(
req.Context(),
name,
tempFile.Name(),
); err != nil {
g.logErrorf("failed to cache module file: %s: %v", name, err)
responseInternalServerError(rw, req)
return
}
content, err := os.Open(tempFile.Name())
if err != nil {
g.logErrorf("failed to open temporary file: %s: %v", name, err)
responseInternalServerError(rw, req)
return
}
defer content.Close()
responseSuccess(rw, req, content, contentType, cacheControlMaxAge)
}
// serveCache serves requests with cached module files.
func (g *Goproxy) serveCache(
rw http.ResponseWriter,
req *http.Request,
name string,
contentType string,
cacheControlMaxAge int,
onNotFound func(),
) {
content, err := g.cache(req.Context(), name)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
onNotFound()
return
}
g.logErrorf(
"failed to get cached module file: %s: %v",
name,
err,
)
responseInternalServerError(rw, req)
return
}
defer content.Close()
responseSuccess(rw, req, content, contentType, cacheControlMaxAge)
}
// cache returns the matched cache for the name from the g.Cacher.
func (g *Goproxy) cache(
ctx context.Context,
name string,
) (io.ReadCloser, error) {
if g.Cacher == nil {
return nil, os.ErrNotExist
}
return g.Cacher.Get(ctx, name)
}
// putCache puts a cache to the g.Cacher for the name with the content.
func (g *Goproxy) putCache(
ctx context.Context,
name string,
content io.ReadSeeker,
) error {
if g.Cacher == nil {
return nil
}
if g.CacherMaxCacheBytes != 0 {
if size, err := content.Seek(0, io.SeekEnd); err != nil {
return err
} else if size > int64(g.CacherMaxCacheBytes) {
return nil
} else if _, err := content.Seek(0, io.SeekStart); err != nil {
return err
}
}
return g.Cacher.Put(ctx, name, content)
}
// putCacheFile puts a cache to the g.Cacher for the name with the targeted
// local file.
func (g *Goproxy) putCacheFile(ctx context.Context, name, file string) error {
f, err := os.Open(file)
if err != nil {
return err
}
defer f.Close()
return g.putCache(ctx, name, f)
}
// logErrorf formats according to the format and logs the v as an error.
func (g *Goproxy) logErrorf(format string, v ...interface{}) {
msg := fmt.Sprint("goproxy: ", fmt.Sprintf(format, v...))
if g.ErrorLogger != nil {
g.ErrorLogger.Output(2, msg)
} else {
log.Output(2, msg)
}
}
// walkGOPROXY walks the proxy list parsed from the goproxy.
func walkGOPROXY(
goproxy string,
onProxy func(proxy string) error,
onDirect func() error,
onOff func() error,
) error {
if goproxy == "" {
return errors.New("missing GOPROXY")
}
var proxyError error
for goproxy != "" {
var (
proxy string
fallBackOnError bool
)
if i := strings.IndexAny(goproxy, ",|"); i >= 0 {
proxy = goproxy[:i]
fallBackOnError = goproxy[i] == '|'
goproxy = goproxy[i+1:]
} else {
proxy = goproxy
goproxy = ""
}
switch proxy {
case "direct":
return onDirect()
case "off":
return onOff()
}
if err := onProxy(proxy); err != nil {
if fallBackOnError || errors.Is(err, errNotFound) {
proxyError = err
continue
}
return err
}
return nil
}
return proxyError
}
var (
exponentialBackoffRand = rand.New(rand.NewSource(time.Now().UnixNano()))
exponentialBackoffMutex sync.Mutex
)
// exponentialBackoffSleep computes the exponential backoff sleep according to
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.
func exponentialBackoffSleep(
base time.Duration,
cap time.Duration,
attempt int,
) time.Duration {
var pow time.Duration
if attempt < 63 {
pow = 1 << attempt
} else {
pow = math.MaxInt64
}
sleep := base * pow
if sleep > cap || sleep/pow != base {
sleep = cap
}
exponentialBackoffMutex.Lock()
sleep = time.Duration(exponentialBackoffRand.Int63n(int64(sleep)))
exponentialBackoffMutex.Unlock()
return sleep
}
// stringSliceContains reports whether the ss contains the s.
func stringSliceContains(ss []string, s string) bool {
for _, v := range ss {
if v == s {
return true
}
}
return false
}
// globsMatchPath reports whether any path prefix of target matches one of the
// glob patterns (as defined by the [path.Match]) in the comma-separated globs
// list. It ignores any empty or malformed patterns in the list.
func globsMatchPath(globs, target string) bool {
for globs != "" {
// Extract next non-empty glob in comma-separated list.
var glob string
if i := strings.Index(globs, ","); i >= 0 {
glob, globs = globs[:i], globs[i+1:]
} else {
glob, globs = globs, ""
}
if glob == "" {
continue
}
// A glob with N+1 path elements (N slashes) needs to be matched
// against the first N+1 path elements of target, which end just
// before the N+1'th slash.
n := strings.Count(glob, "/")
prefix := target
// Walk target, counting slashes, truncating at the N+1'th
// slash.
for i := 0; i < len(target); i++ {
if target[i] == '/' {
if n == 0 {
prefix = target[:i]
break
}
n--
}
}
if n > 0 {
// Not enough prefix elements.
continue
}
if matched, _ := path.Match(glob, prefix); matched {
return true
}
}
return false
}
// readSeekCloser is the interface that groups the basic Read, Seek and Close
// methods.
//
// TODO: Remove the readSeekCloser when the minimum supported Go version is
// 1.16. See https://go.dev/doc/go1.16#io.
type readSeekCloser interface {
io.Reader
io.Seeker
io.Closer
}
// nopCloser is an [io.ReadCloser] with a no-op Close method wrapping an
// [io.Reader].
//
// TODO: Remove the nopCloser when the minimum supported Go version is 1.16. See
// https://go.dev/doc/go1.16#io.
type nopCloser struct {
io.Reader
}
// Close implements the [io.Closer].
func (nopCloser) Close() error { return nil }