From eba6dfe27b5fbf64eea25b9b18d3f0166b5c8cd9 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Thu, 22 Aug 2024 08:38:58 +0200 Subject: [PATCH] api: remove deprecated methods --- api/main.go | 4 ++-- api/methods/auth.go | 5 ++--- api/methods/unit.go | 5 ++--- api/middleware/middleware.go | 7 +++---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/api/main.go b/api/main.go index 201f8c3..d93a4d2 100644 --- a/api/main.go +++ b/api/main.go @@ -10,7 +10,7 @@ package main import ( - "io/ioutil" + "io" "net/http" "github.com/fatih/structs" @@ -61,7 +61,7 @@ func main() { // disable log to stdout when running in release mode if gin.Mode() == gin.ReleaseMode { - gin.DefaultWriter = ioutil.Discard + gin.DefaultWriter = io.Discard } // init routers diff --git a/api/methods/auth.go b/api/methods/auth.go index 21b5edc..7f77d69 100644 --- a/api/methods/auth.go +++ b/api/methods/auth.go @@ -10,7 +10,6 @@ package methods import ( - "io/ioutil" "os" "strings" @@ -19,7 +18,7 @@ import ( func CheckTokenValidation(username string, token string) bool { // read whole file - secrestListB, err := ioutil.ReadFile(configuration.Config.TokensDir + "/" + username) + secrestListB, err := os.ReadFile(configuration.Config.TokensDir + "/" + username) if err != nil { return false } @@ -43,7 +42,7 @@ func SetTokenValidation(username string, token string) bool { func DelTokenValidation(username string, token string) bool { // read whole file - secrestListB, errR := ioutil.ReadFile(configuration.Config.TokensDir + "/" + username) + secrestListB, errR := os.ReadFile(configuration.Config.TokensDir + "/" + username) if errR != nil { return false } diff --git a/api/methods/unit.go b/api/methods/unit.go index 978cf82..1ff452a 100644 --- a/api/methods/unit.go +++ b/api/methods/unit.go @@ -13,7 +13,6 @@ import ( "bytes" "encoding/json" "errors" - "io/ioutil" "net/http" "os" "os/exec" @@ -399,7 +398,7 @@ func RegisterUnit(c *gin.Context) { // read credentials from file var credentials models.LoginRequest - jsonString, errRead := ioutil.ReadFile(configuration.Config.CredentialsDir + "/" + jsonRequest.UnitId) + jsonString, errRead := os.ReadFile(configuration.Config.CredentialsDir + "/" + jsonRequest.UnitId) // credentials exists, update only if username matches if errRead == nil { @@ -557,7 +556,7 @@ func getUnitToken(unitId string) (string, string, error) { // read credentials var credentials models.LoginRequest - body, err := ioutil.ReadFile(configuration.Config.CredentialsDir + "/" + unitId) + body, err := os.ReadFile(configuration.Config.CredentialsDir + "/" + unitId) if err != nil { return "", "", errors.New("cannot open credentials file for: " + unitId) } diff --git a/api/middleware/middleware.go b/api/middleware/middleware.go index 2bf76dd..394ff5b 100644 --- a/api/middleware/middleware.go +++ b/api/middleware/middleware.go @@ -13,7 +13,6 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "os" "strings" @@ -153,8 +152,8 @@ func InitJWT() *jwt.GinJWTMiddleware { // extract body var buf bytes.Buffer tee := io.TeeReader(c.Request.Body, &buf) - body, _ := ioutil.ReadAll(tee) - c.Request.Body = ioutil.NopCloser(&buf) + body, _ := io.ReadAll(tee) + c.Request.Body = io.NopCloser(&buf) // convert to map and flat it var jsonDyn map[string]interface{} @@ -162,7 +161,7 @@ func InitJWT() *jwt.GinJWTMiddleware { in, _ := flat.Flatten(jsonDyn, nil) // search for sensitve data, in sensitive list - for k, _ := range in { + for k := range in { for _, s := range configuration.Config.SensitiveList { if strings.Contains(strings.ToLower(k), strings.ToLower(s)) { in[k] = "XXX"