Commit 6ef30ef0 authored by zdc's avatar zdc

first demo

parents
package main
import (
"fmt"
"html/template"
"log"
"net/http"
)
func page01 (w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("page01.gtpl")
t.Execute(w, nil)
}
func doit (w http.ResponseWriter, r *http.Request) {
type data struct {
Command string
Items string
}
output := data{Command: r.PostFormValue("action"), Items: "Generated output for "+r.PostFormValue("argument")}
fmt.Println("router:", r.PostFormValue("router"))
fmt.Println("action:", r.PostFormValue("action"))
fmt.Println("argument:", r.PostFormValue("argument"))
fmt.Println(output)
t, _ := template.ParseFiles("page02.gtpl")
t.Execute(w, output)
}
func main() {
http.HandleFunc("/", page01) // setting router rule
http.HandleFunc("/do", doit) // setting router rule
//http.HandleFunc("/login", login)
fmt.Println("started")
err := http.ListenAndServe(":80", nil) // setting listening port
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
<html>
<head>
<title>Looking Glass</title>
</head>
<body>
<p>&nbsp;</p>
<form action="/do" method="post">
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td style="text-align: center;" colspan="3">
<p><strong>Looking Glass</strong></p>
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td>Router</td>
<td style="width: 50px;">&nbsp;</td>
<td>
<select name="router">
<option value="router01">router01</option>
<option value="router02">router02</option>
<option value="router03">router03</option>
</select>
</td>
</tr>
<tr>
<td>Action</td>
<td>&nbsp;</td>
<td>
<select name="action">
<option value="ping">ping</option>
<option value="traceroute">traceroute</option>
<option value="showroute">show route</option>
</select>
</td>
</tr>
<tr>
<td>Argument</td>
<td>&nbsp;</td>
<td><input name="argument" type="input" /></td>
</tr>
<tr>
<td style="text-align: center;" colspan="3">
<p>&nbsp;</p>
<p><input type="submit" value="Do it!" /></p>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
\ No newline at end of file
<html>
<head>
<title>Looking Glass</title>
</head>
<body>
<p><strong>Output for {{.Command}}</strong></p>
<pre>{{.Items}}</pre>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment