Log in New API Help About

Using the dpaste.com API with Go

515 bytes of Go
Created 3 months, 1 week ago by dpaste.com
https://dpaste.com/6VSSDLMXV
SOFT WRAP RAW TEXT DUPLICATE DIFF
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
)

// Note: This example code ignores errors
func main() {
	data := url.Values{}
	data.Set("content", "Hello!")
	data.Set("syntax", "go")
	client := &http.Client{}
	r, _ := http.NewRequest("POST", "https://dpaste.com/api/",
		strings.NewReader(data.Encode()))
	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	res, _ := client.Do(r)
	body, _ := ioutil.ReadAll(res.Body)
	fmt.Println(string(body))
}