int64.go 923 B

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