goestoeleven / go_web_app Goto Github PK
View Code? Open in Web Editor NEWgo_web_app
go_web_app
Hello,
I have looked this over and everything appears to be working normally. Did you make a change? When I ran the app and navigated to http://localhost:8080/home, the page loaded just like I expected. Please let me know if you are still having issues.
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>
Computes basic statistics for the given list of numbers
const doc2=`
<title></title>
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
Hi, I've seen your youtube video, I like your project and way you talk about go, good job!
I can help you with git.
This should be applied to each branch:
It is a good practise NOT to commit .idea directory to git project ;)
Content-Type is misspelled causing everything delivered as text/plain.
https://github.com/GoesToEleven/go_web_app/blob/06_set_content_type/src/main/main.go
line 35 says:
w.Header().Add("Content Type", contentType)
and should say:
w.Header().Add("Content-Type", contentType)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.