forked from github-release/github-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
52 lines (43 loc) · 905 Bytes
/
util.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
package main
import (
"fmt"
"os"
"time"
)
/* nvls returns the first value in xs that is not empty. */
func nvls(xs ...string) string {
for _, s := range xs {
if s != "" {
return s
}
}
return ""
}
func vprintln(a ...interface{}) (int, error) {
if VERBOSITY > 0 {
return fmt.Fprintln(os.Stderr, a...)
}
return 0, nil
}
func vprintf(format string, a ...interface{}) (int, error) {
if VERBOSITY > 0 {
return fmt.Fprintf(os.Stderr, format, a...)
}
return 0, nil
}
// formats time `t` as `fmt` if it is not nil, otherwise returns `def`
func timeFmtOr(t *time.Time, fmt, def string) string {
if t == nil {
return def
}
return t.Format(fmt)
}
// isCharDevice returns true if f is a character device (panics if f can't
// be stat'ed).
func isCharDevice(f *os.File) bool {
stat, err := f.Stat()
if err != nil {
panic(err)
}
return (stat.Mode() & os.ModeCharDevice) != 0
}