Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc2 does not execute after doc1 #7

Open
sohamkumar05 opened this issue Jan 7, 2018 · 0 comments
Open

doc2 does not execute after doc1 #7

sohamkumar05 opened this issue Jan 7, 2018 · 0 comments

Comments

@sohamkumar05
Copy link

package main

import(
"net/http"
"io"
)

type statistic struct{
arr string
count int
Mean float32
Median float32
}

var integer []int
var cnt,i int
var sum,median float32

func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":9999", nil)
}

func hello(w http.ResponseWriter,r http.Request) {
s:= statistic{}
sum=0
w.Header().Set("Content-Type", "text/html")
switch r.Method {
case "GET":
/
display the form to the user */
io.WriteString(w, doc1 );
case "POST":
s.arr=r.FormValue("array")
for i:= range s.arr {
if s.arr[i]==0 {
continue
}
integer[i]=int(s.arr[i])
}
cnt=len(integer)
for i := range integer {
sum+=float32(integer[i])
}
s.count=cnt
s.Mean=float32(sum)/float32(cnt)
i=cnt%2
switch(i) {
case 0:
median=float32(integer[cnt/2]+integer[cnt/2-1])/2.0
break
case 1:
median=float32(integer[(cnt+1)/2])/2.0
break
}
s.Median=median
io.WriteString(w, doc2)
}
}

const doc1=`

<title></title>

Statistics

Computes basic statistics for the given list of numbers

`

const doc2=`

<title></title>

Statistics

Computes basic statistics for the given list of numbers

Numbers{{.arr}}
Count{{.count}}
Mean{{.Mean}}
Median{{.Median}}
`

for some reason once I click calculate on doc1,doc2 does not show up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant