session.go 693 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "time"
  6. "golang-fave/utils"
  7. "github.com/vladimirok5959/golang-server-sessions/session"
  8. )
  9. func session_clean_start(www_dir string) chan bool {
  10. ch := make(chan bool)
  11. go func() {
  12. for {
  13. select {
  14. case <-time.After(1 * time.Hour):
  15. files, err := ioutil.ReadDir(www_dir)
  16. if err == nil {
  17. for _, file := range files {
  18. tmpdir := www_dir + string(os.PathSeparator) + file.Name() + string(os.PathSeparator) + "tmp"
  19. if utils.IsDirExists(tmpdir) {
  20. session.Clean(tmpdir)
  21. }
  22. }
  23. }
  24. case <-ch:
  25. ch <- true
  26. return
  27. }
  28. }
  29. }()
  30. return ch
  31. }
  32. func session_clean_stop(ch chan bool) {
  33. ch <- true
  34. <-ch
  35. }