moving defer to when error check has passed

go-staticcheck: should check returned error before deferring commandAllowListFile.Close() (SA5001)
This commit is contained in:
Tobias Lindberg
2021-05-19 19:53:54 +02:00
parent a9feeee228
commit 7baecf3a61
+1 -1
View File
@@ -140,10 +140,10 @@ func initCommandAllowList() {
if len(allowList) == 0 {
var allowListFile []string
commandAllowListFile, err := os.Open(commandAllowListLocation)
defer commandAllowListFile.Close()
if err != nil {
log.Println("[error] getAllowList error with COMMANDS_ALLOWLIST: " + commandAllowListLocation + " not found and will be ignored")
} else {
defer commandAllowListFile.Close()
byteValue, err := ioutil.ReadAll(commandAllowListFile)
if err != nil {
log.Println("[error] getAllowList error while reading COMMANDS_ALLOWLIST: " + commandAllowListLocation + " it will be ignored")