I am trying to draw to a webserver using this: The basics is that when I run it gives error "undefined: canvas". I believe its because the "canvas = svg.New(w)" is located within the "func draw()" and there are other calls of the canvas in "func sqre ()" and other functions similiar "TRI()" "CIR()" etc.. How can I fix this?
func sqre(){ //Square Function
var xcoord =100
var ycoord =150
canvas.Rect(xcoord, ycoord, 250,150,"fill:none ;stroke:blue")
func draw(w http.ResponseWriter, req *http.Request) { //handler function
w.header().Set("Content-Type", "image/svg+xml")
canvas = svg.New(w)
canvas.Start(width,height)
var x int
for x=0; stringarray[x] != "finish"; {
switch stringarray[x] {
case "SQR":
Sqre()
x=x+1
case "TRI":
Tri()
x=x+1
case "GRID":
Grid()
x=x+1
case "FILL":
Filler()
x=x+1
case "CIR":
Cir()
x=x+1
default:
x=x+1
}
}
canvas.End()
}
func main(){
http.Handle ("/draw",http.Handlerfunc(draw))
err := http.ListenAndServe(":2014", nil)
if err !=nil{
log.Fatal("ListenAndServe:", err)
}
}