Reintroduce duration function
This commit is contained in:
parent
ba1ae34465
commit
fa91a2fa81
18
pastebin.go
18
pastebin.go
|
@ -105,6 +105,17 @@ func Sha1(paste string) string {
|
||||||
return sha
|
return sha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DurationFromExpiry takes the expiry in string format and returns the duration
|
||||||
|
// that the paste will exist for
|
||||||
|
func DurationFromExpiry(expiry string) time.Duration {
|
||||||
|
dura, err := duration.FromString(expiry) // dura is time.Duration type
|
||||||
|
Check(err)
|
||||||
|
|
||||||
|
duration := dura.ToDuration()
|
||||||
|
|
||||||
|
return duration
|
||||||
|
}
|
||||||
|
|
||||||
// Save function handles the saving of each paste.
|
// Save function handles the saving of each paste.
|
||||||
// raw string is the raw paste input
|
// raw string is the raw paste input
|
||||||
// lang string is the user specified language for syntax highlighting
|
// lang string is the user specified language for syntax highlighting
|
||||||
|
@ -137,12 +148,7 @@ func Save(raw string, lang string, title string, expiry string) Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeFormat = "2006-01-02 15:04:05"
|
const timeFormat = "2006-01-02 15:04:05"
|
||||||
|
expiryTime := time.Now().Add(DurationFromExpiry(expiry)).Format(timeFormat)
|
||||||
dura, err := duration.FromString(expiry) // dura is time.Duration type
|
|
||||||
Check(err)
|
|
||||||
|
|
||||||
duration := dura.ToDuration()
|
|
||||||
expiryTime := time.Now().Add(duration).Format(timeFormat)
|
|
||||||
|
|
||||||
delKey := uniuri.NewLen(40)
|
delKey := uniuri.NewLen(40)
|
||||||
dataEscaped := html.EscapeString(raw)
|
dataEscaped := html.EscapeString(raw)
|
||||||
|
|
Loading…
Reference in New Issue