Add expiryTime to sql query
This commit is contained in:
parent
63dff38c3c
commit
d17154b353
20
main.go
20
main.go
|
@ -38,7 +38,6 @@ type Response struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
SIZE int `json:"size"`
|
SIZE int `json:"size"`
|
||||||
DELKEY string `json:"delkey"`
|
DELKEY string `json:"delkey"`
|
||||||
EXPIRY time.Time `json:"expiry"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
|
@ -109,34 +108,35 @@ func save(raw string, lang string, title string, expiry string) []string {
|
||||||
url = ADDRESS + "/p/" + id + "/" + lang
|
url = ADDRESS + "/p/" + id + "/" + lang
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
var expiryTime string
|
||||||
|
|
||||||
switch expiry {
|
switch expiry {
|
||||||
case "5 minutes":
|
case "5 minutes":
|
||||||
expiry := now.Add(time.Minute * 5).Format(time.RFC3339)
|
expiryTime = now.Add(time.Minute * 5).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "1 hour":
|
case "1 hour":
|
||||||
expiry := now.Add(time.Hour + 1).Format(time.RFC3339)
|
expiryTime = now.Add(time.Hour + 1).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "1 day":
|
case "1 day":
|
||||||
expiry := now.Add(time.Hour * 24 * 1).Format(time.RFC3339)
|
expiryTime = now.Add(time.Hour * 24 * 1).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "1 week":
|
case "1 week":
|
||||||
expiry := now.Add(time.Hour * 24 * 7).Format(time.RFC3339)
|
expiryTime = now.Add(time.Hour * 24 * 7).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "1 month":
|
case "1 month":
|
||||||
expiry := now.Add(time.Hour * 24 * 30).Format(time.RFC3339)
|
expiryTime = now.Add(time.Hour * 24 * 30).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "1 year":
|
case "1 year":
|
||||||
expiry := now.Add(time.Hour * 24 * 365).Format(time.RFC3339)
|
expiryTime = now.Add(time.Hour * 24 * 365).Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
expiry := now.Format(time.RFC3339)
|
expiryTime = now.Format(time.RFC3339)
|
||||||
break
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,10 +146,10 @@ func save(raw string, lang string, title string, expiry string) []string {
|
||||||
stmt, err := db.Prepare("INSERT INTO pastebin(id, title, hash, data, delkey, expiry) values(?,?,?,?,?,?)")
|
stmt, err := db.Prepare("INSERT INTO pastebin(id, title, hash, data, delkey, expiry) values(?,?,?,?,?,?)")
|
||||||
check(err)
|
check(err)
|
||||||
if title == "" {
|
if title == "" {
|
||||||
_, err = stmt.Exec(id, id, sha, paste, delKey, expiry)
|
_, err = stmt.Exec(id, id, sha, paste, delKey, expiryTime)
|
||||||
check(err)
|
check(err)
|
||||||
} else {
|
} else {
|
||||||
_, err = stmt.Exec(id, html.EscapeString(title), sha, paste, delKey, expiry)
|
_, err = stmt.Exec(id, html.EscapeString(title), sha, paste, delKey, expiryTime)
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
Loading…
Reference in New Issue