From 106fcbf95a21df63dd422f01ee6935d05543fda1 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Sat, 24 Mar 2018 11:50:21 -0400 Subject: [PATCH 1/2] deprecate NewDocument and NewDocumentFromResponse --- type.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/type.go b/type.go index e2169fa..6ad51db 100644 --- a/type.go +++ b/type.go @@ -31,6 +31,10 @@ func NewDocumentFromNode(root *html.Node) *Document { // NewDocument is a Document constructor that takes a string URL as argument. // It loads the specified document, parses it, and stores the root Document // node, ready to be manipulated. +// +// Deprecated: Use the net/http standard library package to make the request +// and validate the response before calling goquery.NewDocumentFromReader +// with the response's body. func NewDocument(url string) (*Document, error) { // Load the URL res, e := http.Get(url) @@ -40,10 +44,10 @@ func NewDocument(url string) (*Document, error) { return NewDocumentFromResponse(res) } -// NewDocumentFromReader returns a Document from a generic reader. +// NewDocumentFromReader returns a Document from an io.Reader. // It returns an error as second value if the reader's data cannot be parsed -// as html. It does *not* check if the reader is also an io.Closer, so the -// provided reader is never closed by this call, it is the responsibility +// as html. It does not check if the reader is also an io.Closer, the +// provided reader is never closed by this call. It is the responsibility // of the caller to close it if required. func NewDocumentFromReader(r io.Reader) (*Document, error) { root, e := html.Parse(r) @@ -56,6 +60,8 @@ func NewDocumentFromReader(r io.Reader) (*Document, error) { // NewDocumentFromResponse is another Document constructor that takes an http response as argument. // It loads the specified response's document, parses it, and stores the root Document // node, ready to be manipulated. The response's body is closed on return. +// +// Deprecated: Use goquery.NewDocumentFromReader with the response's body. func NewDocumentFromResponse(res *http.Response) (*Document, error) { if res == nil { return nil, errors.New("Response is nil") From b4912d23e5dc8c3464b4e04f2d1f9260251863ac Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Sat, 24 Mar 2018 11:52:59 -0400 Subject: [PATCH 2/2] document the new release --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b7bf488..fba004d 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Please note that because of the net/html dependency, goquery requires Go1.1+. **Note that goquery's API is now stable, and will not break.** +* **2018-03-24 (v1.4.0)** : Deprecate `NewDocument(url)` and `NewDocumentFromResponse(response)`. * **2018-01-28 (v1.3.0)** : Add `ToEnd` constant to `Slice` until the end of the selection (thanks to @davidjwilkins for raising the issue). * **2018-01-11 (v1.2.0)** : Add `AddBack*` and deprecate `AndSelf` (thanks to @davidjwilkins). * **2017-02-12 (v1.1.0)** : Add `SetHtml` and `SetText` (thanks to @glebtv).