diff --git a/default_test.go b/default_test.go index e7c047d..3898c62 100644 --- a/default_test.go +++ b/default_test.go @@ -6,7 +6,7 @@ import ( ) func Test_LinkInfoApi_detectContentType(t *testing.T) { - api := &LinkInfoApi{} + api := New() contentType := api.detectContentType("http://example.com", "") @@ -31,11 +31,11 @@ func Test_LinkInfoApi_defaultLinkHandler(t *testing.T) { } testLinks := []expectedData{ - {"https://paste.ee", "Paste.ee", "text/html"}, + {"http://example.com", "Example Domain", "text/html"}, {"http://techslides.com/demos/sample-videos/small.mp4", "", "video/mp4"}, } - api := &LinkInfoApi{} + api := New() for _, link := range testLinks { l, err := api.DefaultLinkHandler(link.Link) @@ -57,7 +57,7 @@ func Test_LinkInfoApi_defaultLinkHandler(t *testing.T) { func Test_LinkInfoApi_retrieveHtmlLinkTitle(t *testing.T) { ret := &LinkInfo{} - api := &LinkInfoApi{} + api := New() if err := api.retrieveHtmlLinkTitle(ret, "http://example.com"); err != nil { t.Fatal("Unable to retrieve html link title:", err) diff --git a/linkinfo.go b/linkinfo.go index 816784d..b23e42f 100644 --- a/linkinfo.go +++ b/linkinfo.go @@ -3,6 +3,7 @@ package linkinfo import ( "net/http" "net/url" + "time" ) type LinkHandler struct { @@ -25,7 +26,11 @@ type LinkInfo struct { } func New() *LinkInfoApi { - api := &LinkInfoApi{} + api := &LinkInfoApi{ + Client: &http.Client{ + Timeout: 60 * time.Second, + }, + } api.registerDefaultHandlers()