Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
25
pkg/redis/set.go
Normal file
25
pkg/redis/set.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package redis
|
||||
|
||||
// Set represents a set object using a map of empty structs
|
||||
type Set map[string]void
|
||||
type void struct{}
|
||||
|
||||
var member void
|
||||
|
||||
// Add id to the set, returns false if id exists
|
||||
func (s Set) Add(id string) bool {
|
||||
if _, ok := s[id]; ok {
|
||||
return false
|
||||
}
|
||||
s[id] = member
|
||||
return true
|
||||
}
|
||||
|
||||
// Remove id from the set, return false if id doesn't exist
|
||||
func (s Set) Remove(id string) bool {
|
||||
if _, ok := s[id]; !ok {
|
||||
return false
|
||||
}
|
||||
delete(s, id)
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user