浏览代码

updated default routing

bmallred 10 年之前
父节点
当前提交
0df25426b6
共有 2 个文件被更改,包括 17 次插入7 次删除
  1. 5 5
      index.html
  2. 12 2
      main.go

+ 5 - 5
index.html

@ -61,12 +61,12 @@
61 61
</head>
62 62
<body>
63 63
    <div class="container">
64
        <form class="form-signin">
64
        <form action="/" method="post" class="form-signin">
65 65
            <h2 class="form-signin-heading">Please sign in</h2>
66
            <label for="inputEmail" class="sr-only">Email address</label>
67
            <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
68
            <label for="inputPassword" class="sr-only">Password</label>
69
            <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
66
            <label for="profile" class="sr-only">Email address</label>
67
            <input type="text" id="profile" name="profile" class="form-control" placeholder="Username" required autofocus>
68
            <label for="p" class="sr-only">Password</label>
69
            <input type="password" id="p" name="p" class="form-control" placeholder="Password" required>
70 70
            <div class="checkbox">
71 71
                <label>
72 72
                    <input type="checkbox" value="remember-me"> Remember me

+ 12 - 2
main.go

@ -164,8 +164,11 @@ func main() {
164 164
	})
165 165
166 166
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
167
		path := strings.TrimPrefix(r.URL.Path, "/")
168
		if path == "" {
167
		profile := r.FormValue("profile")
168
		passphrase := r.FormValue("p")
169
		//path := strings.TrimPrefix(r.URL.Path, "/")
170
171
		if profile == "" || passphrase == "" {
169 172
			// Index
170 173
			page, err := ioutil.ReadFile("index.html")
171 174
			if err != nil {
@ -176,6 +179,13 @@ func main() {
176 179
			fmt.Fprintf(w, string(page))
177 180
		} else {
178 181
			// A passphrase has been entered
182
			page, err := ioutil.ReadFile("book.html")
183
			if err != nil {
184
				http.NotFound(w, r)
185
				return
186
			}
187
188
			fmt.Fprintf(w, string(page))
179 189
		}
180 190
	})
181 191