Use any instead of interface{}

This commit is contained in:
eleksir
2025-04-07 20:50:49 +03:00
parent 30cb930a5e
commit 95a5033dfc
2 changed files with 7 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ type Collection struct {
// Item just interface for stoing any data. // Item just interface for stoing any data.
type item struct { type item struct {
data interface{} data any
} }
// NewCollection creates new instance of "collection". // NewCollection creates new instance of "collection".
@@ -25,7 +25,7 @@ func NewCollection() *Collection {
} }
// Get returns value by given key. Or empty value. // Get returns value by given key. Or empty value.
func (collection *Collection) Get(key interface{}) (interface{}, bool) { func (collection *Collection) Get(key any) (any, bool) {
obj, exists := collection.items.Load(key) obj, exists := collection.items.Load(key)
if !exists { if !exists {
@@ -38,15 +38,15 @@ func (collection *Collection) Get(key interface{}) (interface{}, bool) {
} }
// Set saves value to given "collection". // Set saves value to given "collection".
func (collection *Collection) Set(key interface{}, value interface{}) { func (collection *Collection) Set(key any, value any) {
collection.items.Store(key, item{ collection.items.Store(key, item{
data: value, data: value,
}) })
} }
// Range apply function f to all keys/values in collection. Retuns immediatly on first error. // Range apply function f to all keys/values in collection. Retuns immediatly on first error.
func (collection *Collection) Range(f func(key, value interface{}) bool) { func (collection *Collection) Range(f func(key, value any) bool) {
fn := func(key, value interface{}) bool { fn := func(key, value any) bool {
item := value.(item) item := value.(item)
return f(key, item.data) return f(key, item.data)
@@ -56,7 +56,7 @@ func (collection *Collection) Range(f func(key, value interface{}) bool) {
} }
// Delete deletes key and corresponding value from collection. // Delete deletes key and corresponding value from collection.
func (collection *Collection) Delete(key interface{}) { func (collection *Collection) Delete(key any) {
collection.items.Delete(key) collection.items.Delete(key)
} }

View File

@@ -302,7 +302,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
// then produced json unmarshal to struct. Not very effective way, but in app lifetime it happens only once. // then produced json unmarshal to struct. Not very effective way, but in app lifetime it happens only once.
var ( var (
sampleConfig *MyConfig sampleConfig *MyConfig
tmp map[string]interface{} tmp map[string]any
) )
err = hjson.Unmarshal(buf, &tmp) err = hjson.Unmarshal(buf, &tmp)