string.go 759 B

123456789101112131415161718192021222324252627282930313233343536
  1. package session
  2. // IsSetString to check if variable exists
  3. func (s *Session) IsSetString(name string) bool {
  4. if _, ok := s.varlist.String[name]; ok {
  5. return true
  6. } else {
  7. return false
  8. }
  9. }
  10. // GetString returns stored variable value or default
  11. func (s *Session) GetString(name string, def string) string {
  12. if v, ok := s.varlist.String[name]; ok {
  13. return v
  14. } else {
  15. return def
  16. }
  17. }
  18. // SetString to set variable value
  19. func (s *Session) SetString(name string, value string) {
  20. isset := s.IsSetString(name)
  21. s.varlist.String[name] = value
  22. if isset || value != "" {
  23. s.changed = true
  24. }
  25. }
  26. // DelString to remove variable
  27. func (s *Session) DelString(name string) {
  28. if s.IsSetString(name) {
  29. delete(s.varlist.String, name)
  30. s.changed = true
  31. }
  32. }