I am learning golang and trying to make a simple website. This is my folder structure.
- ui
|
- login.html
- cmd
|
- main.go
My main.go
package main
import (
"html/template"
"net/http"
)
var tmpl *template.Template
func init() {
tmpl = template.Must(template.ParseFiles("../ui/login.html"))
}
func main() {
http.HandleFunc("/", foo)
http.ListenAndServe(":8080", nil)
}
func foo(reswt http.ResponseWriter, req *http.Request) {
tmpl.ExecuteTemplate(reswt, "../ui/login.html", nil)
}
login.html
<html>
<form method="POST">
<label for="uname">User Name</label>
<input type="text" id="uname" name="username">
<br>
<input type="submit">
</form>
</html>
When I executre main.go
, I do not get errors. But nothing on localhost:8080
.
If I keep main.go
and login.html
same folder, this works.
Why this folder structure is not working? I have tried [this SO thread], but this is not solving my problem1
Following parts added after css
is not working.
<style>
input[type=submit]:active {
background: #cde5ef;
border-color: #9eb9c2 #b3c0c8 #b4ccce;
-webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.2);
}
</style>
<div class="login">
<h1>Login to Web App</h1>
<form method="post" action="">
<p><input type="text" name="login" value="" placeholder="Username or Email"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="remember_me">
<label>
<input type="checkbox" name="remember_me" id="remember_me">
Remember me on this computer
</label>
</p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
</div>
<div class="login-help">
<p>Forgot your password? <a href="#">Click here to reset it</a>.</p>
</div>
When I go to localhost:8080
I get following output in my browser.
<style> input[type=submit]:active { background: #cde5ef; border-color: #9eb9c2 #b3c0c8 #b4ccce; -webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.2); box-shadow: inset 0 0 3px rgba(0, 0, 0,
0.2); } } </style>
<div class="login"> <h1>Login to Web App</h1> <form method="post" action="">
<p><input type="text" name="login" value="" placeholder="Username or Email"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="remember_me">
<label>
<input type="checkbox" name="remember_me" id="remember_me">
Remember me on this computer
</label>
</p>
<p class="submit"><input type="submit" name="commit" value="Login"></p> </form> </div>