Skip to content

Commit 111922f

Browse files
committed
backend: empty slice should be '[]' not 'null' in json
* change slice initialiations to prevent nil slices
1 parent dfa1075 commit 111922f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

dir_entry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func ScanDirEntries(path string) (DirEntries, error) {
1515
return nil, err
1616
}
1717

18-
var dirEntries DirEntries
18+
dirEntries := DirEntries{}
1919
for _, fi := range files {
2020
_type := "F"
2121
if fi.IsDir() {

zfs_diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ScanZFSDiffs(zfsName, snapName string) (ZFSDiffs, error) {
2121
// see: https://www.illumos.org/issues/1912
2222
replacer := strings.NewReplacer("\\040", " ")
2323

24-
var diffs ZFSDiffs
24+
diffs := ZFSDiffs{}
2525
for _, line := range strings.Split(out, "\n") {
2626
//FIXME: filter only files, directories?
2727
//FIXME: type rename: '/' -> 'D' ...

zfs_snapshots.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func ScanZFSSnapshots(zfsName string) (ZFSSnapshots, error) {
1515
return nil, errors.New(out)
1616
}
1717

18-
var snapshots ZFSSnapshots
18+
snapshots := ZFSSnapshots{}
1919
for _, line := range strings.Split(string(out), "\n") {
2020
fields := strings.SplitN(line, "\t", 2)
2121
snap := ZFSSnapshot{lastElement(fields[0], "@"), fields[1]}
@@ -27,7 +27,7 @@ func ScanZFSSnapshots(zfsName string) (ZFSSnapshots, error) {
2727

2828
// Reverse reverse the snapshot list
2929
func (s ZFSSnapshots) Reverse() ZFSSnapshots {
30-
var reversed ZFSSnapshots
30+
reversed := ZFSSnapshots{}
3131
for i := len(s) - 1; i >= 0; i-- {
3232
reversed = append(reversed, s[i])
3333
}
@@ -36,7 +36,7 @@ func (s ZFSSnapshots) Reverse() ZFSSnapshots {
3636

3737
// Filter filters snapshots per given filter function
3838
func (s *ZFSSnapshots) Filter(f func(ZFSSnapshot) bool) ZFSSnapshots {
39-
var newS ZFSSnapshots
39+
newS := ZFSSnapshots{}
4040
for _, snap := range *s {
4141
if f(snap) {
4242
newS = append(newS, snap)

0 commit comments

Comments
 (0)