modernize the codebase

Run the modernize linter across the codebase.
Change generated by running:

```
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
```

Ref:
https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
This commit is contained in:
2025-09-23 09:13:29 +03:30
parent fc1502c4a0
commit 94694741a7
5 changed files with 33 additions and 38 deletions

View File

@@ -129,6 +129,6 @@ func NewFXLogger() *FXLogger {
return &FXLogger{logger: logger}
}
func (l *FXLogger) Printf(str string, args ...interface{}) {
func (l *FXLogger) Printf(str string, args ...any) {
l.logger.Sugar().Infof(str, args...)
}

View File

@@ -2,6 +2,7 @@ package auth
import (
"CatsOfMastodonBotGo/internal/config"
"maps"
"strings"
"time"
@@ -17,16 +18,14 @@ func NewJwtTokenGenerator(cfg *config.Config) *JwtTokenGenerator {
return &JwtTokenGenerator{cfg: cfg}
}
func (j *JwtTokenGenerator) GenerateToken(claims map[string]interface{}) (string, error) {
func (j *JwtTokenGenerator) GenerateToken(claims map[string]any) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"exp": time.Now().AddDate(0, 0, 1).Unix(),
"iat": time.Now().Unix(),
"iss": j.cfg.JwtIssuer,
"aud": j.cfg.JwtAudience,
})
for k, v := range claims {
token.Claims.(jwt.MapClaims)[k] = v
}
maps.Copy(token.Claims.(jwt.MapClaims), claims)
return token.SignedString([]byte(j.cfg.JwtSecret))
}
@@ -41,7 +40,7 @@ func (j *JwtTokenGenerator) GinMiddleware() gin.HandlerFunc {
}
tokenString := strings.TrimPrefix(authHeader, "Bearer ")
t, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {
t, err := jwt.Parse(tokenString, func(t *jwt.Token) (any, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, jwt.ErrSignatureInvalid
}

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"math/rand"
"net/http"
"slices"
"strings"
"gorm.io/gorm"
@@ -163,10 +164,5 @@ func (ps *PostService) GetMedia() domain.MediaAttachment {
}
func arrayContains(arr []string, str string) bool {
for _, a := range arr {
if a == str {
return true
}
}
return false
return slices.Contains(arr, str)
}

View File

@@ -77,7 +77,7 @@ func (adh *AdminDashboardHandler) Login(c *gin.Context) {
}
if input.Password == adh.cfg.AdminPassword { // Its more than enough for this project
token, err := adh.jwt.GenerateToken(map[string]interface{}{"role": "admin"})
token, err := adh.jwt.GenerateToken(map[string]any{"role": "admin"})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token generation failed"})
return

View File

@@ -55,7 +55,7 @@ func (olh *OauthLoginHandler) LoginWithGitea(c *gin.Context) {
// Check if the user's email is in the allowed list
for _, email := range olh.cfg.GiteaOauthAllowedEmails {
if email == userEmail {
token, err := olh.jwt.GenerateToken(map[string]interface{}{"role": "admin"})
token, err := olh.jwt.GenerateToken(map[string]any{"role": "admin"})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token generation failed"})
return