瀏覽代碼

updated default routing

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

+ 5 - 5
index.html

61
</head>
61
</head>
62
<body>
62
<body>
63
    <div class="container">
63
    <div class="container">
64
        <form class="form-signin">
64
        <form action="/" method="post" class="form-signin">
65
            <h2 class="form-signin-heading">Please sign in</h2>
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
            <div class="checkbox">
70
            <div class="checkbox">
71
                <label>
71
                <label>
72
                    <input type="checkbox" value="remember-me"> Remember me
72
                    <input type="checkbox" value="remember-me"> Remember me

+ 12 - 2
main.go

164
	})
164
	})
165
165
166
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
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
			// Index
172
			// Index
170
			page, err := ioutil.ReadFile("index.html")
173
			page, err := ioutil.ReadFile("index.html")
171
			if err != nil {
174
			if err != nil {
176
			fmt.Fprintf(w, string(page))
179
			fmt.Fprintf(w, string(page))
177
		} else {
180
		} else {
178
			// A passphrase has been entered
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