From 0c7138250b4cf02793fe57b8b2e220fa88dfecaf Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Sun, 15 Nov 2020 12:02:07 +0000 Subject: [PATCH 1/3] fix pastebin.com's URL --- pastebin/pastebin.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pastebin/pastebin.go b/pastebin/pastebin.go index 8d13263..43098a5 100644 --- a/pastebin/pastebin.go +++ b/pastebin/pastebin.go @@ -3,6 +3,7 @@ package pastebin import ( + "fmt" "errors" "io/ioutil" "net/http" @@ -36,18 +37,18 @@ func (p Pastebin) Put(text, title string) (id string, err error) { data.Set("api_paste_private", "0") // Create a public paste. data.Set("api_paste_expire_date", "N") // The paste should never expire. - resp, err := http.PostForm("http://pastebin.com/api/api_post.php", data) + resp, err := http.PostForm("https://pastebin.com/api/api_post.php", data) if err != nil { return "", err } - if resp.StatusCode != 200 { - return "", ErrPutFailed - } defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } + if resp.StatusCode != 200 { + return "", fmt.Errorf("%w: %s", ErrPutFailed, string(respBody)) + } return p.StripURL(string(respBody)), nil } From 26563eff1d8f0b463e00144beb870c43b56cec07 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Sun, 15 Nov 2020 12:15:09 +0000 Subject: [PATCH 2/3] pastebin.com uses HTTPS --- pastebin/pastebin.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pastebin/pastebin.go b/pastebin/pastebin.go index 43098a5..7f804c1 100644 --- a/pastebin/pastebin.go +++ b/pastebin/pastebin.go @@ -3,8 +3,8 @@ package pastebin import ( - "fmt" "errors" + "fmt" "io/ioutil" "net/http" "net/url" @@ -12,6 +12,7 @@ import ( ) const ( + baseURL = "https://pastebin.com/" pastebinDevKey = "d06a9df64b29123b8eeda23f53d6535d" ) @@ -37,7 +38,7 @@ func (p Pastebin) Put(text, title string) (id string, err error) { data.Set("api_paste_private", "0") // Create a public paste. data.Set("api_paste_expire_date", "N") // The paste should never expire. - resp, err := http.PostForm("https://pastebin.com/api/api_post.php", data) + resp, err := http.PostForm(baseURL+"api/api_post.php", data) if err != nil { return "", err } @@ -54,7 +55,7 @@ func (p Pastebin) Put(text, title string) (id string, err error) { // Get returns the text inside the paste identified by ID. func (p Pastebin) Get(id string) (text string, err error) { - resp, err := http.Get("http://pastebin.com/raw.php?i=" + id) + resp, err := http.Get(baseURL + "raw.php?i=" + id) if err != nil { return "", err } @@ -71,7 +72,7 @@ func (p Pastebin) Get(id string) (text string, err error) { // StripURL returns the paste ID from a pastebin URL. func (p Pastebin) StripURL(url string) string { - return strings.Replace(url, "http://pastebin.com/", "", -1) + return strings.Replace(url, baseURL, "", -1) } // WrapID returns the pastebin URL from a paste ID. From e8879f7c7a58f1efa2485a0bca559bcd36cd02ef Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Sun, 15 Nov 2020 15:56:42 +0000 Subject: [PATCH 3/3] Update pastebin.go --- pastebin/pastebin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pastebin/pastebin.go b/pastebin/pastebin.go index 7f804c1..f9dadd2 100644 --- a/pastebin/pastebin.go +++ b/pastebin/pastebin.go @@ -77,5 +77,5 @@ func (p Pastebin) StripURL(url string) string { // WrapID returns the pastebin URL from a paste ID. func (p Pastebin) WrapID(id string) string { - return "http://pastebin.com/" + id + return baseURL + id }