From 563f3c4017720b9cc35f5c10711fe8fcaaf3f7b5 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 21 Feb 2021 23:54:15 +0100 Subject: [PATCH] Fixes here and there --- app.go | 4 ++-- handlers.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index c8f310e6..d83254ac 100644 --- a/app.go +++ b/app.go @@ -2,8 +2,8 @@ package headscale import ( "fmt" - "io/ioutil" "log" + "os" "github.com/gin-gonic/gin" "tailscale.com/tailcfg" @@ -34,7 +34,7 @@ type Headscale struct { // NewHeadscale returns the Headscale app func NewHeadscale(cfg Config) (*Headscale, error) { - content, err := ioutil.ReadFile(cfg.PrivateKeyPath) + content, err := os.ReadFile(cfg.PrivateKeyPath) if err != nil { return nil, err } diff --git a/handlers.go b/handlers.go index 80217b55..7fd70042 100644 --- a/handlers.go +++ b/handlers.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "time" @@ -24,7 +23,7 @@ func (h *Headscale) KeyHandler(c *gin.Context) { } func (h *Headscale) RegistrationHandler(c *gin.Context) { - body, _ := ioutil.ReadAll(c.Request.Body) + body, _ := io.ReadAll(c.Request.Body) mKeyStr := c.Param("id") mKey, err := wgcfg.ParseHexKey(mKeyStr) if err != nil { @@ -104,7 +103,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) { } func (h *Headscale) PollNetMapHandler(c *gin.Context) { - body, _ := ioutil.ReadAll(c.Request.Body) + body, _ := io.ReadAll(c.Request.Body) mKeyStr := c.Param("id") mKey, err := wgcfg.ParseHexKey(mKeyStr) if err != nil { @@ -126,6 +125,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) { c.String(http.StatusInternalServerError, ":(") return } + defer db.Close() var m Machine if db.First(&m, "machine_key = ?", mKey.HexString()).RecordNotFound() { log.Printf("Cannot encode message: %s", err)