Esempio n. 1
0
func main() {
	// middleware
	middle := interpose.New()
	middle.Use(adaptors.FromNegroni(cors.New(cors.Options{
		// CORS
		AllowedOrigins: []string{"*"},
	})))

	// router
	router := pat.New()
	middle.UseHandler(router)

	router.Get("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		url := r.URL.Query().Get("url")

		if url != "" {
			encoded := imgbase64.FromRemote(url)
			fmt.Fprint(w, encoded)
		} else {
			fmt.Fprint(w, "/?url=<your-image-url> returns the base64 data-URI of that image.")
		}
	}))

	// listen
	port := os.Getenv("PORT")
	if port == "" {
		port = "5000"
	}
	log.Print("listening...")
	http.ListenAndServe(":"+port, middle)
}
Esempio n. 2
0
// For this example a DefaultImage will not be set
func main() {
	img := imgbase64.FromRemote("https://s3.amazonaws.com/uploads.hipchat.com/46533/311662/7rcjJ1KHy128Dxv/transparent.png")

	fmt.Println(img)
}