Browse Source

Add readme, badge, resolve issue with test

master
Tyler 3 years ago
parent
commit
3053714678
  1. 7
      README.md
  2. 2
      default_test.go
  3. 13
      linkinfo.go

7
README.md

@ -0,0 +1,7 @@
LinkInfo
--------
[![Build Status](https://drone.meow.tf/api/badges/tyler/linkinfo/status.svg)](https://drone.meow.tf/tyler/linkinfo)
An API/Library to get link information (Title, Description, etc)

2
default_test.go

@ -16,7 +16,7 @@ func Test_detectContentType(t *testing.T) {
contentType = contentType[:idx]
}
if contentType != ContentTypeHtml {
if contentType != contentTypeHtml {
t.Fatal("Unexpected content type:", contentType)
}
}

13
linkinfo.go

@ -10,6 +10,11 @@ type linkHandler struct {
handler func(link string) (*LinkInfo, error)
}
type LinkInfoApi struct {
client *http.Client
ImgurId string
}
type LinkInfo struct {
Title string `json:"title"`
Description string `json:"description"`
@ -20,14 +25,16 @@ type LinkInfo struct {
}
var (
Client = http.DefaultClient
linkHandlers = []*linkHandler{
{hosts: []string{"youtube.com", "youtu.be"}, handler: youtubeLinkHandler},
}
)
func Retrieve(link string) (*LinkInfo, error) {
func New() *LinkInfoApi {
return &LinkInfoApi{}
}
func (i *LinkInfoApi) Retrieve(link string) (*LinkInfo, error) {
u, err := url.Parse(link)
if err != nil {

Loading…
Cancel
Save