Created
October 8, 2016 07:15
-
-
Save JosephGregg/97ff06879337da18af83878e7b5e9019 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// need to hack this in to onionscan | |
package main | |
import ( | |
"log" | |
"encoding/hex" | |
"fmt" | |
"net/http" | |
"crypto/sha1" | |
"io/ioutil" | |
) | |
const url = "http://i2.cdn.turner.com/cnnnext/dam/assets/161008002626-donald-trump-video-statement-overlay-tease.jpg" | |
type Body struct { | |
Bytes []byte | |
String string | |
} | |
func main() { | |
res, err := http.Get(url) | |
if err != nil { | |
log.Fatalf("http.Get-> %v", err) | |
} | |
// We read all the bytes of the image | |
// Types: data []byte | |
data, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
log.Fatalf("ioutil.ReadAll -> %v", err) | |
} | |
// You have to manually close the body, check docs | |
// This is required if you want to use things like | |
// Keep-Alive and other HTTP sorcery. | |
res.Body.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
image := string(data) | |
h := sha1.New() | |
h.Write([]byte(image)) | |
sha1_hash := hex.EncodeToString(h.Sum(nil)) | |
fmt.Println(url, sha1_hash) | |
// fmt.Println(len(image), len(image)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment