Enforce use of any instead of interface{} (#30588)

Этот коммит содержится в:
Ben Schumacher
2025-03-31 10:44:34 +02:00
коммит произвёл GitHub
родитель 9aa4818c71
Коммит 166a676fe5
78 изменённых файлов: 268 добавлений и 262 удалений

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

@@ -26,7 +26,7 @@ const (
// MutexPluginAPI is the plugin API interface required to manage mutexes.
type MutexPluginAPI interface {
KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
LogError(msg string, keyValuePairs ...interface{})
LogError(msg string, keyValuePairs ...any)
}
// Mutex is similar to sync.Mutex, except usable by multiple plugin instances across a cluster.

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

@@ -14,7 +14,7 @@ type ConfigurationService struct {
// struct to which the configuration JSON can be unmarshalled.
//
// Minimum server version: 5.2
func (c *ConfigurationService) LoadPluginConfiguration(dest interface{}) error {
func (c *ConfigurationService) LoadPluginConfiguration(dest any) error {
// TODO: Isn't this method redundant given GetPluginConfig() and even GetConfig()?
return c.api.LoadPluginConfiguration(dest)
}
@@ -43,13 +43,13 @@ func (c *ConfigurationService) SaveConfig(cfg *model.Config) error {
// GetPluginConfig fetches the currently persisted config of plugin
//
// Minimum server version: 5.6
func (c *ConfigurationService) GetPluginConfig() map[string]interface{} {
func (c *ConfigurationService) GetPluginConfig() map[string]any {
return c.api.GetPluginConfig()
}
// SavePluginConfig sets the given config for plugin and persists the changes
//
// Minimum server version: 5.6
func (c *ConfigurationService) SavePluginConfig(cfg map[string]interface{}) error {
func (c *ConfigurationService) SavePluginConfig(cfg map[string]any) error {
return normalizeAppErr(c.api.SavePluginConfig(cfg))
}

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

@@ -46,7 +46,7 @@ func NewFromAPI(api common.LogAPI, dmer poster.DMer, logLevel logger.LogLevel, i
return New(logger.New(api), dmer, logLevel, includeContext, userIDs...)
}
func (l *adminCCLogger) Debugf(format string, args ...interface{}) {
func (l *adminCCLogger) Debugf(format string, args ...any) {
l.Logger.Debugf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 4 {
@@ -54,7 +54,7 @@ func (l *adminCCLogger) Debugf(format string, args ...interface{}) {
}
}
func (l *adminCCLogger) Errorf(format string, args ...interface{}) {
func (l *adminCCLogger) Errorf(format string, args ...any) {
l.Logger.Errorf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 1 {
@@ -62,7 +62,7 @@ func (l *adminCCLogger) Errorf(format string, args ...interface{}) {
}
}
func (l *adminCCLogger) Infof(format string, args ...interface{}) {
func (l *adminCCLogger) Infof(format string, args ...any) {
l.Logger.Infof(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 3 {
@@ -70,7 +70,7 @@ func (l *adminCCLogger) Infof(format string, args ...interface{}) {
}
}
func (l *adminCCLogger) Warnf(format string, args ...interface{}) {
func (l *adminCCLogger) Warnf(format string, args ...any) {
l.Logger.Warnf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 2 {
@@ -86,7 +86,7 @@ func (l *adminCCLogger) logToAdmins(level, message string) {
_ = l.dmAdmins("(log " + level + ") " + message)
}
func (l *adminCCLogger) dmAdmins(format string, args ...interface{}) error {
func (l *adminCCLogger) dmAdmins(format string, args ...any) error {
for _, id := range l.userIDs {
_, err := l.dmer.DM(id, format, args)
if err != nil {

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

@@ -30,7 +30,7 @@ func New(api common.LogAPI) Logger {
func (l *defaultLogger) With(logContext LogContext) Logger {
newLogger := *l
if len(newLogger.logContext) == 0 {
newLogger.logContext = map[string]interface{}{}
newLogger.logContext = map[string]any{}
}
for k, v := range logContext {
newLogger.logContext[k] = v
@@ -41,7 +41,7 @@ func (l *defaultLogger) With(logContext LogContext) Logger {
func (l *defaultLogger) WithError(err error) Logger {
newLogger := *l
if len(newLogger.logContext) == 0 {
newLogger.logContext = map[string]interface{}{}
newLogger.logContext = map[string]any{}
}
newLogger.logContext[ErrorKey] = err.Error()
return &newLogger
@@ -57,25 +57,25 @@ func (l *defaultLogger) Timed() Logger {
})
}
func (l *defaultLogger) Debugf(format string, args ...interface{}) {
func (l *defaultLogger) Debugf(format string, args ...any) {
measure(l.logContext)
message := fmt.Sprintf(format, args...)
l.logAPI.LogDebug(message, toKeyValuePairs(l.logContext)...)
}
func (l *defaultLogger) Errorf(format string, args ...interface{}) {
func (l *defaultLogger) Errorf(format string, args ...any) {
measure(l.logContext)
message := fmt.Sprintf(format, args...)
l.logAPI.LogError(message, toKeyValuePairs(l.logContext)...)
}
func (l *defaultLogger) Infof(format string, args ...interface{}) {
func (l *defaultLogger) Infof(format string, args ...any) {
measure(l.logContext)
message := fmt.Sprintf(format, args...)
l.logAPI.LogInfo(message, toKeyValuePairs(l.logContext)...)
}
func (l *defaultLogger) Warnf(format string, args ...interface{}) {
func (l *defaultLogger) Warnf(format string, args ...any) {
measure(l.logContext)
message := fmt.Sprintf(format, args...)
l.logAPI.LogWarn(message, toKeyValuePairs(l.logContext)...)

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

@@ -24,7 +24,7 @@ const (
)
// LogContext defines the context for the logs.
type LogContext map[string]interface{}
type LogContext map[string]any
// Logger defines an object able to log messages.
type Logger interface {
@@ -37,13 +37,13 @@ type Logger interface {
// Timed add a timed log context.
Timed() Logger
// Debugf logs a formatted string as a debug message.
Debugf(format string, args ...interface{})
Debugf(format string, args ...any)
// Errorf logs a formatted string as an error message.
Errorf(format string, args ...interface{})
Errorf(format string, args ...any)
// Infof logs a formatted string as an info message.
Infof(format string, args ...interface{})
Infof(format string, args ...any)
// Warnf logs a formatted string as an warning message.
Warnf(format string, args ...interface{})
Warnf(format string, args ...any)
}
func measure(lc LogContext) {
@@ -70,7 +70,7 @@ func Level(l LogLevel) int {
return 0
}
func toKeyValuePairs(in map[string]interface{}) (out []interface{}) {
func toKeyValuePairs(in map[string]any) (out []any) {
for k, v := range in {
out = append(out, k, v)
}

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

@@ -7,11 +7,11 @@ func NewNilLogger() Logger {
return &nilLogger{}
}
func (l *nilLogger) With(LogContext) Logger { return l }
func (l *nilLogger) WithError(error) Logger { return l }
func (l *nilLogger) Context() LogContext { return nil }
func (l *nilLogger) Timed() Logger { return l }
func (l *nilLogger) Debugf(string, ...interface{}) {}
func (l *nilLogger) Errorf(string, ...interface{}) {}
func (l *nilLogger) Infof(string, ...interface{}) {}
func (l *nilLogger) Warnf(string, ...interface{}) {}
func (l *nilLogger) With(LogContext) Logger { return l }
func (l *nilLogger) WithError(error) Logger { return l }
func (l *nilLogger) Context() LogContext { return nil }
func (l *nilLogger) Timed() Logger { return l }
func (l *nilLogger) Debugf(string, ...any) {}
func (l *nilLogger) Errorf(string, ...any) {}
func (l *nilLogger) Infof(string, ...any) {}
func (l *nilLogger) Warnf(string, ...any) {}

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

@@ -37,7 +37,7 @@ func NewFromAPI(api common.LogAPI, logLevel logger.LogLevel, tracker telemetry.T
return New(logger.New(api), logLevel, tracker)
}
func (l *telemetryLogger) Debugf(format string, args ...interface{}) {
func (l *telemetryLogger) Debugf(format string, args ...any) {
l.Logger.Debugf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 4 {
@@ -45,7 +45,7 @@ func (l *telemetryLogger) Debugf(format string, args ...interface{}) {
}
}
func (l *telemetryLogger) Errorf(format string, args ...interface{}) {
func (l *telemetryLogger) Errorf(format string, args ...any) {
l.Logger.Errorf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 1 {
@@ -53,7 +53,7 @@ func (l *telemetryLogger) Errorf(format string, args ...interface{}) {
}
}
func (l *telemetryLogger) Infof(format string, args ...interface{}) {
func (l *telemetryLogger) Infof(format string, args ...any) {
l.Logger.Infof(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 3 {
@@ -61,7 +61,7 @@ func (l *telemetryLogger) Infof(format string, args ...interface{}) {
}
}
func (l *telemetryLogger) Warnf(format string, args ...interface{}) {
func (l *telemetryLogger) Warnf(format string, args ...any) {
l.Logger.Warnf(format, args...)
message := fmt.Sprintf(format, args...)
if logger.Level(l.logLevel) >= 2 {
@@ -70,7 +70,7 @@ func (l *telemetryLogger) Warnf(format string, args ...interface{}) {
}
func (l *telemetryLogger) logToTelemetry(level, message string) {
properties := map[string]interface{}{}
properties := map[string]any{}
properties["message"] = message
for k, v := range l.Context() {
properties["context_"+k] = fmt.Sprintf("%v", v)

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

@@ -19,7 +19,7 @@ func NewTestLogger() Logger {
func (l *testLogger) With(logContext LogContext) Logger {
newl := *l
if len(newl.logContext) == 0 {
newl.logContext = map[string]interface{}{}
newl.logContext = map[string]any{}
}
for k, v := range logContext {
newl.logContext[k] = v
@@ -30,7 +30,7 @@ func (l *testLogger) With(logContext LogContext) Logger {
func (l *testLogger) WithError(err error) Logger {
newl := *l
if len(newl.logContext) == 0 {
newl.logContext = map[string]interface{}{}
newl.logContext = map[string]any{}
}
newl.logContext[ErrorKey] = err.Error()
return &newl
@@ -46,7 +46,7 @@ func (l *testLogger) Timed() Logger {
})
}
func (l *testLogger) logf(prefix, format string, args ...interface{}) {
func (l *testLogger) logf(prefix, format string, args ...any) {
out := fmt.Sprintf(prefix+": "+format, args...)
if len(l.logContext) > 0 {
measure(l.logContext)
@@ -55,7 +55,7 @@ func (l *testLogger) logf(prefix, format string, args ...interface{}) {
l.TB.Log(out)
}
func (l *testLogger) Debugf(format string, args ...interface{}) { l.logf("DEBUG", format, args...) }
func (l *testLogger) Errorf(format string, args ...interface{}) { l.logf("ERROR", format, args...) }
func (l *testLogger) Infof(format string, args ...interface{}) { l.logf("INFO", format, args...) }
func (l *testLogger) Warnf(format string, args ...interface{}) { l.logf("WARN", format, args...) }
func (l *testLogger) Debugf(format string, args ...any) { l.logf("DEBUG", format, args...) }
func (l *testLogger) Errorf(format string, args ...any) { l.logf("ERROR", format, args...) }
func (l *testLogger) Infof(format string, args ...any) { l.logf("INFO", format, args...) }
func (l *testLogger) Warnf(format string, args ...any) { l.logf("WARN", format, args...) }

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

@@ -20,7 +20,7 @@ func NewPoster(postAPI PostAPI, id string) Poster {
}
// DM posts a simple Direct Message to the specified user
func (p *defaultPoster) DM(mattermostUserID, format string, args ...interface{}) (string, error) {
func (p *defaultPoster) DM(mattermostUserID, format string, args ...any) (string, error) {
post := &model.Post{
Message: fmt.Sprintf(format, args...),
}
@@ -44,7 +44,7 @@ func (p *defaultPoster) DMWithAttachments(mattermostUserID string, attachments .
}
// Ephemeral sends an ephemeral message to a user
func (p *defaultPoster) Ephemeral(userID, channelID, format string, args ...interface{}) {
func (p *defaultPoster) Ephemeral(userID, channelID, format string, args ...any) {
post := &model.Post{
UserId: p.id,
ChannelId: channelID,
@@ -53,7 +53,7 @@ func (p *defaultPoster) Ephemeral(userID, channelID, format string, args ...inte
p.postAPI.SendEphemeralPost(userID, post)
}
func (p *defaultPoster) UpdatePostByID(postID, format string, args ...interface{}) error {
func (p *defaultPoster) UpdatePostByID(postID, format string, args ...any) error {
post, err := p.postAPI.GetPost(postID)
if err != nil {
return err

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

@@ -30,7 +30,7 @@ func TestInterface(t *testing.T) {
func TestDM(t *testing.T) {
format := "test format, string: %s int: %d value: %v"
args := []interface{}{"some string", 5, 8.423}
args := []any{"some string", 5, 8.423}
expectedMessage := "test format, string: some string int: 5 value: 8.423"
expectedPostID := "expected-post-id"
@@ -153,7 +153,7 @@ func TestDMWithAttachments(t *testing.T) {
func TestEphemeral(t *testing.T) {
format := "test format, string: %s int: %d value: %v"
args := []interface{}{"some string", 5, 8.423}
args := []any{"some string", 5, 8.423}
expectedMessage := "test format, string: some string int: 5 value: 8.423"
channelID := "some-channel"
@@ -194,7 +194,7 @@ func TestEphemeral(t *testing.T) {
func TestUpdatePostByID(t *testing.T) {
format := "test format, string: %s int: %d value: %v"
args := []interface{}{"some string", 5, 8.423}
args := []any{"some string", 5, 8.423}
expectedMessage := "test format, string: some string int: 5 value: 8.423"
postID := "some-post-id"
@@ -364,7 +364,7 @@ func TestUpdatePost(t *testing.T) {
func TestUpdatePosterID(t *testing.T) {
format := "test format, string: %s int: %d value: %v"
args := []interface{}{"some string", 5, 8.423}
args := []any{"some string", 5, 8.423}
expectedMessage := "test format, string: some string int: 5 value: 8.423"
expectedPostID := "expected-post-id"

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

@@ -16,10 +16,10 @@ type Poster interface {
DMWithAttachments(mattermostUserID string, attachments ...*model.SlackAttachment) (string, error)
// Ephemeral sends an ephemeral message to a user
Ephemeral(mattermostUserID, channelID, format string, args ...interface{})
Ephemeral(mattermostUserID, channelID, format string, args ...any)
// UpdatePostByID updates the post with postID with the formatted message
UpdatePostByID(postID, format string, args ...interface{}) error
UpdatePostByID(postID, format string, args ...any) error
// DeletePost deletes a single post
DeletePost(postID string) error
@@ -34,5 +34,5 @@ type Poster interface {
// DMer defines an entity that can send Direct Messages
type DMer interface {
// DM posts a simple Direct Message to the specified user
DM(mattermostUserID, format string, args ...interface{}) (string, error)
DM(mattermostUserID, format string, args ...any) (string, error)
}

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

@@ -9,8 +9,8 @@ import (
var ErrNotFound = errors.New("not found")
type KVStore interface {
Set(key string, value interface{}, options ...pluginapi.KVSetOption) (bool, error)
Get(key string, o interface{}) error
Set(key string, value any, options ...pluginapi.KVSetOption) (bool, error)
Get(key string, o any) error
Delete(key string) error
DeleteAll() error
ListKeys(page, count int, options ...pluginapi.ListKeysOption) ([]string, error)

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

@@ -1,8 +1,8 @@
package common
type LogAPI interface {
LogError(message string, keyValuePairs ...interface{})
LogWarn(message string, keyValuePairs ...interface{})
LogInfo(message string, keyValuePairs ...interface{})
LogDebug(message string, keyValuePairs ...interface{})
LogError(message string, keyValuePairs ...any)
LogWarn(message string, keyValuePairs ...any)
LogInfo(message string, keyValuePairs ...any)
LogDebug(message string, keyValuePairs ...any)
}

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

@@ -8,7 +8,7 @@ import (
"fmt"
)
func JSON(ref interface{}) string {
func JSON(ref any) string {
bb, _ := json.MarshalIndent(ref, "", " ")
return string(bb)
}
@@ -17,6 +17,6 @@ func CodeBlock(in string) string {
return fmt.Sprintf("\n```\n%s\n```\n", in)
}
func JSONBlock(ref interface{}) string {
func JSONBlock(ref any) string {
return fmt.Sprintf("\n```json\n%s\n```\n", JSON(ref))
}

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

@@ -259,8 +259,8 @@ func Goto(toName Name) func(*Flow) (Name, State, error) {
}
}
func DialogGoto(toName Name) func(*Flow, map[string]interface{}) (Name, State, map[string]string, error) {
return func(_ *Flow, submitted map[string]interface{}) (Name, State, map[string]string, error) {
func DialogGoto(toName Name) func(*Flow, map[string]any) (Name, State, map[string]string, error) {
return func(_ *Flow, submitted map[string]any) (Name, State, map[string]string, error) {
stateUpdate := State{}
for k, v := range submitted {
stateUpdate[k] = fmt.Sprintf("%v", v)

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

@@ -97,7 +97,7 @@ func (f *Flow) handleButton(fromName Name, selectedButton int, triggerID string)
}
func (f *Flow) handleDialog(
fromName Name, selectedButton int, submission map[string]interface{},
fromName Name, selectedButton int, submission map[string]any,
) (
*model.Post, map[string]string, error,
) {
@@ -105,7 +105,7 @@ func (f *Flow) handleDialog(
}
func (f *Flow) handle(
fromName Name, selectedButton int, submission map[string]interface{}, triggerID string, asButton bool,
fromName Name, selectedButton int, submission map[string]any, triggerID string, asButton bool,
) (
*model.Post, map[string]string, error,
) {

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

@@ -9,7 +9,7 @@ import (
var errStateNotFound = errors.New("flow state not found")
// State is the "app"'s state
type State map[string]interface{}
type State map[string]any
func (s State) MergeWith(update State) State {
n := State{}

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

@@ -50,7 +50,7 @@ type Button struct {
// Function that is called when the dialog box is submitted. It can return a
// general error, or field-specific errors. On success it returns the name
// of the next step, and the state updates to apply.
OnDialogSubmit func(f *Flow, submitted map[string]interface{}) (Name, State, map[string]string, error)
OnDialogSubmit func(f *Flow, submitted map[string]any) (Name, State, map[string]string, error)
}
func NewStep(name Name) Step {
@@ -229,7 +229,7 @@ func renderButton(b Button, stepName Name, i int, state State) *model.PostAction
Disabled: b.Disabled,
Style: string(b.Color),
Integration: &model.PostActionIntegration{
Context: map[string]interface{}{
Context: map[string]any{
contextStepKey: string(stepName),
contextButtonKey: strconv.Itoa(i),
},

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

@@ -11,7 +11,7 @@ import (
)
type Panel interface {
Set(userID, settingID string, value interface{}) error
Set(userID, settingID string, value any) error
Print(userID string)
ToPost(userID string) (*model.Post, error)
Clear(userID string) error
@@ -57,7 +57,7 @@ func NewSettingsPanel(
return panel
}
func (p *panel) Set(userID, settingID string, value interface{}) error {
func (p *panel) Set(userID, settingID string, value any) error {
s, ok := p.settings[settingID]
if !ok {
return errors.New("cannot find setting " + settingID)

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

@@ -23,6 +23,6 @@ func (s *baseSetting) GetDependency() string {
return s.dependsOn
}
func (s *baseSetting) IsDisabled(foreignValue interface{}) bool {
func (s *baseSetting) IsDisabled(foreignValue any) bool {
return false
}

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

@@ -25,7 +25,7 @@ func NewBoolSetting(id, title, description, dependsOn string, store SettingStore
}
}
func (s *boolSetting) Set(userID string, value interface{}) error {
func (s *boolSetting) Set(userID string, value any) error {
boolValue := false
if value == TrueString {
boolValue = true
@@ -39,7 +39,7 @@ func (s *boolSetting) Set(userID string, value interface{}) error {
return nil
}
func (s *boolSetting) Get(userID string) (interface{}, error) {
func (s *boolSetting) Get(userID string) (any, error) {
value, err := s.store.GetSetting(userID, s.id)
if err != nil {
return "", err
@@ -79,7 +79,7 @@ func (s *boolSetting) GetSlackAttachments(userID, settingHandler string, disable
Name: "Yes",
Integration: &model.PostActionIntegration{
URL: settingHandler,
Context: map[string]interface{}{
Context: map[string]any{
ContextIDKey: s.id,
ContextButtonValueKey: TrueString,
},
@@ -91,7 +91,7 @@ func (s *boolSetting) GetSlackAttachments(userID, settingHandler string, disable
Name: "No",
Integration: &model.PostActionIntegration{
URL: settingHandler,
Context: map[string]interface{}{
Context: map[string]any{
ContextIDKey: s.id,
ContextButtonValueKey: FalseString,
},
@@ -111,6 +111,6 @@ func (s *boolSetting) GetSlackAttachments(userID, settingHandler string, disable
return &sa, nil
}
func (s *boolSetting) IsDisabled(foreignValue interface{}) bool {
func (s *boolSetting) IsDisabled(foreignValue any) bool {
return foreignValue == FalseString
}

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

@@ -32,10 +32,10 @@ func (s *emptySetting) GetSlackAttachments(userID, settingHandler string, disabl
return &sa, nil
}
func (s *emptySetting) Get(userID string) (interface{}, error) {
func (s *emptySetting) Get(userID string) (any, error) {
return nil, nil
}
func (s *emptySetting) Set(userID string, value interface{}) error {
func (s *emptySetting) Set(userID string, value any) error {
return nil
}

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

@@ -27,7 +27,7 @@ func NewOptionSetting(id, title, description, dependsOn string, options []string
}
}
func (s *optionSetting) Set(userID string, value interface{}) error {
func (s *optionSetting) Set(userID string, value any) error {
err := s.store.SetSetting(userID, s.id, value)
if err != nil {
return err
@@ -36,7 +36,7 @@ func (s *optionSetting) Set(userID string, value interface{}) error {
return nil
}
func (s *optionSetting) Get(userID string) (interface{}, error) {
func (s *optionSetting) Get(userID string) (any, error) {
value, err := s.store.GetSetting(userID, s.id)
if err != nil {
return "", err
@@ -66,7 +66,7 @@ func (s *optionSetting) GetSlackAttachments(userID, settingHandler string, disab
Name: "Select an option:",
Integration: &model.PostActionIntegration{
URL: settingHandler + "?" + s.id + "=true",
Context: map[string]interface{}{
Context: map[string]any{
ContextIDKey: s.id,
},
},
@@ -86,6 +86,6 @@ func (s *optionSetting) GetSlackAttachments(userID, settingHandler string, disab
return &sa, nil
}
func (s *optionSetting) IsDisabled(foreignValue interface{}) bool {
func (s *optionSetting) IsDisabled(foreignValue any) bool {
return foreignValue == FalseString
}

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

@@ -25,7 +25,7 @@ func NewReadOnlySetting(id, title, description, dependsOn string, store SettingS
}
}
func (s *readOnlySetting) Get(userID string) (interface{}, error) {
func (s *readOnlySetting) Get(userID string) (any, error) {
value, err := s.store.GetSetting(userID, s.id)
if err != nil {
return "", err
@@ -38,7 +38,7 @@ func (s *readOnlySetting) Get(userID string) (interface{}, error) {
return stringValue, nil
}
func (s *readOnlySetting) Set(userID string, value interface{}) error {
func (s *readOnlySetting) Set(userID string, value any) error {
return nil
}
@@ -64,6 +64,6 @@ func (s *readOnlySetting) GetSlackAttachments(userID, settingHandler string, dis
return &sa, nil
}
func (s *readOnlySetting) IsDisabled(foreignValue interface{}) bool {
func (s *readOnlySetting) IsDisabled(foreignValue any) bool {
return foreignValue == FalseString
}

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

@@ -22,11 +22,11 @@ const (
// Setting defines the behavior of each element a the panel
type Setting interface {
Set(userID string, value interface{}) error
Get(userID string) (interface{}, error)
Set(userID string, value any) error
Get(userID string) (any, error)
GetID() string
GetDependency() string
IsDisabled(foreignValue interface{}) bool
IsDisabled(foreignValue any) bool
GetTitle() string
GetDescription() string
GetSlackAttachments(userID, settingHandler string, disabled bool) (*model.SlackAttachment, error)

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

@@ -2,6 +2,6 @@ package settings
// SettingStore defines the behavior needed to set and get settings
type SettingStore interface {
SetSetting(userID, settingID string, value interface{}) error
GetSetting(userID, settingID string) (interface{}, error)
SetSetting(userID, settingID string, value any) error
GetSetting(userID, settingID string) (any, error)
}

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

@@ -39,9 +39,9 @@ func NewTrackerConfig(config *model.Config) TrackerConfig {
// Tracker defines a telemetry tracker
type Tracker interface {
// TrackEvent registers an event through the configured telemetry client
TrackEvent(event string, properties map[string]interface{}) error
TrackEvent(event string, properties map[string]any) error
// TrackUserEvent registers an event through the configured telemetry client associated to a user
TrackUserEvent(event string, userID string, properties map[string]interface{}) error
TrackUserEvent(event string, userID string, properties map[string]any) error
// Reload Config re-evaluates tracker config to determine if tracking behavior should change
ReloadConfig(config TrackerConfig)
}
@@ -58,7 +58,7 @@ type Client interface {
type Track struct {
UserID string
Event string
Properties map[string]interface{}
Properties map[string]any
InstallationID string
}
@@ -126,14 +126,14 @@ func (t *tracker) ReloadConfig(config TrackerConfig) {
}
// Note that config lock is handled by the caller.
func (t *tracker) debugf(message string, args ...interface{}) {
func (t *tracker) debugf(message string, args ...any) {
if t.logger == nil || !t.config.EnabledLogging {
return
}
t.logger.Debugf(message, args...)
}
func (t *tracker) TrackEvent(event string, properties map[string]interface{}) error {
func (t *tracker) TrackEvent(event string, properties map[string]any) error {
t.configLock.RLock()
defer t.configLock.RUnlock()
@@ -144,7 +144,7 @@ func (t *tracker) TrackEvent(event string, properties map[string]interface{}) er
}
if properties == nil {
properties = map[string]interface{}{}
properties = map[string]any{}
}
properties["PluginID"] = t.pluginID
properties["PluginVersion"] = t.pluginVersion
@@ -169,9 +169,9 @@ func (t *tracker) TrackEvent(event string, properties map[string]interface{}) er
return nil
}
func (t *tracker) TrackUserEvent(event, userID string, properties map[string]interface{}) error {
func (t *tracker) TrackUserEvent(event, userID string, properties map[string]any) error {
if properties == nil {
properties = map[string]interface{}{}
properties = map[string]any{}
}
properties["UserActualID"] = userID

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

@@ -25,6 +25,6 @@ func (f *FrontendService) OpenInteractiveDialog(dialog model.OpenDialogRequest)
// broadcast determines to which users to send the event.
//
// Minimum server version: 5.2
func (f *FrontendService) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
func (f *FrontendService) PublishWebSocketEvent(event string, payload map[string]any, broadcast *model.WebsocketBroadcast) {
f.api.PublishWebSocketEvent(event, payload, broadcast)
}

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

@@ -18,7 +18,7 @@ type PluginAPI interface {
GetBundlePath() (string, error)
GetConfig() *model.Config
GetUser(userID string) (*model.User, *model.AppError)
LogWarn(msg string, keyValuePairs ...interface{})
LogWarn(msg string, keyValuePairs ...any)
}
// Message is a string that can be localized.

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

@@ -24,7 +24,7 @@ type KVService struct {
type KVSetOptions struct {
model.PluginKVSetOptions
oldValue interface{}
oldValue any
}
// KVSetOption is an option passed to Set() operation.
@@ -33,7 +33,7 @@ type KVSetOption func(*KVSetOptions)
// SetAtomic guarantees the write will occur only when the current value of matches the given old
// value. A client is expected to read the old value first, then pass it back to ensure the value
// has not since been modified.
func SetAtomic(oldValue interface{}) KVSetOption {
func SetAtomic(oldValue any) KVSetOption {
return func(o *KVSetOptions) {
o.Atomic = true
o.oldValue = oldValue
@@ -55,7 +55,7 @@ func SetExpiry(ttl time.Duration) KVSetOption {
// Returns (true, nil) if the value was set
//
// Minimum server version: 5.18
func (k *KVService) Set(key string, value interface{}, options ...KVSetOption) (bool, error) {
func (k *KVService) Set(key string, value any, options ...KVSetOption) (bool, error) {
if strings.HasPrefix(key, internalKeyPrefix) {
return false, errors.Errorf("'%s' prefix is not allowed for keys", internalKeyPrefix)
}
@@ -123,7 +123,7 @@ func (k *KVService) Set(key string, value interface{}, options ...KVSetOption) (
// Returns nil if the value was set.
//
// Minimum server version: 5.18
func (k *KVService) SetAtomicWithRetries(key string, valueFunc func(oldValue []byte) (newValue interface{}, err error)) error {
func (k *KVService) SetAtomicWithRetries(key string, valueFunc func(oldValue []byte) (newValue any, err error)) error {
for i := 0; i < numRetries; i++ {
var oldVal []byte
if err := k.Get(key, &oldVal); err != nil {
@@ -153,7 +153,7 @@ func (k *KVService) SetAtomicWithRetries(key string, valueFunc func(oldValue []b
// error, with nothing written to the given interface.
//
// Minimum server version: 5.2
func (k *KVService) Get(key string, o interface{}) error {
func (k *KVService) Get(key string, o any) error {
data, appErr := k.api.KVGet(key)
if appErr != nil {
return normalizeAppErr(appErr)

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

@@ -24,7 +24,7 @@ func TestKVSet(t *testing.T) {
tests := []struct {
name string
key string
value interface{}
value any
options []pluginapi.KVSetOption
expectedValue []byte
expectedOptions model.PluginKVSetOptions
@@ -158,7 +158,7 @@ func TestSetAtomicWithRetries(t *testing.T) {
tests := []struct {
name string
key string
valueFunc func(t *testing.T) func(old []byte) (interface{}, error)
valueFunc func(t *testing.T) func(old []byte) (any, error)
setupAPI func(api *plugintest.API)
wantErr bool
expectedErrPrefix string
@@ -166,8 +166,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries success after first attempt",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return 2, nil
}
},
@@ -184,8 +184,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test success after first attempt, old is struct and as expected",
key: "testNum2",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
type toStore struct {
Value int
}
@@ -213,8 +213,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test success after first attempt, old is an int value and as expected",
key: "testNum2",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
fromDB, err := strconv.Atoi(string(old))
if err != nil {
return nil, err
@@ -236,8 +236,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries success on fourth attempt",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return 2, nil
}
},
@@ -258,8 +258,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries success on fourth attempt because value was changed between calls to KVGet",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return 2, nil
}
},
@@ -280,8 +280,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries failure on get",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return nil, errors.New("should not have got here")
}
},
@@ -294,8 +294,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries failure on valueFunc",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return nil, errors.New("some user provided error")
}
},
@@ -309,8 +309,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries DB failure on set",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return 2, nil
}
},
@@ -329,8 +329,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries failure on five set attempts -- depends on numRetries constant being = 5",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
return 2, nil
}
},
@@ -349,8 +349,8 @@ func TestSetAtomicWithRetries(t *testing.T) {
{
name: "Test SetAtomicWithRetries success after five set attempts -- depends on numRetries constant being = 5",
key: "testNum",
valueFunc: func(t *testing.T) func(old []byte) (interface{}, error) {
return func(old []byte) (interface{}, error) {
valueFunc: func(t *testing.T) func(old []byte) (any, error) {
return func(old []byte) (any, error) {
fromDB, err := strconv.Atoi(string(old))
if err != nil {
return nil, err

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

@@ -13,21 +13,21 @@ type LogService struct {
}
// Error logs an error message, optionally structured with alternating key, value parameters.
func (l *LogService) Error(message string, keyValuePairs ...interface{}) {
func (l *LogService) Error(message string, keyValuePairs ...any) {
l.api.LogError(message, keyValuePairs...)
}
// Warn logs an error message, optionally structured with alternating key, value parameters.
func (l *LogService) Warn(message string, keyValuePairs ...interface{}) {
func (l *LogService) Warn(message string, keyValuePairs ...any) {
l.api.LogWarn(message, keyValuePairs...)
}
// Info logs an error message, optionally structured with alternating key, value parameters.
func (l *LogService) Info(message string, keyValuePairs ...interface{}) {
func (l *LogService) Info(message string, keyValuePairs ...any) {
l.api.LogInfo(message, keyValuePairs...)
}
// Debug logs an error message, optionally structured with alternating key, value parameters.
func (l *LogService) Debug(message string, keyValuePairs ...interface{}) {
func (l *LogService) Debug(message string, keyValuePairs ...any) {
l.api.LogDebug(message, keyValuePairs...)
}

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

@@ -33,7 +33,7 @@ func (lh *LogrusHook) Levels() []logrus.Level {
// Fire proxies logrus entries through the plugin API at the appropriate level.
func (lh *LogrusHook) Fire(entry *logrus.Entry) error {
fields := []interface{}{}
fields := []any{}
for key, value := range entry.Data {
fields = append(fields, key, fmt.Sprintf("%+v", value))
}