Ubuntu Pastebin

Paste from Matteo Croce at Tue, 21 Jun 2016 11:54:44 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	out, err := os.Create("output.txt")
	defer out.Close()
	resp, err := http.Get("https://public.apps.ubuntu.com/anon/download-snap/b8X2psL1ryVrPt5WEmpYiqfr5emixTd7_123.snap")
	if err != nil {
		fmt.Printf("error %v\n", err);
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		fmt.Printf("HTTP error %d\n", resp.StatusCode);
		return
	}
	fmt.Printf("Downloading %d bytes\n", resp.ContentLength);
	n, err := io.Copy(out, resp.Body)
	fmt.Printf("%d copied\n", n);
}
Download as text