Beispiel #1
0
func AnonymousExample(clientId, path string) {
	r := imgurgo.NewRequesterAnonymous(clientId)
	res, err := r.UploadImageFromPath(path)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(res)
}
Beispiel #2
0
func main() {
	clientId := os.Getenv("IMGURGO_CLIENTID")
	r := imgurgo.NewRequesterAnonymous(clientId)
	for _, p := range os.Args[1:] {
		img, err := r.UploadImageFromPath(p)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s\n", img.Link)
	}
}
Beispiel #3
0
func PinExample(clientId, clientSecret, path string) {
	r := imgurgo.NewRequesterAnonymous(clientId)

	// Wait for user to type PIN in to terminal.
	// The thing that really is relevant here, is the usage of SecretChan.
	go func() {
		rdr := bufio.NewReader(os.Stdin)
		fmt.Print("Please input PIN:")
		str, err := rdr.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}
		// Remove newline.
		r.Authorizer.SecretChan <- str[:len(str)-1]
	}()

	resp, err := r.UploadImageFromPath(path)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(resp)
}