From 07a9f95aeb2d124bff2434f8535fe5c271bb7ed7 Mon Sep 17 00:00:00 2001 From: zy Date: Sun, 25 Apr 2021 00:29:40 +0800 Subject: [PATCH] fix: remove db twice * fix: remove db twice. * better for new error, use errors.New. * Error strings should not be capitalized or end with punctuation. https://github.com/golang/go/wiki/CodeReviewComments#error-strings --- cli.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli.go b/cli.go index 90acb42..56df135 100644 --- a/cli.go +++ b/cli.go @@ -2,6 +2,7 @@ package headscale import ( "encoding/json" + "errors" "fmt" "log" @@ -86,7 +87,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) @@ -104,8 +105,8 @@ 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") } func eqCIDRs(a, b []netaddr.IPPrefix) bool {