I'm new to Golang and I am trying to move data from an action field to a struct.
My func main is:
func main () {
http.HandleFunc("/public/", func (w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:]) })
http.HandleFunc("/public/new_user/", signup)
http.ListenAndServe(":8080", nil)
}
// struct for recieving Signup data input from signup.html
type Signup struct {
name string
email string
}
// func to receive data into struc above FROM signup.html
func signup(w http.ResponseWriter, r *http.Request) {
var S Signup
S.name = r.FormValue("name")
S.email = r.FormValue("email")
//this is just to test the output
fmt.Println("%v
", S.name)
fmt.Println("%v
", S.email)
}
I have http.HandleFunc("public/new_user/", signup)
which should render the signup
function. However, I am receiving a BLANK html page when I route to public/new_user
instead of receiving the struct from func signup.
The S.name = r.FormValue("name")
and S.email = r.FormValue("email")
lines ABOVE are getting their info from the signup page which is:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
</head>
<body>
<h1>Sign Up</h1>
<br/>
<form action="/public/new_user" method="post" id="form1">
<label>Name:</label>
<input type="string" name="name" />
</br>
</br>
<label>Email:</label>
<input type="string" name="email" />
</form>
</br>
<button type="submit" form="form1" value="Submit">Submit</button>
</body>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</html>
As you can see, this page routes to public/new_user
upon submit. Can anyone please tell me why public/new_user
is blank seeing as how I have public/new_user
in:
http.HandleFunc("/public/new_user/", signup)
Which should render the signup function? Thanks