util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AntMatcher

type AntMatcher struct {
	// contains filtered or unexported fields
}

AntMatcher is an implementation for Ant-style path patterns.

Standard Ant path matching URLs rules apply :

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path

Examples

  • "com/t?st.html" — matches "com/test.html" but also "com/tast.html" or "com/txst.html"
  • "com/*.html" — matches all .html files in the com directory
  • "com/**/test.html" — matches all test.html files underneath the com path
  • "com/beamfoundry/**/*.html" — matches all .html files underneath the org/beamfoundry path
  • "org/**/services/bla.html" — matches "org/beamfoundry/services/bla.html" but also "org/beamfoundry/testing/services/bla.html" and "org/services/bla.html"

func (*AntMatcher) Match

func (this *AntMatcher) Match(n []byte) bool

Match() returns whether the n byte slice match the pattern.

TODO: With 1.27 use generic method instead of two methods.

func (*AntMatcher) MatchString

func (this *AntMatcher) MatchString(s string) bool

MatchString() returns whether the s string match the pattern

TODO: With 1.27 use generic method instead of two methods.

func (AntMatcher) New

func (this AntMatcher) New(pattern string) (*AntMatcher, Error)

New() returns optionally and AntMatcher object pointer.

Internally the string pattern is transformed into a regexp.Regexp. In case the regexp compilation fails an github.com/BeamFoundry/rays/pkg/lang.Error will be returned.

func (*AntMatcher) String

func (this *AntMatcher) String() string

String() returns the original string passed to the constructor

type CaseUtils

type CaseUtils string

CaseUtils is a type redefinition of "string"

As such it can be constructed using the type name as a function.

Example :

CaseUtils("test").UpperCase().String() // Returns "TEST"

func (CaseUtils) Capitalize

func (this CaseUtils) Capitalize() CaseUtils

Capitalize() will change the first letter to uppercase case. No other letters are changed.

func (CaseUtils) LowerCase

func (this CaseUtils) LowerCase() CaseUtils

LowerCase() will convert all the characters to lower case

func (CaseUtils) SnakeCase

func (this CaseUtils) SnakeCase() CaseUtils

SnakeCase() will convert this string to a snake case format

func (CaseUtils) String

func (this CaseUtils) String() string

String() Returns a string version of this CaseUtils

func (CaseUtils) ToString

func (this CaseUtils) ToString() String

ToString() Returns a github.com/BeamFoundry/rays/pkg/lang.String version of this CaseUtils

func (CaseUtils) Uncapitalize

func (this CaseUtils) Uncapitalize() CaseUtils

Capitalize() will change the first letter to lowercase case. No other letters are changed.

func (CaseUtils) UpperCase

func (this CaseUtils) UpperCase() CaseUtils

UpperCase() will convert all the characters to upper case

type ConcurrentHashMap

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

ConcurrentHashMap is a Map implementation that is thread-safe

Internally it's just a [HasmMap] combined to a sync.RWMutex

TODO: Review lock.

func (*ConcurrentHashMap[K, V]) Clear

func (this *ConcurrentHashMap[K, V]) Clear()

Clear() implements Map.Clear

func (*ConcurrentHashMap[K, V]) ContainsKey

func (this *ConcurrentHashMap[K, V]) ContainsKey(key K) bool

ContainsKey() implements Map.ContainsKey

func (*ConcurrentHashMap[K, V]) Delete

func (this *ConcurrentHashMap[K, V]) Delete(f func(key K, val V) bool)

Delete() implements Map.Delete

func (*ConcurrentHashMap[K, V]) Equals

func (this *ConcurrentHashMap[K, V]) Equals(m Map[K, V]) bool

Equals() implements Map.Equals.

func (*ConcurrentHashMap[K, V]) Get

func (this *ConcurrentHashMap[K, V]) Get(key K) Optional[V]

Get() implements Map.Get

func (*ConcurrentHashMap[K, V]) IsEmpty

func (this *ConcurrentHashMap[K, V]) IsEmpty() bool

IsEmpty() implements Map.IsEmpty

func (*ConcurrentHashMap[K, V]) Iterator

func (this *ConcurrentHashMap[K, V]) Iterator() iter.Seq2[K, V]

Iterator() implements Map.Iterator

func (*ConcurrentHashMap[K, V]) Map

func (this *ConcurrentHashMap[K, V]) Map() map[K]V

Map() implements Map.Map

func (*ConcurrentHashMap[K, V]) MarshalJSON

func (this *ConcurrentHashMap[K, V]) MarshalJSON() ([]byte, error)

MashalJSON() implements json.Marshaler

func (*ConcurrentHashMap[K, V]) Merge

func (this *ConcurrentHashMap[K, V]) Merge(m Map[K, V])

Merge() implements Map.Merge.

func (ConcurrentHashMap[K, V]) New

func (this ConcurrentHashMap[K, V]) New() *ConcurrentHashMap[K, V]

New() creates a new ConcurrentHashMap

func (*ConcurrentHashMap[K, V]) Put

func (this *ConcurrentHashMap[K, V]) Put(key K, val V) Map[K, V]

