From 5242324a6094879ad14826299ed5aa4fe8d9e761 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 15 Jul 2016 12:12:09 +1000 Subject: [PATCH] Rewrite DurationFromExpiry function --- assets/clone.html | 20 ++++++++++---------- assets/index.html | 15 +++++++-------- database.sql | 2 +- pastebin.go | 21 ++++----------------- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/assets/clone.html b/assets/clone.html index f211b74..5857ed9 100644 --- a/assets/clone.html +++ b/assets/clone.html @@ -449,23 +449,23 @@ - + + Home Download Raw Clone - + diff --git a/assets/index.html b/assets/index.html index 0b661a3..5ae2722 100644 --- a/assets/index.html +++ b/assets/index.html @@ -450,16 +450,15 @@ - + diff --git a/database.sql b/database.sql index 4bde569..3adb90b 100644 --- a/database.sql +++ b/database.sql @@ -4,6 +4,6 @@ CREATE TABLE `pastebin` ( `hash` char(40) default NULL, `data` longtext, `delkey` char(40) default NULL, - `expiry` TIMESTAMP, + `expiry` DATETIME, PRIMARY KEY (`id`) ); diff --git a/pastebin.go b/pastebin.go index 37e30f7..60752e1 100644 --- a/pastebin.go +++ b/pastebin.go @@ -14,6 +14,7 @@ import ( "io/ioutil" "log" "net/http" + "strconv" "time" // uniuri is used for easy random string generation @@ -107,23 +108,9 @@ func Sha1(paste string) string { // DurationFromExpiry takes the expiry in string format and returns the duration // that the paste will exist for func DurationFromExpiry(expiry string) time.Duration { - switch expiry { - case "5 minutes": - return time.Minute * 5 - case "1 hour": - return time.Hour + 1 // XXX: did you mean '*'? - case "1 day": - return time.Hour * 24 - case "1 week": - return time.Hour * 24 * 7 - case "1 month": - return time.Hour * 24 * 30 - case "1 year": - return time.Hour * 24 * 365 - case "forever": - return time.Hour * 24 * (365 * 20) - } - return time.Hour * 24 * (365 * 20) + i, err := strconv.ParseInt(expiry, 10, 64) + Check(err) + return time.Hour * time.Duration(i) } // Save function handles the saving of each paste.