Skip to content

Instantly share code, notes, and snippets.

@JosephGregg
Created October 8, 2016 07:15
Show Gist options
  • Save JosephGregg/97ff06879337da18af83878e7b5e9019 to your computer and use it in GitHub Desktop.
Save JosephGregg/97ff06879337da18af83878e7b5e9019 to your computer and use it in GitHub Desktop.
// 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