Skip to content

Commit

Permalink
refactor config
Browse files Browse the repository at this point in the history
  • Loading branch information
dezren39 committed Feb 23, 2024
1 parent db24dc3 commit dc9b239
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 180 deletions.
30 changes: 29 additions & 1 deletion sources/identity/auth/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetConnectionMap(ctx context.Context) (*SafeConnectionMap, bool) {
}

type SafeConnectionMap struct {
mu sync.RWMutex
mu sync.RWMutex // todo ristretto
data map[string]*Connection
}

Expand Down Expand Up @@ -123,6 +123,20 @@ func (sm *SafeConnectionMap) Values() []Connection {
return values
}

func (sm *SafeConnectionMap) ValuesUnique() []*Connection {
sm.mu.RLock()
defer sm.mu.RUnlock()
values := make([]*Connection, 0, len(sm.data))
unique := make(map[string]bool)
for _, v := range sm.data {
if _, ok := unique[*v.ConnectionID]; !ok {
unique[*v.ConnectionID] = true
values = append(values, v)
}
}
return values
}

// ValuesRef safely retrieves all values from the map
// Be careful with this, as it allows you to modify the map
func (sm *SafeConnectionMap) ValuesRef() []*Connection {
Expand All @@ -135,6 +149,20 @@ func (sm *SafeConnectionMap) ValuesRef() []*Connection {
return values
}

func (sm *SafeConnectionMap) ValuesRefUnique() []*Connection {
sm.mu.RLock()
defer sm.mu.RUnlock()
values := make([]*Connection, 0, len(sm.data))
unique := make(map[string]bool)
for _, v := range sm.data {
if _, ok := unique[*v.ConnectionID]; !ok {
unique[*v.ConnectionID] = true
values = append(values, v)
}
}
return values
}

// Connection represents a connection
type Connection struct {
ConnectionID *string
Expand Down
Loading

0 comments on commit dc9b239

Please sign in to comment.