Skip to content

Commit 695c8cc

Browse files
committed
metrics: create new SMBStatus via helper func
Use convenience helper function with all-empty fields by default. In particular, internal maps. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 1caf02d commit 695c8cc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

internal/metrics/smbstatus.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ func executeCommand(command string, arg ...string) (string, error) {
205205
// parseSMBStatus parses to output of 'smbstatus --json' into internal
206206
// representation.
207207
func parseSMBStatus(data string) (*SMBStatus, error) {
208-
res := SMBStatus{}
209-
err := json.Unmarshal([]byte(data), &res)
210-
return &res, err
208+
res := NewSMBStatus()
209+
err := json.Unmarshal([]byte(data), res)
210+
return res, err
211211
}
212212

213213
// parseSMBStatusLocks parses to output of 'smbstatus --locks --json' into
@@ -217,3 +217,16 @@ func parseSMBStatusLocks(data string) (*SMBStatusLocks, error) {
217217
err := json.Unmarshal([]byte(data), &res)
218218
return &res, err
219219
}
220+
221+
// NewSMBStatus returns non-populated SMBStatus object
222+
func NewSMBStatus() *SMBStatus {
223+
smbStatus := SMBStatus{
224+
Timestamp: "",
225+
Version: "",
226+
SmbConf: "",
227+
Sessions: map[string]SMBStatusSession{},
228+
TCons: map[string]SMBStatusTreeCon{},
229+
LockedFiles: map[string]SMBStatusLockedFile{},
230+
}
231+
return &smbStatus
232+
}

0 commit comments

Comments
 (0)