utils

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModelMatches

func ModelMatches(modelName string, patterns []string) bool

ModelMatches 检查 modelName 是否匹配给定的模式列表。 空模式列表表示匹配所有模型。先尝试精确匹配,再尝试正则匹配(自动添加 ^$)。

func ValidateModelPatterns

func ValidateModelPatterns(patterns []string) error

ValidateModelPatterns 校验模式列表的合法性。

Types

type SyncMap

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SyncMap is like a Go sync.Map but type-safe using generics.

The zero SyncMap is empty and ready for use. A SyncMap must not be copied after first use.

func (*SyncMap[K, V]) Clear added in v0.0.16

func (s *SyncMap[K, V]) Clear()

Clear removes all entries while keeping the map ready for reuse.

func (*SyncMap[K, V]) Clone

func (s *SyncMap[K, V]) Clone() SyncMap[K, V]

Clone returns a copy (clone) of current SyncMap.

func (*SyncMap[K, V]) Delete

func (s *SyncMap[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*SyncMap[K, V]) Export

func (s *SyncMap[K, V]) Export() map[K]V

Export returns a copy of the map contents.

func (*SyncMap[K, V]) Grow

func (s *SyncMap[K, V]) Grow(size int)

Grow grows the map to the given size. It can be called before the first write operation used.

func (*SyncMap[K, V]) Keys

func (s *SyncMap[K, V]) Keys() []K

Keys return slice with all map keys.

func (*SyncMap[K, V]) Len

func (s *SyncMap[K, V]) Len() (l int)

Len returns the count of values in the map.

func (*SyncMap[K, V]) Load

func (s *SyncMap[K, V]) Load(key K) (value V, loaded bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*SyncMap[K, V]) LoadAndDelete

func (s *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*SyncMap[K, V]) LoadOrStore

func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*SyncMap[K, V]) Range

func (s *SyncMap[K, V]) Range(f func(key K, value V) (shouldContinue bool))

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once. Range does not block other methods on the receiver; even f itself may call any method on m.

func (*SyncMap[K, V]) Store

func (s *SyncMap[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*SyncMap[K, V]) ToMap

func (s *SyncMap[K, V]) ToMap() map[K]V

ToMap returns a copy of the map contents as a regular map.

func (*SyncMap[K, V]) Values

func (s *SyncMap[K, V]) Values() []V

Values return slice with all map values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL