Add readme, badge, resolve issue with test
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Tyler 2019-10-03 20:50:58 -04:00
parent 580a1c2fb0
commit 3053714678
3 changed files with 18 additions and 4 deletions

7
README.md Normal file
View File

@ -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)

View File

@ -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)
}
}

View File

@ -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 {