/////////////////////////////////////////////// //trying to figure out how to serve an image to a template, string //replacement works... but HTML template didn't yet package main import ( "fmt" //"net" "net/url" "net/http" //"html/template" "log" //"os" ) type MyImage struct { Url string } func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){ //fmt.Fprintf(w, "hello world") s := "http://davidsarma.org?image='https://dl.dropboxusercontent.com/u/7632896/dinosaur.png'" // Parse the URL and ensure there are no errors. u, err := url.Parse(s) if err != nil { panic(err) } //fmt.Println(u.RawQuery) m, _ := url.ParseQuery(u.RawQuery) //fmt.Println(m["image"][0]) /* //execute the template to return the image to the web page t := template.New("page") t, _ = t.Parse(webpage) img := MyImage{Url: m["image"][0]} log.Printf(m["image"][0]) t.Execute(w, img) */ fmt.Fprintf(w, webpage, m["image"][0]) }) log.Printf("Listening on port 9000") http.ListenAndServe(":9000", nil) } var webpage = `<html><body> <img src=%s> </body></html>`