Put() implements Map.Put

func (*ConcurrentHashMap[K, V]) PutAll

func (this *ConcurrentHashMap[K, V]) PutAll(m Map[K, V]) Map[K, V]

PutAll() implements Map.PutAll

func (*ConcurrentHashMap[K, V]) Remove

func (this *ConcurrentHashMap[K, V]) Remove(key K) Optional[V]

Remove() implements Map.Remove

func (*ConcurrentHashMap[K, V]) Size

func (this *ConcurrentHashMap[K, V]) Size() int

Size() implements Map.Size

func (*ConcurrentHashMap[K, V]) UnmarshalJSON

func (this *ConcurrentHashMap[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON() implements json.Unmarshal

type HashMap

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

HashMap is default Map implementation

func NewHashMap

func NewHashMap[K comparable, V any]() HashMap[K, V]

NewHashMap() creates a new, empty HashMap

func NewHashMapFor

func NewHashMapFor[K comparable, V any](m map[K]V) HashMap[K, V]

NewHashMapFor() encapsulate an existing map as a HashMap

func NewHashMapFrom

func NewHashMapFrom[K comparable, V any](m map[K]V) HashMap[K, V]

NewHashMapFrom() encapsulate an existing map as a HashMap and clones it.

func (HashMap[K, V]) Clear

func (this HashMap[K, V]) Clear()

Clear() implements Map.Clear

func (HashMap[K, V]) Clone

func (this HashMap[K, V]) Clone() HashMap[K, V]

Clone() clones the current map

func (HashMap[K, V]) ContainsKey

func (this HashMap[K, V]) ContainsKey(key K) bool

ContainsKey() implements Map.ContainsKey

func (HashMap[K, V]) Delete

func (this HashMap[K, V]) Delete(f func(key K, val V) bool)

Delete() implements Map.Delete

func (HashMap[K, V]) Equals

func (this HashMap[K, V]) Equals(m Map[K, V]) bool

Equals() implements Map.Equals.

It does it using reflect.DeepEqual

func (HashMap[K, V]) Get

func (this HashMap[K, V]) Get(key K) Optional[V]

Get() implements Map.Get

func (HashMap[K, V]) IsEmpty

func (this HashMap[K, V]) IsEmpty() bool

IsEmpty() implements Map.IsEmpty

func (HashMap[K, V]) Iterator

func (this HashMap[K, V]) Iterator() iter.Seq2[K, V]

Iterator() implements Map.Iterator

func (HashMap[K, V]) Map

func (this HashMap[K, V]) Map() map[K]V

Map() implements Map.Map

func (HashMap[K, V]) MarshalJSON

func (this HashMap[K, V]) MarshalJSON() ([]byte, error)

MashalJSON() implements json.Marshaler

func (HashMap[K, V]) Merge

func (this HashMap[K, V]) Merge(m Map[K, V])

Merge() implements Map.Merge.

func (HashMap[K, V]) Put

func (this HashMap[K, V]) Put(key K, val V) Map[K, V]

Put() implements Map.Put

func (HashMap[K, V]) PutAll

func (this HashMap[K, V]) PutAll(m Map[K, V]) Map[K, V]

PutAll() implements Map.PutAll

func (HashMap[K, V]) Remove

func (this HashMap[K, V]) Remove(key K) Optional[V]

Remove() implements Map.Remove

func (HashMap[K, V]) Size

func (this HashMap[K, V]) Size() int

Size() implements Map.Size

func (HashMap[K, V]) UnmarshalJSON

func (this HashMap[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON() implements json.Unmarshal

type Map

type Map[K comparable, V any] interface {
	// Map() returns a snapshot of the underlying map as a Go native map.
	//
	// This should be a shallow copy of the Map.
	Map() map[K]V

	// Clear() empty the map
	Clear()

	// ContainsKey() returns whether the map contains that key
	ContainsKey(key K) bool

	// Merge() will merge the given map
	//
	// To the difference of PutAll(), this will try to merge a map recusively.
	Merge(m Map[K, V])

	// Iterator() returns an iterator over the underlying map.
	//
	// This should be done over a snapshot (shallow copy) of the Map.
	Iterator() iter.Seq2[K, V]

	// Equals() returns whether a Map equals to this one.
	Equals(m Map[K, V]) bool

	// Get() returns optionally the requested key
	Get(key K) Optional[V]

	// Remove() returns optionally the requested key after removing it from the map
	Remove(key K) Optional[V]

	// Delete() apply a filter to remove key/values from the map
	Delete(f func(key K, val V) bool)

	// IsEmpty() returns whether the Map is empty or not
	IsEmpty() bool

	// Put() add (or replace) a key/value in the Map.
	Put(key K, val V) Map[K, V]

	// PutAll() merge the given Map and returns it.
	//
	// To the difference of Merge() this will replace existing key without merging Map entry of the same type.
	PutAll(m Map[K, V]) Map[K, V]

	// Size() returns the size of the Map
	Size() int
}

Map is an interface for an object oriented map.

TODO: Add Clone and JSON Marshaler/Unmarshaler ???

Jump to

Keyboard shortcuts

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