fix gopls lintings

This commit is contained in:
dhax 2025-03-05 15:41:29 +01:00
parent a2e2ba39f9
commit dd2412463b
7 changed files with 19 additions and 25 deletions

View file

@ -2,6 +2,7 @@ package authorize
import (
"net/http"
"slices"
"github.com/go-chi/render"
@ -24,10 +25,5 @@ func RequiresRole(role string) func(next http.Handler) http.Handler {
}
func hasRole(role string, roles []string) bool {
for _, r := range roles {
if r == role {
return true
}
}
return false
return slices.Contains(roles, role)
}

View file

@ -20,7 +20,7 @@ type AppClaims struct {
}
// ParseClaims parses JWT claims into AppClaims.
func (c *AppClaims) ParseClaims(claims map[string]interface{}) error {
func (c *AppClaims) ParseClaims(claims map[string]any) error {
id, ok := claims["id"]
if !ok {
return errors.New("could not parse claim id")
@ -40,7 +40,7 @@ func (c *AppClaims) ParseClaims(claims map[string]interface{}) error {
var roles []string
if rl != nil {
for _, v := range rl.([]interface{}) {
for _, v := range rl.([]any) {
roles = append(roles, v.(string))
}
}
@ -57,7 +57,7 @@ type RefreshClaims struct {
}
// ParseClaims parses the JWT claims into RefreshClaims.
func (c *RefreshClaims) ParseClaims(claims map[string]interface{}) error {
func (c *RefreshClaims) ParseClaims(claims map[string]any) error {
token, ok := claims["token"]
if !ok {
return errors.New("could not parse claim token")

View file

@ -65,8 +65,8 @@ func (a *TokenAuth) CreateJWT(c AppClaims) (string, error) {
return tokenString, err
}
func ParseStructToMap(c interface{}) (map[string]interface{}, error) {
var claims map[string]interface{}
func ParseStructToMap(c any) (map[string]any, error) {
var claims map[string]any
inrec, _ := json.Marshal(c)
err := json.Unmarshal(inrec, &claims)
if err != nil {

View file

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -349,7 +348,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
return nil, ""
@ -372,7 +371,7 @@ func genRefreshJWT(c jwt.RefreshClaims) string {
return tokenString
}
func encode(v interface{}) (*bytes.Buffer, error) {
func encode(v any) (*bytes.Buffer, error) {
data := new(bytes.Buffer)
err := json.NewEncoder(data).Encode(v)
return data, err