///////////////////////////////////////////////
//now it works with HTML template. the problem was the single quotes around the image URL
//solution was to do strings.Replace
package main
import (
//"fmt"
//"net"
"net/url"
"net/http"
"html/template"
"log"
"os"
"strings"
)
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: strings.Replace(m["image"][0], "'", "", -1)}
//log.Printf(m["image"][0])
t.Execute(os.Stdout, img)
t.Execute(w, img)
//fmt.Fprintf(w, webpage, m["image"][0])
})
log.Printf("Listening on port 9000")
http.ListenAndServe(":9000", nil)
}