-
Notifications
You must be signed in to change notification settings - Fork 80
/
local.go
52 lines (41 loc) · 933 Bytes
/
local.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"
"path/filepath"
)
// LocalAssets contains the local objects to be uploaded
func LocalAssets(path string) ([]string, error) {
if path == "" {
return []string{}, nil
}
path, err := filepath.Abs(path)
if err != nil {
return nil, fmt.Errorf("failed to get abs path: %w", err)
}
fi, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("failed to get file stat: %w", err)
}
if !fi.IsDir() {
return []string{path}, nil
}
// Glob all files in the given path
files, err := filepath.Glob(filepath.Join(path, "*"))
if err != nil {
return nil, fmt.Errorf("failed to glob files: %w", err)
}
assets := make([]string, 0, len(files))
for _, f := range files {
// Exclude directory.
if fi, _ := os.Stat(f); fi.IsDir() {
continue
}
// Exclude hidden file
if filepath.Base(f)[0] == '.' {
continue
}
assets = append(assets, f)
}
return assets, nil
}