mirror of
https://code.dumpstack.io/tools/wi.git
synced 2024-11-22 19:13:01 +00:00
Use existing links
This commit is contained in:
parent
37ae632189
commit
623a3d0f3a
11
main.go
11
main.go
@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
arg_url = kingpin.Flag("url", "Url").String()
|
arg_url = kingpin.Flag("url", "Url").String()
|
||||||
arg_link = kingpin.Flag("link", "Link").Int()
|
arg_link = kingpin.Flag("link", "Link").Int64()
|
||||||
)
|
)
|
||||||
|
|
||||||
func cmd_url(db *sql.DB, url string) {
|
func cmd_url(db *sql.DB, url string) {
|
||||||
@ -81,9 +81,12 @@ func cmd_url(db *sql.DB, url string) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
linkNo, err := storage.AddLink(db, url.String())
|
linkNo, err := storage.GetLinkID(db, url.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
linkNo, err = storage.AddLink(db, url.String())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range []string{string(value), html.EscapeString(string(value))} {
|
for _, s := range []string{string(value), html.EscapeString(string(value))} {
|
||||||
@ -107,7 +110,7 @@ func cmd_url(db *sql.DB, url string) {
|
|||||||
fmt.Println(text)
|
fmt.Println(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmd_link(db *sql.DB, linkID int) {
|
func cmd_link(db *sql.DB, linkID int64) {
|
||||||
url, err := storage.GetLink(db, linkID)
|
url, err := storage.GetLink(db, linkID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -42,7 +42,7 @@ func AddLink(db *sql.DB, url string) (linkNo int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLink(db *sql.DB, linkID int) (url string, err error) {
|
func GetLink(db *sql.DB, linkID int64) (url string, err error) {
|
||||||
stmt, err := db.Prepare("SELECT `url` FROM `links` WHERE id=$1;")
|
stmt, err := db.Prepare("SELECT `url` FROM `links` WHERE id=$1;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -53,3 +53,15 @@ func GetLink(db *sql.DB, linkID int) (url string, err error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLinkID(db *sql.DB, url string) (linkID int64, err error) {
|
||||||
|
stmt, err := db.Prepare("SELECT `id` FROM `links` WHERE url=$1;")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
err = stmt.QueryRow(url).Scan(&linkID)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user