forked from drone/funcmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.go
50 lines (44 loc) · 1.16 KB
/
os.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
// Copyright 2018 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Blue Oak Model License
// license that can be found in the LICENSE file.
package funcmap
import (
"io/ioutil"
"os"
)
// Getenv retrieves the value of the environment variable
// named by the key.
func Getenv(key interface{}) (string, error) {
sk, err := toStringE(key)
if err != nil {
return "", err
}
return os.Getenv(sk), nil
}
// ReadDir reads the directory named by dirname and returns
// a list of directory entries sorted by filename.
func ReadDir(dirname interface{}) ([]os.FileInfo, error) {
sd, err := toStringE(dirname)
if err != nil {
return nil, err
}
return ioutil.ReadDir(sd)
}
// ReadFile reads the directory named by dirname and returns
// a list of directory entries sorted by filename.
func ReadFile(filename interface{}) ([]byte, error) {
sf, err := toStringE(filename)
if err != nil {
return nil, err
}
return ioutil.ReadFile(sf)
}
// FileExists returns true if the file exists.
func FileExists(name interface{}) (bool, error) {
sn, err := toStringE(name)
if err != nil {
return false, err
}
_, err = os.Stat(sn)
return err == nil, nil
}