-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.go
More file actions
45 lines (38 loc) · 686 Bytes
/
util.go
File metadata and controls
45 lines (38 loc) · 686 Bytes
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
package main
import (
"fmt"
"io"
"golang.org/x/exp/constraints"
)
func min[T constraints.Ordered](a, b T) T {
if a < b {
return a
}
return b
}
func panicIfErr(err error) {
if err != nil {
panic(err)
}
}
func panicIfTrue(b bool, msg string) {
if b {
panic(msg)
}
}
func panicIfErr2[T any](_ T, err error) {
if err != nil {
panic(err)
}
}
func ioCopy(dst io.Writer, src io.Reader, buf []byte, expected int64) error {
if buf == nil {
buf = make([]byte, 128*1024)
}
if n, err := io.CopyBuffer(dst, src, buf); err != nil {
return err
} else if expected >= 0 && n != expected {
return fmt.Errorf("expected %d bytes, got %d", expected, n)
}
return nil
}