diff --git a/cmd/configure.go b/cmd/configure.go index 03553b8d6..26b5c9f8a 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -67,7 +67,7 @@ func configureCmdRun(cmd *cobra.Command, args []string) { questions = append(questions, &survey.Question{ Name: "PanelURL", Prompt: &survey.Input{Message: "Panel URL: "}, - Validate: func(ans interface{}) error { + Validate: func(ans any) error { if str, ok := ans.(string); ok { _, err := url.ParseRequestURI(str) return err @@ -81,7 +81,7 @@ func configureCmdRun(cmd *cobra.Command, args []string) { questions = append(questions, &survey.Question{ Name: "Token", Prompt: &survey.Input{Message: "API Token: "}, - Validate: func(ans interface{}) error { + Validate: func(ans any) error { if str, ok := ans.(string); ok { if len(str) == 0 { return fmt.Errorf("please provide a valid authentication token") @@ -96,7 +96,7 @@ func configureCmdRun(cmd *cobra.Command, args []string) { questions = append(questions, &survey.Question{ Name: "Node", Prompt: &survey.Input{Message: "Node ID: "}, - Validate: func(ans interface{}) error { + Validate: func(ans any) error { if str, ok := ans.(string); ok { if !nodeIdRegex.Match([]byte(str)) { return fmt.Errorf("please provide a valid authentication token") diff --git a/cmd/diagnostics.go b/cmd/diagnostics.go index aa3bd8b69..336d7d59f 100644 --- a/cmd/diagnostics.go +++ b/cmd/diagnostics.go @@ -235,7 +235,7 @@ func uploadToHastebin(hbUrl, content string) (string, error) { fmt.Println("Failed to upload report to ", u.String(), err) return "", err } - pres := make(map[string]interface{}) + pres := make(map[string]any) body, err := io.ReadAll(res.Body) if err != nil { fmt.Println("Failed to parse response.", err) diff --git a/environment/settings.go b/environment/settings.go index 1d57154ee..8601f0ac8 100644 --- a/environment/settings.go +++ b/environment/settings.go @@ -131,7 +131,7 @@ func (l Limits) AsContainerResources() container.Resources { return resources } -type Variables map[string]interface{} +type Variables map[string]any // Get is an ugly hacky function to handle environment variables that get passed // through as not-a-string from the Panel. Ideally we'd just say only pass diff --git a/events/events.go b/events/events.go index 1cc1dafc6..42c96c3a0 100644 --- a/events/events.go +++ b/events/events.go @@ -12,7 +12,7 @@ import ( // Event represents an Event sent over a Bus. type Event struct { Topic string - Data interface{} + Data any } // Bus represents an Event Bus. @@ -33,7 +33,7 @@ func NewBus() *Bus { } // Publish publishes a message to the Bus. -func (b *Bus) Publish(topic string, data interface{}) { +func (b *Bus) Publish(topic string, data any) { // Some of our actions for the socket support passing a more specific namespace, // such as "backup completed:1234" to indicate which specific backup was completed. // @@ -63,7 +63,7 @@ func MustDecode(data []byte) (e Event) { } // DecodeTo decodes a byte slice of event data into the given interface. -func DecodeTo(data []byte, v interface{}) error { +func DecodeTo(data []byte, v any) error { if err := json.Unmarshal(data, &v); err != nil { return errors.Wrap(err, "events: failed to decode byte slice") } diff --git a/internal/cron/sftp_cron.go b/internal/cron/sftp_cron.go index f51d835db..cc38c4a90 100644 --- a/internal/cron/sftp_cron.go +++ b/internal/cron/sftp_cron.go @@ -141,7 +141,7 @@ func (em *eventMap) Push(a models.Activity) { if a.Timestamp.Before(m.Timestamp) { m.Timestamp = a.Timestamp } - list := m.Metadata["files"].([]interface{}) + list := m.Metadata["files"].([]any) if s, ok := a.Metadata["files"]; ok { v := reflect.ValueOf(s) if v.Kind() != reflect.Slice || v.IsNil() { @@ -188,7 +188,7 @@ func (em *eventMap) forActivity(a models.Activity) *models.Activity { // function and then assign it into the map with an empty metadata value. v := a v.Metadata = models.ActivityMeta{ - "files": make([]interface{}, 0), + "files": make([]any, 0), } em.m[key] = &v return &v diff --git a/internal/models/activity.go b/internal/models/activity.go index 058a75567..8afd6ca8f 100644 --- a/internal/models/activity.go +++ b/internal/models/activity.go @@ -10,7 +10,7 @@ import ( type Event string -type ActivityMeta map[string]interface{} +type ActivityMeta map[string]any // Activity defines an activity log event for a server entity performed by a user. This is // used for tracking commands, power actions, and SFTP events so that they can be reconciled diff --git a/parser/helpers.go b/parser/helpers.go index be09c686f..a00de178a 100644 --- a/parser/helpers.go +++ b/parser/helpers.go @@ -36,7 +36,7 @@ var configMatchRegex = regexp.MustCompile(`{{\s?config\.([\w.-]+)\s?}}`) var xmlValueMatchRegex = regexp.MustCompile(`^\[([\w]+)='(.*)'\]$`) // Gets the value of a key based on the value type defined. -func (cfr *ConfigurationFileReplacement) getKeyValue(value string) interface{} { +func (cfr *ConfigurationFileReplacement) getKeyValue(value string) any { if cfr.ReplaceWith.Type() == jsonparser.Boolean { v, _ := strconv.ParseBool(value) return v @@ -115,7 +115,7 @@ var checkForArrayElement = regexp.MustCompile(`^([^\[\]]+)\[([\d]+)](\..+)?$`) // to handle that edge case and ensure the value gets set correctly. // // Bless thee who has to touch these most unholy waters. -func setValueAtPath(c *gabs.Container, path string, value interface{}) error { +func setValueAtPath(c *gabs.Container, path string, value any) error { var err error matches := checkForArrayElement.FindStringSubmatch(path) @@ -135,12 +135,12 @@ func setValueAtPath(c *gabs.Container, path string, value interface{}) error { return errors.WithMessage(err, "error while parsing array element at path") } - t := make([]interface{}, 1) + t := make([]any, 1) // If the length of matches is 4 it means we're trying to access an object down in this array // key, so make sure we generate the array as an array of objects, and not just a generic nil // array. if len(matches) == 4 { - t = []interface{}{map[string]interface{}{}} + t = []any{map[string]any{}} } // If the error is because this isn't an array or isn't found go ahead and create the array with diff --git a/parser/parser.go b/parser/parser.go index e7c98b3b2..cd76585a4 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -413,7 +413,7 @@ func (f *ConfigurationFile) parseYamlFile(file ufs.File) error { return err } - i := make(map[string]interface{}) + i := make(map[string]any) if err := yaml.Unmarshal(b, &i); err != nil { return err } diff --git a/remote/http.go b/remote/http.go index da3a413af..6679a4325 100644 --- a/remote/http.go +++ b/remote/http.go @@ -88,7 +88,7 @@ func (c *client) Get(ctx context.Context, path string, query q) (*Response, erro } // Post executes a HTTP POST request. -func (c *client) Post(ctx context.Context, path string, data interface{}) (*Response, error) { +func (c *client) Post(ctx context.Context, path string, data any) (*Response, error) { b, err := json.Marshal(data) if err != nil { return nil, err @@ -242,7 +242,7 @@ func (r *Response) Read() ([]byte, error) { // BindJSON binds a given interface with the data returned in the response. This // is a shortcut for calling Read and then manually calling json.Unmarshal on // the raw bytes. -func (r *Response) BindJSON(v interface{}) error { +func (r *Response) BindJSON(v any) error { b, err := r.Read() if err != nil { return err diff --git a/remote/types.go b/remote/types.go index 08f0df332..7c5d63480 100644 --- a/remote/types.go +++ b/remote/types.go @@ -21,7 +21,7 @@ const ( // benefit from being a typed struct. // // Inspired by gin.H, same concept. -type d map[string]interface{} +type d map[string]any // Same concept as d, but a map of strings, used for querying GET requests. type q map[string]string diff --git a/router/router_server_backup.go b/router/router_server_backup.go index 4c3d337eb..a05d27b56 100644 --- a/router/router_server_backup.go +++ b/router/router_server_backup.go @@ -42,7 +42,7 @@ func postServerBackup(c *gin.Context) { // Attach the server ID and the request ID to the adapter log context for easier // parsing in the logs. - adapter.WithLogContext(map[string]interface{}{ + adapter.WithLogContext(map[string]any{ "server": s.ID(), "request_id": c.GetString("request_id"), }) diff --git a/router/websocket/websocket.go b/router/websocket/websocket.go index 4482667e6..1a66f88dc 100644 --- a/router/websocket/websocket.go +++ b/router/websocket/websocket.go @@ -191,7 +191,7 @@ func (h *Handler) SendJson(v Message) error { // Sends JSON over the websocket connection, ignoring the authentication state of the // socket user. Do not call this directly unless you are positive a response should be // sent back to the client! -func (h *Handler) unsafeSendJson(v interface{}) error { +func (h *Handler) unsafeSendJson(v any) error { h.Lock() defer h.Unlock() diff --git a/server/backup.go b/server/backup.go index 1568290d5..69ac1d153 100644 --- a/server/backup.go +++ b/server/backup.go @@ -78,7 +78,7 @@ func (s *Server) Backup(b backup.BackupInterface) error { s.Log().WithField("backup", b.Identifier()).Info("notified panel of failed backup state") } - s.Events().Publish(BackupCompletedEvent+":"+b.Identifier(), map[string]interface{}{ + s.Events().Publish(BackupCompletedEvent+":"+b.Identifier(), map[string]any{ "uuid": b.Identifier(), "is_successful": false, "checksum": "", @@ -102,7 +102,7 @@ func (s *Server) Backup(b backup.BackupInterface) error { // Emit an event over the socket so we can update the backup in realtime on // the frontend for the server. - s.Events().Publish(BackupCompletedEvent+":"+b.Identifier(), map[string]interface{}{ + s.Events().Publish(BackupCompletedEvent+":"+b.Identifier(), map[string]any{ "uuid": b.Identifier(), "is_successful": true, "checksum": ad.Checksum, diff --git a/server/backup/backup.go b/server/backup/backup.go index 01e73d0dd..342b039b0 100644 --- a/server/backup/backup.go +++ b/server/backup/backup.go @@ -45,7 +45,7 @@ type BackupInterface interface { Identifier() string // WithLogContext attaches additional context to the log output for this // backup. - WithLogContext(map[string]interface{}) + WithLogContext(map[string]any) // Generate creates a backup in whatever the configured source for the // specific implementation is. Generate(context.Context, *filesystem.Filesystem, string) (*ArchiveDetails, error) @@ -80,7 +80,7 @@ type Backup struct { client remote.Client adapter AdapterType - logContext map[string]interface{} + logContext map[string]any } func (b *Backup) SetClient(c remote.Client) { diff --git a/server/backup/backup_local.go b/server/backup/backup_local.go index 2351416f8..7d62e2989 100644 --- a/server/backup/backup_local.go +++ b/server/backup/backup_local.go @@ -53,7 +53,7 @@ func (b *LocalBackup) Remove() error { } // WithLogContext attaches additional context to the log output for this backup. -func (b *LocalBackup) WithLogContext(c map[string]interface{}) { +func (b *LocalBackup) WithLogContext(c map[string]any) { b.logContext = c } diff --git a/server/backup/backup_s3.go b/server/backup/backup_s3.go index e281ca70a..72fbfa82f 100644 --- a/server/backup/backup_s3.go +++ b/server/backup/backup_s3.go @@ -42,7 +42,7 @@ func (s *S3Backup) Remove() error { } // WithLogContext attaches additional context to the log output for this backup. -func (s *S3Backup) WithLogContext(c map[string]interface{}) { +func (s *S3Backup) WithLogContext(c map[string]any) { s.logContext = c } diff --git a/server/filesystem/archive.go b/server/filesystem/archive.go index 16ae7f9ed..ebd23ab5b 100644 --- a/server/filesystem/archive.go +++ b/server/filesystem/archive.go @@ -24,7 +24,7 @@ import ( const memory = 4 * 1024 var pool = sync.Pool{ - New: func() interface{} { + New: func() any { b := make([]byte, memory) return b }, diff --git a/sftp/event.go b/sftp/event.go index 2c4d85fa9..a0fff4f8c 100644 --- a/sftp/event.go +++ b/sftp/event.go @@ -28,7 +28,7 @@ type FileAction struct { // Log parses a SFTP specific file activity event and then passes it off to be stored // in the normal activity database. func (eh *eventHandler) Log(e models.Event, fa FileAction) error { - metadata := map[string]interface{}{ + metadata := map[string]any{ "files": []string{fa.Entity}, } if fa.Target != "" {