package main import ( "fmt" "net/http" "net/url" "time" "github.com/PuerkitoBio/goquery" ) type Bookmark struct { Id int Name string Url *url.URL Desc string Tags []string Created time.Time LastUsed time.Time } func NewBookmark(url *url.URL) *Bookmark { // First, search for a bookmark with this same URL // If we didn't find one, create a new bookmark struct b := Bookmark{ Id: 0, Url: url, Created: time.Now(), } return &b } func (b *Bookmark) DownloadDetail() error { fmt.Println("Downloading Page: ", b.Url.String()) resp, err := http.Get(b.Url.String()) if err != nil { return err } defer resp.Body.Close() var doc *goquery.Document doc, err = goquery.NewDocumentFromResponse(resp) if err != nil { return err } title := doc.Find("title").Text() fmt.Println("Bookmark Title: " + title) metas := doc.Find("meta") metas.Each(func(i int, s *goquery.Selection) { // For each item, check the 'name' attr if v, has := s.Attr("name"); has { if v == "description" { str := s.Data fmt.Println(str) //b.Desc = s.Get(i) } } }) return nil } func (b *Bookmark) SetName(nm string) { b.Name = nm } func (b *Bookmark) SetUrl(url *url.URL) { b.Url = url } func (b *Bookmark) SetDescription(desc string) { b.Desc = desc } func (b *Bookmark) AddTag(tg string) { for _, v := range b.Tags { if v == tg { return } } b.Tags = append(b.Tags, tg) } func (b *Bookmark) RemoveTag(tg string) { remId := -1 for idx := range b.Tags { if b.Tags[idx] == tg { remId = idx break } } if remId >= 0 { b.Tags = append(b.Tags[:remId], b.Tags[remId+1:]...) } }