-
Notifications
You must be signed in to change notification settings - Fork 22
/
utils.go
43 lines (38 loc) · 982 Bytes
/
utils.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
package utils
import (
"fmt"
"io/ioutil"
"log"
"runtime"
"strings"
"time"
"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
func PrintVersion(log logr.Logger) {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
}
func CtrlZapOptions() zap.Options {
opts := zap.Options{
Development: true,
TimeEncoder: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("2006-01-02 15:04:05 MST"))
},
}
return opts
}
// Validate return true if the file exists and the content is not empty
func Validate(filePath string) bool {
if len(filePath) == 0 {
return false
}
content, err := ioutil.ReadFile(filePath) // #nosec G304
if err != nil {
log.Printf("failed to read file %s - %v", filePath, err)
return false
}
trimmedContent := strings.TrimSpace(string(content))
return len(trimmedContent) > 0
}