mirror of
https://code.dumpstack.io/tools/wi.git
synced 2024-11-22 19:13:01 +00:00
Implements follow link from history
This commit is contained in:
parent
159907723b
commit
fd1e14128e
@ -126,8 +126,17 @@ func Get(db *sql.DB, url string) {
|
||||
fmt.Println(text)
|
||||
}
|
||||
|
||||
func Link(db *sql.DB, linkID int64) {
|
||||
url, err := storage.GetLink(db, linkID)
|
||||
func Link(db *sql.DB, linkID int64, fromHistory bool) {
|
||||
|
||||
var url string
|
||||
var err error
|
||||
|
||||
if fromHistory {
|
||||
url, err = storage.GetHistoryUrl(db, linkID)
|
||||
} else {
|
||||
url, err = storage.GetLink(db, linkID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -21,6 +21,7 @@ var (
|
||||
|
||||
link = kingpin.Command("link", "Get link")
|
||||
linkNo = link.Arg("no", "Number").Required().Int64()
|
||||
linkFromHistory = link.Flag("history", "Item from history").Bool()
|
||||
|
||||
historyList = kingpin.Command("history", "List history")
|
||||
historyListItems = historyList.Arg("items", "Amount of items").Int64()
|
||||
@ -38,7 +39,7 @@ func main() {
|
||||
case "get":
|
||||
commands.Get(db, *getUrl)
|
||||
case "link":
|
||||
commands.Link(db, *linkNo)
|
||||
commands.Link(db, *linkNo, *linkFromHistory)
|
||||
case "history":
|
||||
commands.History(db, *historyListItems, 20, *historyListAll)
|
||||
}
|
||||
|
@ -109,3 +109,15 @@ func GetHistory(db *sql.DB) (history []HistoryItem, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetHistoryUrl(db *sql.DB, historyID int64) (url string, err error) {
|
||||
stmt, err := db.Prepare("SELECT `url` FROM `history` WHERE id=$1;")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
err = stmt.QueryRow(historyID).Scan(&url)
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user