Move HTML to template

This commit is contained in:
Jan Bader 2016-11-23 22:07:53 +01:00
parent d8860aabc8
commit 73950eb6da
2 changed files with 16 additions and 9 deletions

11
main.go
View File

@ -16,6 +16,7 @@ const (
func main() {
router := gin.Default()
router.LoadHTMLGlob("./templates/*")
// Middleware
//e.Use(middleware.Logger())
//e.Use(middleware.Recover())
@ -53,15 +54,7 @@ func restricted(c *gin.Context) {
}
func login(c *gin.Context) {
c.String(http.StatusOK, `<html>
<head><title>Login</title>
<body>
<form action=\"login\">
<input type=\"text\" name=\"username\" />
<input type=\"password\" name=\"password\" />
</form>
</body>
</html>`)
c.HTML(http.StatusOK, "login.html", nil)
}
func loginPost(c *gin.Context) {

14
templates/login.html Normal file
View File

@ -0,0 +1,14 @@
<html>
<head><title>Login</title>
<body>
<form action="/api/v1/login?target=/" method="POST">
<label for="username">User</label>
<input type="text" name="username" /><br />
<label for="password">Password</label>
<input type="password" name="password" /><br />
<input type="submit">Login</form>
</form>
</body>
</html>