Merge pull request #11 from xpzouying/zy/fix-remove-dup-close-db

fix: remove db twice
This commit is contained in:
Juan Font 2021-04-25 00:35:46 +02:00 committed by GitHub
commit 6fa84004b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

5
cli.go
View file

@ -2,6 +2,7 @@ package headscale
import (
"encoding/json"
"errors"
"fmt"
"log"
@ -90,7 +91,7 @@ func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr
log.Printf("Cannot open DB: %s", err)
return err
}
defer db.Close()
routes, _ := json.Marshal([]string{routeStr}) // TODO: only one for the time being, so overwriting the rest
m.EnabledRoutes = postgres.Jsonb{RawMessage: json.RawMessage(routes)}
db.Save(&m)
@ -107,6 +108,6 @@ func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr
return nil
}
}
return fmt.Errorf("Could not find routable range")
return errors.New("could not find routable range")
}