Browse Source

Move time to constant, code comments

Volodymyr Tkach 2 years ago
parent
commit
90ba9f233b
1 changed files with 8 additions and 3 deletions
  1. 8 3
      session/clean.go

+ 8 - 3
session/clean.go

@@ -7,6 +7,9 @@ import (
 	"time"
 )
 
+// Keep session files for 7 days
+const LifeTime = (24 * time.Hour) * 7
+
 // Clean to remove all local session files which not was used more than 24 hours
 func Clean(tmpdir string) error {
 	files, err := ioutil.ReadDir(tmpdir)
@@ -15,9 +18,11 @@ func Clean(tmpdir string) error {
 	}
 	for _, file := range files {
 		if len(file.Name()) == 40 {
-			if diff := time.Since(file.ModTime()); diff > ((24 * time.Hour) * 7) {
-				err = os.Remove(strings.Join([]string{tmpdir, file.Name()}, string(os.PathSeparator)))
-				if err != nil {
+			if diff := time.Since(file.ModTime()); diff > LifeTime {
+				if err := os.Remove(strings.Join(
+					[]string{tmpdir, file.Name()},
+					string(os.PathSeparator),
+				)); err != nil {
 					return err
 				}
 			}