// link的host func (l Link) Host() string { if !l.IsUrl() { return "" } //u, err := url.Parse(l.Context) //if err != nil { // return "" //} //if strings.Index(u.Host, "www.") == 0 { // return u.Host[4:] //} //return u.Host return utils.GetUrlHost(l.Context) }
//添加link到es搜索; contextType:0: url, 1:文本 func addLinkForSearch(contextType int, linkId int64, title string, context string, topics string, userName string) { m := make(map[string]interface{}) m["id"] = linkId m["title"] = title m["context"] = context m["topics"] = topics m["username"] = userName if contextType == 0 { m["host"] = utils.GetUrlHost(m["context"].(string)) m["context"] = "" } else { m["host"] = "" } ls := utils.LinkSearch{} _, err := ls.AddLink(m) if err != nil { fmt.Println("失败: ", m) } else { fmt.Println("成功: ", m) } }