int.go 889 B

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