Fix pb utility (#16)
* Update dependencies and go compile target version * Adds deletion support to the server * Add form around delete button * Add support for returning the url in curl * remove -config option for now * Upload as form value instead of file * remove dependencies from go mod * update to README re: new curl usage
This commit is contained in:
		@@ -7,6 +7,8 @@ import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
@@ -31,13 +33,22 @@ func (c *Client) Paste(body io.Reader) error {
 | 
			
		||||
	}
 | 
			
		||||
	client := &http.Client{Transport: tr}
 | 
			
		||||
 | 
			
		||||
	res, err := client.Post(c.url, contentType, body)
 | 
			
		||||
	buf := new(strings.Builder)
 | 
			
		||||
	_, err := io.Copy(buf, body)
 | 
			
		||||
	// check errors
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("error reading in file: %s", err)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	v := url.Values{}
 | 
			
		||||
	v.Set("blob", buf.String())
 | 
			
		||||
	res, err := client.PostForm(c.url, v)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("error pasting to %s: %s", c.url, err)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if res.StatusCode != 200 {
 | 
			
		||||
	if res.StatusCode != 200 && res.StatusCode != 301 {
 | 
			
		||||
		log.Printf("unexpected response from %s: %d", c.url, res.StatusCode)
 | 
			
		||||
		return errors.New("unexpected response")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user