Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactor: replace interface{} with any

goenningdeb4f9b4f561
diff --git a/app/handlers/common.go b/app/handlers/common.go
index 13edc2b7b..dafcc33cf 100644
--- a/app/handlers/common.go
+++ b/app/handlers/common.go
@@ -105,8 +105,8 @@ func Page(title, description, page string) web.HandlerFunc {
//NewLogError is the input model for UI errors
type NewLogError struct {
- Message string `json:"message"`
- Data interface{} `json:"data"`
+ Message string `json:"message"`
+ Data any `json:"data"`
}
//LogError logs an error coming from the UI
diff --git a/app/models/dto/props.go b/app/models/dto/props.go
index 5a95b3472..864ed7b2a 100644
--- a/app/models/dto/props.go
+++ b/app/models/dto/props.go
@@ -6,7 +6,7 @@ import (
)
// Props is a map of key:value
-type Props map[string]interface{}
+type Props map[string]any
// Value converts props into a database value
func (p Props) Value() (driver.Value, error) {
diff --git a/app/models/entity/oauth.go b/app/models/entity/oauth.go
index 250183de4..3d8d695f8 100644
--- a/app/models/entity/oauth.go
+++ b/app/models/entity/oauth.go
@@ -27,7 +27,7 @@ func (o OAuthConfig) MarshalJSON() ([]byte, error) {
if len(o.ClientSecret) >= 10 {
secret = o.ClientSecret[0:3] + "..." + o.ClientSecret[len(o.ClientSecret)-3:]
}
- return json.Marshal(map[string]interface{}{
+ return json.Marshal(map[string]any{
"id": o.ID,
"provider": o.Provider,
"displayName": o.DisplayName,
diff --git a/app/models/entity/webhook.go b/app/models/entity/webhook.go
index 64a0fc6ba..0cca2f45e 100644
--- a/app/models/entity/webhook.go
+++ b/app/models/entity/webhook.go
@@ -3,6 +3,7 @@ package entity
import (
"database/sql/driver"
"encoding/json"
+
"github.com/getfider/fider/app/models/enum"
"github.com/getfider/fider/app/pkg/errors"
)
@@ -25,7 +26,7 @@ func (h HttpHeaders) Value() (driver.Value, error) {
return json.Marshal(h)
}
-func (h *HttpHeaders) Scan(src interface{}) error {
+func (h *HttpHeaders) Scan(src any) error {
if src == nil {
return nil
}
diff --git a/app/pkg/assert/assert.go b/app/pkg/assert/assert.go
index fe5649818..9c77bf841 100644
--- a/app/pkg/assert/assert.go
+++ b/app/pkg/assert/assert.go
@@ -3,25 +3,26 @@ package assert
import (
"context"
"fmt"
- "github.com/getfider/fider/app/models/dto"
"os"
"reflect"
"strings"
"testing"
"time"
+ "github.com/getfider/fider/app/models/dto"
+
"github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/errors"
)
-func mustBeFunction(v interface{}) {
+func mustBeFunction(v any) {
if reflect.TypeOf(v).Kind() != reflect.Func {
panic("Value is not a function")
}
}
-func describe(v interface{}) string {
+func describe(v any) string {
value := reflect.ValueOf(v)
if v == nil {
@@ -40,7 +41,7 @@ func describeProps(props dto.Props) string {
}
//Fail the current test case with given message
-func Fail(msg string, args ...interface{}) {
+func Fail(msg string, args ...any) {
if currentT == nil {
panic("Did you forget to call RegisterT(t)?")
}
@@ -78,11 +79,11 @@ func restartEnv() {
//AnyAssertions is used to assert any kind of value
type AnyAssertions struct {
- actual interface{}
+ actual any
}
//Expect starts new assertions on given value
-func Expect(actual interface{}) *AnyAssertions {
+func Expect(actual any) *AnyAssertions {
if currentT == nil {
panic("Did you forget to call RegisterT(t)?")
}
@@ -92,7 +93,7 @@ func Expect(actual interface{}) *AnyAssertions {
}
//Equals asserts that actual value equals expected value
-func (a *AnyAssertions) Equals(expected interface{}) bool {
+func (a *AnyAssertions) Equals(expected any) bool {
if reflect.DeepEqual(expected, a.actual) {
return true
}
@@ -112,7 +113,7 @@ func (a *AnyAssertions) ContainsSubstring(substr string) bool {
}
//NotEquals asserts that actual value is different than given value
-func (a *AnyAssertions) NotEquals(other interface{}) bool {
+func (a *AnyAssertions) NotEquals(other any) bool {
if !reflect.DeepEqual(other, a.actual) {
return true
}
@@ -189,7 +190,7 @@ func (a *AnyAssertions) Panics() (panicked bool) {
}
//EventuallyEquals asserts that, within 30 seconds, the actual function will return same value as expected value
-func (a *AnyAssertions) EventuallyEquals(expected interface{}) bool {
+func (a *AnyAssertions) EventuallyEquals(expected any) bool {
mustBeFunction(a.actual)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
@@ -229,7 +230,7 @@ func (a *AnyAssertions) TemporarilySimilar(other time.Time, diff time.Duration)
return false
}
-func (a AnyAssertions) ContainsProps(props map[string]interface{}) bool {
+func (a AnyAssertions) ContainsProps(props map[string]any) bool {
actualValue := reflect.ValueOf(a.actual)
actualType := actualValue.Type()
if actualType.Kind() != reflect.Map ||
@@ -238,7 +239,7 @@ func (a AnyAssertions) ContainsProps(props map[string]interface{}) bool {
panic("Value is not a Props")
}
- actualProps := reflect.ValueOf(a.actual).Convert(reflect.TypeOf(map[string]interface{}{})).Interface().(map[string]interface{})
+ actualProps := reflect.ValueOf(a.actual).Convert(reflect.TypeOf(map[string]any{})).Interface().(map[string]any)
for key, expected := range props {
actual, ok := actualProps[key]
if !ok {
diff --git a/app/pkg/backup/export.go b/app/pkg/backup/export.go
index 58dd995a4..2bed001fe 100644
--- a/app/pkg/backup/export.go
+++ b/app/pkg/backup/export.go
@@ -28,19 +28,19 @@ func exportTable(ctx context.Context, tableName string) ([]byte, error) {
return json.Marshal(jsonify(rows))
}
-func jsonify(rows *sql.Rows) []map[string]interface{} {
+func jsonify(rows *sql.Rows) []map[string]any {
defer rows.Close()
columns, err := rows.Columns()
if err != nil {
panic(err.Error())
}
- allResults := make([]map[string]interface{}, 0)
+ allResults := make([]map[string]any, 0)
for rows.Next() {
- results := make(map[string]interface{})
- values := make([]interface{}, len(columns))
- scanArgs := make([]interface{}, len(values))
+ results := make(map[string]any)
+ values := make([]any, len(columns))
+ scanArgs := make([]any, len(values))
for i := range values {
scanArgs[i] = &values[i]
}
diff --git a/app/pkg/bus/bus.go b/app/pkg/bus/bus.go
index eae81b458..4d87f08f3 100644
--- a/app/pkg/bus/bus.go
+++ b/app/pkg/bus/bus.go
@@ -11,8 +11,8 @@ import (
"github.com/getfider/fider/app/pkg/errors"
)
-type HandlerFunc interface{}
-type Msg interface{}
+type HandlerFunc any
+type Msg any
type Service interface {
Name() string
diff --git a/app/pkg/color/color.go b/app/pkg/color/color.go
index 073771013..b35633f35 100644
--- a/app/pkg/color/color.go
+++ b/app/pkg/color/color.go
@@ -17,7 +17,7 @@ var (
)
// FromName return content with given color name
-func FromName(colorName string, content interface{}) string {
+func FromName(colorName string, content any) string {
switch strings.ToUpper(colorName) {
case "RED":
return Red(content)
@@ -39,36 +39,36 @@ func FromName(colorName string, content interface{}) string {
}
// Red return content with red color
-func Red(content interface{}) string {
+func Red(content any) string {
return fmt.Sprintf("%s%v%s", colorRed, content, resetAll)
}
// Green return content with green color
-func Green(content interface{}) string {
+func Green(content any) string {
return fmt.Sprintf("%s%v%s", colorGreen, content, resetAll)
}
// Yellow return content with yellow color
-func Yellow(content interface{}) string {
+func Yellow(content any) string {
return fmt.Sprintf("%s%v%s", colorYellow, content, resetAll)
}
// Blue return content with blue color
-func Blue(content interface{}) string {
+func Blue(content any) string {
return fmt.Sprintf("%s%v%s", colorBlue, content, resetAll)
}
// Magenta return content with magenta color
-func Magenta(content interface{}) string {
+func Magenta(content any) string {
return fmt.Sprintf("%s%v%s", colorMagenta, content, resetAll)
}
// Bold return content with bold text
-func Bold(content interface{}) string {
+func Bold(content any) string {
return fmt.Sprintf("%s%v%s", styleBold, content, resetAll)
}
// Reverse return content with reverse colors
-func Reverse(content interface{}) string {
+func Reverse(content any) string {
return fmt.Sprintf("%s%v%s", styleReverse, content, resetAll)
}
diff --git a/app/pkg/dbx/dbx.go b/app/pkg/dbx/dbx.go
index db8ecd183..1b21f95d4 100644
--- a/app/pkg/dbx/dbx.go
+++ b/app/pkg/dbx/dbx.go
@@ -80,7 +80,7 @@ type Trx struct {
var formatter = strings.NewReplacer("\t", "", "\n", " ")
// Execute given SQL command
-func (trx *Trx) Execute(command string, args ...interface{}) (int64, error) {
+func (trx *Trx) Execute(command string, args ...any) (int64, error) {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -103,7 +103,7 @@ func (trx *Trx) Execute(command string, args ...interface{}) (int64, error) {
}
// Scalar returns first row and first column
-func (trx *Trx) Scalar(data interface{}, command string, args ...interface{}) error {
+func (trx *Trx) Scalar(data any, command string, args ...any) error {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -128,7 +128,7 @@ func (trx *Trx) Scalar(data interface{}, command string, args ...interface{}) er
}
// Get first row and bind to given data
-func (trx *Trx) Get(data interface{}, command string, args ...interface{}) error {
+func (trx *Trx) Get(data any, command string, args ...any) error {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -160,7 +160,7 @@ func (trx *Trx) Get(data interface{}, command string, args ...interface{}) error
}
// Exists returns true if at least one record is found
-func (trx *Trx) Exists(command string, args ...interface{}) (bool, error) {
+func (trx *Trx) Exists(command string, args ...any) (bool, error) {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -183,7 +183,7 @@ func (trx *Trx) Exists(command string, args ...interface{}) (bool, error) {
}
// Count returns number of rows
-func (trx *Trx) Count(command string, args ...interface{}) (int, error) {
+func (trx *Trx) Count(command string, args ...any) (int, error) {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -210,7 +210,7 @@ func (trx *Trx) Count(command string, args ...interface{}) (int, error) {
}
//Select all matched rows bind to given data
-func (trx *Trx) Select(data interface{}, command string, args ...interface{}) error {
+func (trx *Trx) Select(data any, command string, args ...any) error {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -251,7 +251,7 @@ func (trx *Trx) Select(data interface{}, command string, args ...interface{}) er
}
//Query all matched rows and return raw sql.Rows
-func (trx *Trx) Query(command string, args ...interface{}) (*sql.Rows, error) {
+func (trx *Trx) Query(command string, args ...any) (*sql.Rows, error) {
if log.IsEnabled(log.DEBUG) {
command = formatter.Replace(command)
start := time.Now()
@@ -310,7 +310,7 @@ func (trx *Trx) MustRollback() {
}
}
-func wrap(err error, format string, a ...interface{}) error {
+func wrap(err error, format string, a ...any) error {
if pqErr, ok := err.(*pq.Error); ok {
if pqErr.Code == "57014" { //query canceled
return errors.Wrap(context.Canceled, format, a...)
diff --git a/app/pkg/dbx/mapping.go b/app/pkg/dbx/mapping.go
index 88e261428..be484bd8b 100644
--- a/app/pkg/dbx/mapping.go
+++ b/app/pkg/dbx/mapping.go
@@ -22,7 +22,7 @@ func NewRowMapper() *RowMapper {
}
//Map values from scanner (usually sql.Rows.Scan) into dest based on columns
-func (m *RowMapper) Map(dest interface{}, columns []string, scanner func(dest ...interface{}) error) error {
+func (m *RowMapper) Map(dest any, columns []string, scanner func(dest ...any) error) error {
t := reflect.TypeOf(dest)
if t.Kind() == reflect.Ptr {
t = t.Elem()
@@ -44,7 +44,7 @@ func (m *RowMapper) Map(dest interface{}, columns []string, scanner func(dest ..
m.Unlock()
}
- pointers := make([]interface{}, len(columns))
+ pointers := make([]any, len(columns))
for i, c := range columns {
mapping := typeMapper.Fields[c]
field := reflect.ValueOf(dest).Elem()
diff --git a/app/pkg/dbx/mapping_test.go b/app/pkg/dbx/mapping_test.go
index e9d6805a9..b6072b4a6 100644
--- a/app/pkg/dbx/mapping_test.go
+++ b/app/pkg/dbx/mapping_test.go
@@ -9,8 +9,8 @@ import (
"github.com/getfider/fider/app/pkg/dbx"
)
-func createScanner(values ...interface{}) func(dest ...interface{}) error {
- return func(dest ...interface{}) error {
+func createScanner(values ...any) func(dest ...any) error {
+ return func(dest ...any) error {
for i := 0; i < len(values); i++ {
reflect.Indirect(reflect.ValueOf(dest[i])).Set(reflect.ValueOf(values[i]))
}
diff --git a/app/pkg/errors/errors.go b/app/pkg/errors/errors.go
index 8795626a2..4da66fe10 100644
--- a/app/pkg/errors/errors.go
+++ b/app/pkg/errors/errors.go
@@ -19,19 +19,19 @@ func caller(skip int) (string, int) {
}
//New creates a new error
-func New(format string, a ...interface{}) error {
+func New(format string, a ...any) error {
file, line := caller(2)
text := fmt.Sprintf(format, a...)
return fmt.Errorf("%s (%s:%d)", text, file, line)
}
//Wrap existing error with additional text
-func Wrap(err error, format string, a ...interface{}) error {
+func Wrap(err error, format string, a ...any) error {
return wrap(err, 0, format, a...)
}
//Panicked wraps panick errow with extra details of error
-func Panicked(r interface{}) error {
+func Panicked(r any) error {
err, ok := r.(error)
if !ok {
err = fmt.Errorf("%v", r)
@@ -50,7 +50,7 @@ func StackN(err error, skip int) error {
return wrap(err, skip, "")
}
-func wrap(err error, skip int, format string, a ...interface{}) error {
+func wrap(err error, skip int, format string, a ...any) error {
if err == nil {
return err
}
diff --git a/app/pkg/i18n/i18n.go b/app/pkg/i18n/i18n.go
index fbfbaea7a..3d4f06632 100644
--- a/app/pkg/i18n/i18n.go
+++ b/app/pkg/i18n/i18n.go
@@ -28,7 +28,7 @@ var localeToPlurals = map[string]string{
"tr": "tr",
}
-type Params map[string]interface{}
+type Params map[string]any
// cache for locale parser and file content to prevent excessive disk IO
var cache = make(map[string]localeData)
diff --git a/app/pkg/jsonq/jsonq.go b/app/pkg/jsonq/jsonq.go
index 8a738f78e..16812b518 100644
--- a/app/pkg/jsonq/jsonq.go
+++ b/app/pkg/jsonq/jsonq.go
@@ -71,7 +71,7 @@ func (q *Query) IsArray() bool {
//ArrayLength returns number of elements in the array
func (q *Query) ArrayLength() int {
if q.IsArray() {
- var arr []interface{}
+ var arr []any
err := json.Unmarshal([]byte(q.json), &arr)
if err != nil {
panic(err)
diff --git a/app/pkg/jwt/jwt.go b/app/pkg/jwt/jwt.go
index 812ef84e8..8ba5f1126 100644
--- a/app/pkg/jwt/jwt.go
+++ b/app/pkg/jwt/jwt.go
@@ -74,7 +74,7 @@ func DecodeOAuthClaims(token string) (*OAuthClaims, error) {
}
func decode(token string, claims jwtgo.Claims) error {
- jwtToken, err := jwtgo.ParseWithClaims(token, claims, func(t *jwtgo.Token) (interface{}, error) {
+ jwtToken, err := jwtgo.ParseWithClaims(token, claims, func(t *jwtgo.Token) (any, error) {
if _, ok := t.Method.(*jwtgo.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", t.Header["alg"])
}
diff --git a/app/pkg/log/props.go b/app/pkg/log/props.go
index 5d10dc4a6..5d407f866 100644
--- a/app/pkg/log/props.go
+++ b/app/pkg/log/props.go
@@ -28,12 +28,12 @@ func GetProperties(ctx context.Context) dto.Props {
return dto.Props{}
}
-func GetProperty(ctx context.Context, key string) interface{} {
+func GetProperty(ctx context.Context, key string) any {
props := GetProperties(ctx)
return props[key]
}
-func WithProperty(ctx context.Context, key string, value interface{}) context.Context {
+func WithProperty(ctx context.Context, key string, value any) context.Context {
return WithProperties(ctx, dto.Props{
key: value,
})
diff --git a/app/pkg/mock/server.go b/app/pkg/mock/server.go
index eb2cbfb45..4ca3bc04e 100644
--- a/app/pkg/mock/server.go
+++ b/app/pkg/mock/server.go
@@ -78,7 +78,7 @@ func (s *Server) AsUser(user *entity.User) *Server {
}
// AddParam to current context route parameters
-func (s *Server) AddParam(name string, value interface{}) *Server {
+func (s *Server) AddParam(name string, value any) *Server {
s.context.AddParam(name, fmt.Sprintf("%v", value))
return s
}
@@ -150,7 +150,7 @@ func (s *Server) ExecuteAsPage(handler web.HandlerFunc) (int, *web.Props) {
endIndex := strings.Index(bodyString[startIndex:], endTag)
serverData := strings.TrimSpace(bodyString[startIndex : startIndex+endIndex])
- serverDataJSON := map[string]interface{}{}
+ serverDataJSON := map[string]any{}
err := json.Unmarshal([]byte(serverData), &serverDataJSON)
if err != nil {
@@ -160,7 +160,7 @@ func (s *Server) ExecuteAsPage(handler web.HandlerFunc) (int, *web.Props) {
title, _ := serverDataJSON["title"].(string)
description, _ := serverDataJSON["description"].(string)
page, _ := serverDataJSON["page"].(string)
- props, _ := serverDataJSON["props"].(map[string]interface{})
+ props, _ := serverDataJSON["props"].(map[string]any)
return code, &web.Props{
Title: title,
diff --git a/app/pkg/tpl/funcs.go b/app/pkg/tpl/funcs.go
index 56f488e23..e95eb93bc 100644
--- a/app/pkg/tpl/funcs.go
+++ b/app/pkg/tpl/funcs.go
@@ -16,7 +16,7 @@ import (
var strictHtmlPolicy = bluemonday.NewPolicy()
-var templateFunctions = map[string]interface{}{
+var templateFunctions = map[string]any{
"stripHtml": func(input string) string {
return strictHtmlPolicy.Sanitize(input)
},
@@ -38,12 +38,12 @@ var templateFunctions = map[string]interface{}{
"markdown": func(input string) template.HTML {
return markdown.Full(input)
},
- "dict": func(values ...interface{}) map[string]interface{} {
+ "dict": func(values ...any) map[string]any {
if len(values)%2 != 0 {
panic(errors.New("invalid dictionary call"))
}
- dict := make(map[string]interface{})
+ dict := make(map[string]any)
for i := 0; i < len(values); i += 2 {
var key string
switch v := values[i].(type) {
@@ -59,10 +59,10 @@ var templateFunctions = map[string]interface{}{
"format": func(format string, date time.Time) string {
return date.Format(format)
},
- "quote": func(text interface{}) string {
+ "quote": func(text any) string {
return quote(text)
},
- "escape": func(text interface{}) string {
+ "escape": func(text any) string {
quoted := quote(text)
return quoted[1 : len(quoted)-1]
},
@@ -74,6 +74,6 @@ var templateFunctions = map[string]interface{}{
},
}
-func quote(text interface{}) string {
+func quote(text any) string {
return strconv.Quote(fmt.Sprintf("%v", text))
}
diff --git a/app/pkg/tpl/template.go b/app/pkg/tpl/template.go
index 813b76d7a..ffddaacf0 100644
--- a/app/pkg/tpl/template.go
+++ b/app/pkg/tpl/template.go
@@ -30,7 +30,7 @@ func GetTemplate(baseFileName, templateFileName string) *template.Template {
return tpl
}
-func Render(ctx context.Context, tmpl *template.Template, w io.Writer, data interface{}) error {
+func Render(ctx context.Context, tmpl *template.Template, w io.Writer, data any) error {
if err := template.Must(tmpl.Clone()).Funcs(template.FuncMap{
"translate": func(key string, params ...i18n.Params) string {
return i18n.T(ctx, key, params...)
diff --git a/app/pkg/tpl/text.go b/app/pkg/tpl/text.go
index 51a51ca2c..864e2ce52 100644
--- a/app/pkg/tpl/text.go
+++ b/app/pkg/tpl/text.go
@@ -1,9 +1,10 @@
package tpl
import (
- "github.com/getfider/fider/app/pkg/markdown"
"strings"
"text/template"
+
+ "github.com/getfider/fider/app/pkg/markdown"
)
func GetTextTemplate(name string, rawText string) (*template.Template, error) {
@@ -19,7 +20,7 @@ func GetTextTemplate(name string, rawText string) (*template.Template, error) {
return tpl, nil
}
-func Execute(tmpl *template.Template, data interface{}) (string, error) {
+func Execute(tmpl *template.Template, data any) (string, error) {
builder := &strings.Builder{}
if err := tmpl.Execute(builder, data); err != nil {
return "", err
diff --git a/app/pkg/web/binder.go b/app/pkg/web/binder.go
index 19e0a44b8..ba667bbde 100644
--- a/app/pkg/web/binder.go
+++ b/app/pkg/web/binder.go
@@ -30,7 +30,7 @@ func methodHasBody(method string) bool {
}
//Bind request data to object i
-func (b *DefaultBinder) Bind(target interface{}, c *Context) error {
+func (b *DefaultBinder) Bind(target any, c *Context) error {
if methodHasBody(c.Request.Method) && c.Request.ContentLength > 0 {
contentType := strings.Split(c.Request.GetHeader("Content-Type"), ";")
if len(contentType) == 0 || contentType[0] != JSONContentType {
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index 1f3d94efd..d60f8e46b 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -28,8 +28,8 @@ import (
"github.com/getfider/fider/app/services/blob"
)
-// Map defines a generic map of type `map[string]interface{}`
-type Map map[string]interface{}
+// Map defines a generic map of type `map[string]any`
+type Map map[string]any
// StringMap defines a map of type `map[string]string`
type StringMap map[string]string
@@ -169,7 +169,7 @@ func (c *Context) SetTenant(tenant *entity.Tenant) {
}
//Bind context values into given model
-func (c *Context) Bind(i interface{}) error {
+func (c *Context) Bind(i any) error {
err := c.engine.binder.Bind(i, c)
if err != nil {
return errors.Wrap(err, "failed to bind request to model")
@@ -306,7 +306,7 @@ func (c *Context) Attachment(fileName, contentType string, file []byte) error {
}
//Ok returns 200 OK with JSON result
-func (c *Context) Ok(data interface{}) error {
+func (c *Context) Ok(data any) error {
return c.JSON(http.StatusOK, data)
}
@@ -433,7 +433,7 @@ func (c *Context) GetMatchedRoutePath() string {
}
// Set saves data in the context.
-func (c *Context) Set(key interface{}, val interface{}) {
+func (c *Context) Set(key any, val any) {
c.Context = context.WithValue(c.Context, key, val)
}
@@ -448,7 +448,7 @@ func (c *Context) XML(code int, text string) error {
}
// JSON returns a JSON response with status code.
-func (c *Context) JSON(code int, i interface{}) error {
+func (c *Context) JSON(code int, i any) error {
b, err := json.Marshal(i)
if err != nil {
return errors.Wrap(err, "failed to marshal response to JSON")
@@ -550,7 +550,7 @@ func TenantBaseURL(ctx context.Context, tenant *entity.Tenant) string {
}
// AssetsURL return the full URL to a tenant-specific static asset
-func AssetsURL(ctx context.Context, path string, a ...interface{}) string {
+func AssetsURL(ctx context.Context, path string, a ...any) string {
request := ctx.Value(app.RequestCtxKey).(Request)
path = fmt.Sprintf(path, a...)
diff --git a/app/pkg/web/react.go b/app/pkg/web/react.go
index 0be8514be..d4ac11176 100644
--- a/app/pkg/web/react.go
+++ b/app/pkg/web/react.go
@@ -21,7 +21,7 @@ type ReactRenderer struct {
func newIsolatePool() *sync.Pool {
return &sync.Pool{
- New: func() interface{} {
+ New: func() any {
isolate := v8go.NewIsolate()
runtime.SetFinalizer(isolate, func(iso *v8go.Isolate) {
diff --git a/app/pkg/webhook/props.go b/app/pkg/webhook/props.go
index 580ce10a9..7c2083a05 100644
--- a/app/pkg/webhook/props.go
+++ b/app/pkg/webhook/props.go
@@ -6,7 +6,7 @@ import (
)
// Props is a map of key:value
-type Props map[string]interface{}
+type Props map[string]any
// SetUser describe the user prefixed by "keyPrefix"
func (p Props) SetUser(user *entity.User, keyPrefix string) Props {
diff --git a/app/pkg/worker/context.go b/app/pkg/worker/context.go
index 98a17ffc2..9746dd5e6 100644
--- a/app/pkg/worker/context.go
+++ b/app/pkg/worker/context.go
@@ -53,7 +53,7 @@ func (c *Context) TaskName() string {
}
// Set saves data in the context.
-func (c *Context) Set(key interface{}, val interface{}) {
+func (c *Context) Set(key any, val any) {
c.Context = context.WithValue(c.Context, key, val)
}
diff --git a/app/services/blob/s3/s3.go b/app/services/blob/s3/s3.go
index 48d5ed24c..20988497c 100644
--- a/app/services/blob/s3/s3.go
+++ b/app/services/blob/s3/s3.go
@@ -183,7 +183,7 @@ func isNotFound(err error) bool {
return false
}
-func wrap(err error, format string, a ...interface{}) error {
+func wrap(err error, format string, a ...any) error {
if awsErr, ok := err.(awserr.Error); ok {
return errors.Wrap(awsErr.OrigErr(), format, a...)
}
diff --git a/app/services/log/console/console.go b/app/services/log/console/console.go
index 18af2770a..c2991f27d 100644
--- a/app/services/log/console/console.go
+++ b/app/services/log/console/console.go
@@ -86,7 +86,7 @@ func writeLog(ctx context.Context, level log.Level, message string, props dto.Pr
}
func colorizeLevel(level log.Level) string {
- var colorFunc func(interface{}) string
+ var colorFunc func(any) string
switch level {
case log.DEBUG:
diff --git a/app/services/sqlstore/postgres/post.go b/app/services/sqlstore/postgres/post.go
index 57ef850f8..c1c49cd54 100644
--- a/app/services/sqlstore/postgres/post.go
+++ b/app/services/sqlstore/postgres/post.go
@@ -427,7 +427,7 @@ func getAllPosts(ctx context.Context, q *query.GetAllPosts) error {
})
}
-func querySinglePost(ctx context.Context, trx *dbx.Trx, query string, args ...interface{}) (*entity.Post, error) {
+func querySinglePost(ctx context.Context, trx *dbx.Trx, query string, args ...any) (*entity.Post, error) {
post := dbPost{}
if err := trx.Get(&post, query, args...); err != nil {
diff --git a/app/services/sqlstore/postgres/tag.go b/app/services/sqlstore/postgres/tag.go
index b5140f8f5..aaab85c7b 100644
--- a/app/services/sqlstore/postgres/tag.go
+++ b/app/services/sqlstore/postgres/tag.go
@@ -186,7 +186,7 @@ func queryTagBySlug(trx *dbx.Trx, tenant *entity.Tenant, slug string) (*entity.T
return tag.toModel(), nil
}
-func queryTags(trx *dbx.Trx, query string, args ...interface{}) ([]*entity.Tag, error) {
+func queryTags(trx *dbx.Trx, query string, args ...any) ([]*entity.Tag, error) {
tags := []*dbTag{}
err := trx.Select(&tags, query, args...)
if err != nil {
diff --git a/app/services/sqlstore/postgres/tenant.go b/app/services/sqlstore/postgres/tenant.go
index eae510df7..a1691be51 100644
--- a/app/services/sqlstore/postgres/tenant.go
+++ b/app/services/sqlstore/postgres/tenant.go
@@ -199,7 +199,7 @@ func getVerificationByKey(ctx context.Context, q *query.GetVerificationByKey) er
func saveVerificationKey(ctx context.Context, c *cmd.SaveVerificationKey) error {
return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- var userID interface{}
+ var userID any
if c.Request.GetUser() != nil {
userID = c.Request.GetUser().ID
}
diff --git a/app/services/sqlstore/postgres/user.go b/app/services/sqlstore/postgres/user.go
index cab24ebf5..348368042 100644
--- a/app/services/sqlstore/postgres/user.go
+++ b/app/services/sqlstore/postgres/user.go
@@ -387,7 +387,7 @@ func getAllUsers(ctx context.Context, q *query.GetAllUsers) error {
})
}
-func queryUser(ctx context.Context, trx *dbx.Trx, filter string, args ...interface{}) (*entity.User, error) {
+func queryUser(ctx context.Context, trx *dbx.Trx, filter string, args ...any) (*entity.User, error) {
user := dbUser{}
sql := fmt.Sprintf("SELECT id, name, email, tenant_id, role, status, avatar_type, avatar_bkey FROM users WHERE status != %d AND ", enum.UserDeleted)
err := trx.Get(&user, sql+filter, args...)
diff --git a/app/tasks/tasks.go b/app/tasks/tasks.go
index 4b67873f1..4448dfe6d 100644
--- a/app/tasks/tasks.go
+++ b/app/tasks/tasks.go
@@ -15,11 +15,11 @@ func describe(name string, job worker.Job) worker.Task {
return worker.Task{Name: name, Job: job}
}
-func link(baseURL, path string, args ...interface{}) string {
+func link(baseURL, path string, args ...any) string {
return fmt.Sprintf("<a href='%[1]s%[2]s'>%[1]s%[2]s</a>", baseURL, fmt.Sprintf(path, args...))
}
-func linkWithText(text, baseURL, path string, args ...interface{}) string {
+func linkWithText(text, baseURL, path string, args ...any) string {
return fmt.Sprintf("<a href='%s%s'>%s</a>", baseURL, fmt.Sprintf(path, args...), text)
}