-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
824b972
commit 6b45ef4
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func helloHandlder(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/hello" { | ||
http.Error(w, "404 Not found", http.StatusNotFound) | ||
return | ||
} | ||
|
||
if r.Method != "GET" { | ||
http.Error(w, "method is not supported", http.StatusNotFound) | ||
} | ||
|
||
fmt.Fprintf(w, "Hello!!!") | ||
} | ||
func formHandlder(w http.ResponseWriter, r *http.Request) { | ||
if err := r.ParseForm(); err != nil { | ||
fmt.Fprintf(w, "ParseForm() err : %v", err) | ||
return | ||
} | ||
fmt.Fprintf(w, "POST request successful\n") | ||
name := r.FormValue("name") | ||
address := r.FormValue("address") | ||
fmt.Fprintf(w, "Name = %s\n", name) | ||
fmt.Fprintf(w, "Address = %s\n", address) | ||
} | ||
|
||
func main() { | ||
fileServer := http.FileServer(http.Dir("./static")) | ||
http.Handle("/", fileServer) | ||
http.HandleFunc("/form", formHandlder) | ||
http.HandleFunc("/hello", helloHandlder) | ||
|
||
fmt.Printf("Starting server at port 8080\n") | ||
if err := http.ListenAndServe(":8080", nil); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<form method="POST" action="/form"> | ||
<label>Name</label> <input name = "name" type="text" value=""/> | ||
<label>Address</label> <input name = "address" type="text" value=""/> | ||
|
||
<input type="submit" value="submit"> | ||
</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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Static Website</title> | ||
</head> | ||
<body> | ||
<h2>Static website</h2> | ||
</body> | ||
</html> |