bool.go 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package session
  2. // IsSetBool to check if variable exists
  3. func (s *Session) IsSetBool(name string) bool {
  4. s.varlist.RLock()
  5. defer s.varlist.RUnlock()
  6. if _, ok := s.varlist.Bool[name]; ok {
  7. return true
  8. } else {
  9. return false
  10. }
  11. }
  12. // GetBool returns stored variable value or default
  13. func (s *Session) GetBool(name string, def bool) bool {
  14. s.varlist.RLock()
  15. defer s.varlist.RUnlock()
  16. if v, ok := s.varlist.Bool[name]; ok {
  17. return v
  18. } else {
  19. return def
  20. }
  21. }
  22. // SetBool to set variable value
  23. func (s *Session) SetBool(name string, value bool) {
  24. isset := s.IsSetBool(name)
  25. s.varlist.Lock()
  26. defer s.varlist.Unlock()
  27. s.varlist.Bool[name] = value
  28. if isset || value {
  29. s.changed = true
  30. }
  31. }
  32. // DelBool to remove variable
  33. func (s *Session) DelBool(name string) {
  34. if s.IsSetBool(name) {
  35. s.varlist.Lock()
  36. defer s.varlist.Unlock()
  37. delete(s.varlist.Bool, name)
  38. s.changed = true
  39. }
  40. }