aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2022-04-24 18:53:32 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2022-04-24 18:53:32 +0200
commit79d3c2bfd95c5cb0ac6e4a3f97156161d792c676 (patch)
treecbfd034a362666b8dab842d3afed18cf95124ede
parent7822c9d443458ae9d1d9d678e279bfc516da7a8f (diff)
downloadfeed2imap-go-79d3c2bfd95c5cb0ac6e4a3f97156161d792c676.tar.gz
feed2imap-go-79d3c2bfd95c5cb0ac6e4a3f97156161d792c676.tar.bz2
feed2imap-go-79d3c2bfd95c5cb0ac6e4a3f97156161d792c676.zip
Replace `interface{}` by `any`
-rw-r--r--internal/feed/cache/cache.go2
-rw-r--r--internal/feed/cache/v1.go2
-rw-r--r--internal/feed/cache/v2.go2
-rw-r--r--internal/feed/item.go2
-rw-r--r--internal/feed/template/funcs.go6
-rw-r--r--internal/feed/template/funcs_test.go4
-rw-r--r--internal/feed/template/template.go2
-rw-r--r--internal/imap/connection.go4
-rw-r--r--pkg/config/body.go4
-rw-r--r--pkg/config/config.go6
-rw-r--r--pkg/config/deprecated.go6
-rw-r--r--pkg/log/log.go16
-rw-r--r--pkg/util/util.go4
13 files changed, 30 insertions, 30 deletions
diff --git a/internal/feed/cache/cache.go b/internal/feed/cache/cache.go
index 8029ee0..d13ae9a 100644
--- a/internal/feed/cache/cache.go
+++ b/internal/feed/cache/cache.go
@@ -29,7 +29,7 @@ type Impl interface {
store(io.Writer) error
Version() Version
Info() string
- SpecificInfo(interface{}) string
+ SpecificInfo(any) string
}
type Cache struct {
diff --git a/internal/feed/cache/v1.go b/internal/feed/cache/v1.go
index 1c64513..7d0d11b 100644
--- a/internal/feed/cache/v1.go
+++ b/internal/feed/cache/v1.go
@@ -137,7 +137,7 @@ func (cache *v1Cache) Info() string {
return b.String()
}
-func (cache *v1Cache) SpecificInfo(i interface{}) string {
+func (cache *v1Cache) SpecificInfo(i any) string {
id := idFromString(i.(string))
b := strings.Builder{}
diff --git a/internal/feed/cache/v2.go b/internal/feed/cache/v2.go
index 5d6ff9e..aab0f90 100644
--- a/internal/feed/cache/v2.go
+++ b/internal/feed/cache/v2.go
@@ -41,7 +41,7 @@ func (cache *v2Cache) Info() string {
return cache.asV1().Info()
}
-func (cache *v2Cache) SpecificInfo(i interface{}) string {
+func (cache *v2Cache) SpecificInfo(i any) string {
return cache.asV1().SpecificInfo(i)
}
diff --git a/internal/feed/item.go b/internal/feed/item.go
index 44e878c..79a971c 100644
--- a/internal/feed/item.go
+++ b/internal/feed/item.go
@@ -65,7 +65,7 @@ func (item *Item) FeedLink() string {
}
func (item *Item) AddReason(reason string) {
- if !util.StrContains(item.reasons, reason) {
+ if !util.Contains(item.reasons, reason) {
item.reasons = append(item.reasons, reason)
}
}
diff --git a/internal/feed/template/funcs.go b/internal/feed/template/funcs.go
index 30a2975..fbfb572 100644
--- a/internal/feed/template/funcs.go
+++ b/internal/feed/template/funcs.go
@@ -10,8 +10,8 @@ import (
)
// dict creates a map out of the passed in key/value pairs.
-func dict(v ...interface{}) map[string]interface{} {
- dict := make(map[string]interface{})
+func dict(v ...any) map[string]any {
+ dict := make(map[string]any)
lenv := len(v)
for i := 0; i < lenv; i += 2 {
key := v[i].(string)
@@ -63,7 +63,7 @@ func _html(s string) html.HTML {
return html.HTML(s)
}
-var funcMap = map[string]interface{}{
+var funcMap = map[string]any{
"dict": dict,
"join": join,
"lastUrlPart": lastUrlPart,
diff --git a/internal/feed/template/funcs_test.go b/internal/feed/template/funcs_test.go
index c75d27d..a5c25c3 100644
--- a/internal/feed/template/funcs_test.go
+++ b/internal/feed/template/funcs_test.go
@@ -31,8 +31,8 @@ func TestByteCount(t *testing.T) {
}
func TestDict(t *testing.T) {
- type i []interface{}
- type o map[string]interface{}
+ type i []any
+ type o map[string]any
tests := map[string]struct {
inp i
diff --git a/internal/feed/template/template.go b/internal/feed/template/template.go
index d66a8e4..4f17717 100644
--- a/internal/feed/template/template.go
+++ b/internal/feed/template/template.go
@@ -14,7 +14,7 @@ import (
)
type template interface {
- Execute(wr io.Writer, data interface{}) error
+ Execute(wr io.Writer, data any) error
Name() string
}
diff --git a/internal/imap/connection.go b/internal/imap/connection.go
index b93a61f..8c0f59c 100644
--- a/internal/imap/connection.go
+++ b/internal/imap/connection.go
@@ -125,7 +125,7 @@ func (conn *connection) ensureFolder(folder Folder) error {
}
switch {
- case found == 0 || (found == 1 && util.StrContains(mbox.Attributes, imap.NoSelectAttr)):
+ case found == 0 || (found == 1 && util.Contains(mbox.Attributes, imap.NoSelectAttr)):
return conn.createFolder(folder.str)
case found == 1:
conn.mailboxes.add(mbox)
@@ -137,7 +137,7 @@ func (conn *connection) ensureFolder(folder Folder) error {
func (conn *connection) delete(uids []uint32) error {
storeItem := imap.FormatFlagsOp(imap.AddFlags, true)
- deleteFlag := []interface{}{imap.DeletedFlag}
+ deleteFlag := []any{imap.DeletedFlag}
seqSet := new(imap.SeqSet)
seqSet.AddNum(uids...)
diff --git a/pkg/config/body.go b/pkg/config/body.go
index 3b2f676..17cf924 100644
--- a/pkg/config/body.go
+++ b/pkg/config/body.go
@@ -22,7 +22,7 @@ func (b *Body) UnmarshalYAML(node *yaml.Node) error {
val = "default"
}
- if !util.StrContains(validBody, val) {
+ if !util.Contains(validBody, val) {
return TypeError("line %d: Invalid value for 'body': %q", node.Line, val)
}
@@ -30,6 +30,6 @@ func (b *Body) UnmarshalYAML(node *yaml.Node) error {
return nil
}
-func TypeError(format string, v ...interface{}) *yaml.TypeError {
+func TypeError(format string, v ...any) *yaml.TypeError {
return &yaml.TypeError{Errors: []string{fmt.Sprintf(format, v...)}}
}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index a580337..a7c540f 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -13,7 +13,7 @@ import (
// Map is a convenience type for the non-mapped configuration options
// Mostly used for legacy options
-type Map map[string]interface{}
+type Map map[string]any
// GlobalOptions are not feed specific
type GlobalOptions struct {
@@ -108,12 +108,12 @@ func (cfg *Config) Validate() error {
// WithPartText marks whether 'text' part should be included in mails
func (opt GlobalOptions) WithPartText() bool {
- return util.StrContains(opt.Parts, "text")
+ return util.Contains(opt.Parts, "text")
}
// WithPartHtml marks whether 'html' part should be included in mails
func (opt GlobalOptions) WithPartHtml() bool {
- return util.StrContains(opt.Parts, "html")
+ return util.Contains(opt.Parts, "html")
}
// Load configuration from file and validate it
diff --git a/pkg/config/deprecated.go b/pkg/config/deprecated.go
index 44ed6f6..f373d5e 100644
--- a/pkg/config/deprecated.go
+++ b/pkg/config/deprecated.go
@@ -8,7 +8,7 @@ import (
type deprecated struct {
msg string
- handle func(interface{}, *GlobalOptions, *Options)
+ handle func(any, *GlobalOptions, *Options)
}
var unsupported = deprecated{
@@ -21,7 +21,7 @@ var deprecatedOpts = map[string]deprecated{
"debug-updated": {"Use '-d' as option instead.", nil},
"execurl": {"Use 'exec' instead.", nil},
"filter": {"Use 'item-filter' instead.", nil},
- "disable-ssl-verification": {"Interpreted as 'tls-no-verify'.", func(i interface{}, global *GlobalOptions, opts *Options) {
+ "disable-ssl-verification": {"Interpreted as 'tls-no-verify'.", func(i any, global *GlobalOptions, opts *Options) {
if val, ok := i.(bool); ok {
if val && !opts.NoTLS {
// do not overwrite the set NoTLS flag!
@@ -33,7 +33,7 @@ var deprecatedOpts = map[string]deprecated{
}},
}
-func handleDeprecated(option string, value interface{}, feed string, global *GlobalOptions, opts *Options) bool {
+func handleDeprecated(option string, value any, feed string, global *GlobalOptions, opts *Options) bool {
dep, ok := deprecatedOpts[option]
if !ok {
return false
diff --git a/pkg/log/log.go b/pkg/log/log.go
index b68d026..794cd09 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -33,45 +33,45 @@ func IsDebug() bool {
return level == debug
}
-func Debug(v ...interface{}) {
+func Debug(v ...any) {
if level <= debug {
_ = debugLogger.Output(2, fmt.Sprint(v...))
}
}
-func Debugf(format string, v ...interface{}) {
+func Debugf(format string, v ...any) {
if level <= debug {
_ = debugLogger.Output(2, fmt.Sprintf(format, v...))
}
}
-func Print(v ...interface{}) {
+func Print(v ...any) {
if level <= info {
_ = verboseLogger.Output(2, fmt.Sprint(v...))
}
}
-func Printf(format string, v ...interface{}) {
+func Printf(format string, v ...any) {
if level <= info {
_ = verboseLogger.Output(2, fmt.Sprintf(format, v...))
}
}
-func Error(v ...interface{}) {
+func Error(v ...any) {
_ = errorLogger.Output(2, fmt.Sprint(v...))
}
//noinspection GoUnusedExportedFunction
-func Errorf(format string, a ...interface{}) {
+func Errorf(format string, a ...any) {
_ = errorLogger.Output(2, fmt.Sprintf(format, a...))
}
//noinspection GoUnusedExportedFunction
-func Warn(v ...interface{}) {
+func Warn(v ...any) {
_ = warnLogger.Output(2, fmt.Sprint(v...))
}
//noinspection GoUnusedExportedFunction
-func Warnf(format string, a ...interface{}) {
+func Warnf(format string, a ...any) {
_ = warnLogger.Output(2, fmt.Sprintf(format, a...))
}
diff --git a/pkg/util/util.go b/pkg/util/util.go
index bacb494..cbc6014 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -2,8 +2,8 @@ package util
import "time"
-// StrContains searches for `needle` in `haystack` and returns `true` if found.
-func StrContains(haystack []string, needle string) bool {
+// Contains searches for `needle` in `haystack` and returns `true` if found.
+func Contains[T comparable](haystack []T, needle T) bool {
for _, s := range haystack {
if s == needle {
return true