You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

values.go 942B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package caps
  4. import "sync"
  5. // Values holds capability values.
  6. type Values struct {
  7. sync.RWMutex
  8. // values holds our actual capability values.
  9. values map[Capability]string
  10. }
  11. // NewValues returns a new Values.
  12. func NewValues() *Values {
  13. return &Values{
  14. values: make(map[Capability]string),
  15. }
  16. }
  17. // Set sets the value for the given capability.
  18. func (v *Values) Set(capab Capability, value string) {
  19. v.Lock()
  20. defer v.Unlock()
  21. v.values[capab] = value
  22. }
  23. // Unset removes the value for the given capability, if it exists.
  24. func (v *Values) Unset(capab Capability) {
  25. v.Lock()
  26. defer v.Unlock()
  27. delete(v.values, capab)
  28. }
  29. // Get returns the value of the given capability, and whether one exists.
  30. func (v *Values) Get(capab Capability) (string, bool) {
  31. v.RLock()
  32. defer v.RUnlock()
  33. value, exists := v.values[capab]
  34. return value, exists
  35. }