* replace interface{} with any
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-07-05 09:46:50 +03:00
коммит произвёл GitHub
родитель b45ff0be5d
Коммит 717a4d04a9
258 изменённых файлов: 1286 добавлений и 1286 удалений

Просмотреть файл

@@ -20,7 +20,7 @@ import (
const defaultLocale = "en"
// TranslateFunc is the type of the translate functions
type TranslateFunc func(translationID string, args ...interface{}) string
type TranslateFunc func(translationID string, args ...any) string
// T is the translate function using the default server language as fallback language
var T TranslateFunc
@@ -135,7 +135,7 @@ func GetSupportedLocales() map[string]string {
func tfuncWithFallback(pref string) TranslateFunc {
t, _ := i18n.Tfunc(pref)
return func(translationID string, args ...interface{}) string {
return func(translationID string, args ...any) string {
if translated := t(translationID, args...); translated != translationID {
return translated
}
@@ -147,21 +147,21 @@ func tfuncWithFallback(pref string) TranslateFunc {
// TranslateAsHTML translates the translationID provided and return a
// template.HTML object
func TranslateAsHTML(t TranslateFunc, translationID string, args map[string]interface{}) template.HTML {
func TranslateAsHTML(t TranslateFunc, translationID string, args map[string]any) template.HTML {
message := t(translationID, escapeForHTML(args))
message = strings.Replace(message, "[[", "<strong>", -1)
message = strings.Replace(message, "]]", "</strong>", -1)
return template.HTML(message)
}
func escapeForHTML(arg interface{}) interface{} {
func escapeForHTML(arg any) any {
switch typedArg := arg.(type) {
case string:
return template.HTMLEscapeString(typedArg)
case *string:
return template.HTMLEscapeString(*typedArg)
case map[string]interface{}:
safeArg := make(map[string]interface{}, len(typedArg))
case map[string]any:
safeArg := make(map[string]any, len(typedArg))
for key, value := range typedArg {
safeArg[key] = escapeForHTML(value)
}
@@ -179,7 +179,7 @@ func escapeForHTML(arg interface{}) interface{} {
// IdentityTfunc returns a translation function that don't translate, only
// returns the same id
func IdentityTfunc() TranslateFunc {
return func(translationID string, args ...interface{}) string {
return func(translationID string, args ...any) string {
return translationID
}
}

Просмотреть файл

@@ -16,7 +16,7 @@ var htmlTestTranslationBundle *bundle.Bundle
func init() {
htmlTestTranslationBundle = bundle.New()
fooBold, _ := translation.NewTranslation(map[string]interface{}{
fooBold, _ := translation.NewTranslation(map[string]any{
"id": "foo.bold",
"translation": "<p>[[{{ .Foo }}]]</p>",
})
@@ -24,7 +24,7 @@ func init() {
}
func TestTranslateAsHTML(t *testing.T) {
assert.EqualValues(t, "<p><strong>&lt;i&gt;foo&lt;/i&gt;</strong></p>", TranslateAsHTML(TranslateFunc(htmlTestTranslationBundle.MustTfunc("en")), "foo.bold", map[string]interface{}{
assert.EqualValues(t, "<p><strong>&lt;i&gt;foo&lt;/i&gt;</strong></p>", TranslateAsHTML(TranslateFunc(htmlTestTranslationBundle.MustTfunc("en")), "foo.bold", map[string]any{
"Foo": "<i>foo</i>",
}))
}
@@ -32,8 +32,8 @@ func TestTranslateAsHTML(t *testing.T) {
func TestEscapeForHTML(t *testing.T) {
stringForPointer := "<b>abc</b>"
for name, tc := range map[string]struct {
In interface{}
Expected interface{}
In any
Expected any
}{
"NoHTML": {
In: "abc",
@@ -48,11 +48,11 @@ func TestEscapeForHTML(t *testing.T) {
Expected: "&lt;b&gt;abc&lt;/b&gt;",
},
"Map": {
In: map[string]interface{}{
In: map[string]any{
"abc": "abc",
"123": "<b>123</b>",
},
Expected: map[string]interface{}{
Expected: map[string]any{
"abc": "abc",
"123": "&lt;b&gt;123&lt;/b&gt;",
},

Просмотреть файл

@@ -5,7 +5,7 @@ package markdown
// Inspect traverses the markdown tree in depth-first order. If f returns true, Inspect invokes f
// recursively for each child of the block or inline, followed by a call of f(nil).
func Inspect(markdown string, f func(interface{}) bool) {
func Inspect(markdown string, f func(any) bool) {
document, referenceDefinitions := Parse(markdown)
InspectBlock(document, func(block Block) bool {
if !f(block) {

Просмотреть файл

@@ -22,7 +22,7 @@ func TestInspect(t *testing.T) {
visited := []string{}
level := 0
Inspect(markdown, func(blockOrInline interface{}) bool {
Inspect(markdown, func(blockOrInline any) bool {
if blockOrInline == nil {
level--
} else {
@@ -67,7 +67,7 @@ Some bold text **Text for markdown?** to go with it.
At the end, some more lines`
for i := 0; i < b.N; i++ {
Inspect(text, func(_ interface{}) bool {
Inspect(text, func(_ any) bool {
counterSink++
return true
})

Просмотреть файл

@@ -99,7 +99,7 @@ func TestTextRanges(t *testing.T) {
t.Run(name, func(t *testing.T) {
var ranges []Range
var values []string
Inspect(tc.Markdown, func(node interface{}) bool {
Inspect(tc.Markdown, func(node any) bool {
if textNode, ok := node.(*Text); ok {
ranges = append(ranges, textNode.Range)
values = append(values, textNode.Text)

Просмотреть файл

@@ -18,6 +18,6 @@ func NewGraphQLLogger(logger *Logger) *GraphQLLogger {
// LogPanic satisfies the graphql/log.Logger interface.
// It converts the panic into an error.
func (l *GraphQLLogger) LogPanic(_ context.Context, value interface{}) {
func (l *GraphQLLogger) LogPanic(_ context.Context, value any) {
l.logger.Error("Error while executing GraphQL query", Any("error", value))
}

Просмотреть файл

@@ -27,7 +27,7 @@ type Container struct {
// Data contains the data used to populate the template variables, it has Props
// that can be of any type and HTML that only can be `template.HTML` types.
type Data struct {
Props map[string]interface{}
Props map[string]any
HTML map[string]template.HTML
}

Просмотреть файл

@@ -73,7 +73,7 @@ func TestRender(t *testing.T) {
mt := NewFromTemplate(tpl)
data := Data{
Props: map[string]interface{}{
Props: map[string]any{
"Bar": "bar",
},
}