1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

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