-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Luo
committed
Jun 19, 2019
1 parent
0ab4cb7
commit 3733a44
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<title>Sean's Super Cool Web App</title> | ||
|
||
<body> | ||
<form action="/signup" method="POST"> | ||
<input type="text" name="username" placeholder="Enter Name"> | ||
<input type="submit" value="Check-In"/> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"net/http" | ||
) | ||
|
||
var homeT = template.Must(template.ParseFiles("home.html")) | ||
|
||
var table = map[string]int{} // global table to hold usernames and counts of visits | ||
|
||
func home(w http.ResponseWriter, r *http.Request) { | ||
homeT.Execute(w, nil) | ||
|
||
r.ParseForm() | ||
visitor := r.Form.Get("username") //hold current visitor name | ||
|
||
if count, isIn := table[visitor]; isIn { | ||
table[visitor] = count + 1 // user has been seen before, increment count | ||
} else { | ||
table[visitor] = 1 // new user, add to dict | ||
} | ||
|
||
for name, count := range table { | ||
fmt.Fprintf(w, "<b>User:</b> %v <b>Visits:</b> %v <br><br>", name, count) // print name and # of times visited | ||
} | ||
|
||
} | ||
|
||
func main() { | ||
http.HandleFunc("/", home) // handle all pages with home() | ||
http.ListenAndServe(":8080", nil) // see web app by visiting "localhost:8080" | ||
} |