1. 代码:

  • main.go ```go package main

import ( “github.com/gin-gonic/gin” “net/http” )

func main() { router := gin.Default() router.LoadHTMLFiles(“./login.html”) router.Static(“static”, “./templates/static”)

  1. // 获取 login.html
  2. router.GET("/login", func(c *gin.Context) {
  3. c.HTML(http.StatusOK, "login.html", nil)
  4. })
  5. // 获取表单元素
  6. router.POST("/login", func(c *gin.Context) {
  7. email := c.PostForm("email")
  8. password := c.PostForm("password")
  9. c.JSON(http.StatusOK, gin.H{
  10. "your email: ": email,
  11. "your password: ": password,
  12. })
  13. })
  14. router.Run(":8080")

}

  1. - `login.html`
  2. ```html
  3. <!--声明是 HTML5 -->
  4. <!doctype html>
  5. <!-- 声明语言 -->
  6. <html lang="zh-CN">
  7. <head>
  8. <!-- Required meta tags -->
  9. <!-- 声明是 UTF-8 字符集 -->
  10. <meta charset="utf-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  12. <!-- Bootstrap CSS -->
  13. <link rel="stylesheet" href="static/bootstrap.min.css">
  14. <!-- Loding font -->
  15. <link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">
  16. <!-- Custom Styles -->
  17. <link rel="stylesheet" type="text/css" href="static/login.css">
  18. <title>Login</title>
  19. </head>
  20. <body>
  21. <!-- Backgrounds -->
  22. <div id="login-bg" class="container-fluid">
  23. <div class="bg-img"></div>
  24. <div class="bg-color"></div>
  25. </div>
  26. <!-- End Backgrounds -->
  27. <div class="container" id="login">
  28. <div class="row justify-content-center">
  29. <div class="col-lg-8">
  30. <div class="login">
  31. <h1>Login</h1>
  32. <!-- Loging form -->
  33. <form action="/login" method="post">
  34. <!-- 输入邮箱 -->
  35. <div class="form-group">
  36. <input type="email" name="email" id="login_email" class="form-control" id="exampleInputEmail1"
  37. aria-describedby="emailHelp" placeholder="Enter email">
  38. </div>
  39. <!-- 输入密码 -->
  40. <div class="form-group">
  41. <input type="password" name="password" id="login_password" class="form-control" id="exampleInputPassword1"
  42. placeholder="Password">
  43. </div>
  44. <div class="form-check">
  45. <label class="switch">
  46. <input type="checkbox">
  47. <span class="slider round"></span>
  48. </label>
  49. <label class="form-check-label" for="exampleCheck1">Remember me</label>
  50. <label class="forgot-password"><a href="#">Forgot Password?<a></label>
  51. </div>
  52. <br>
  53. <button type="submit" class="btn btn-lg btn-block btn-success">Log in</button>
  54. </form>
  55. <!-- End Loging form -->
  56. </div>Copyright &copy; 2022. Company name All rights reserved. <a target="_blank"
  57. href="https://www.chenzhiyong.website">Home Page</a>
  58. </div>
  59. </div>
  60. </div>
  61. </body>
  62. </html>
  • login.css
    1. 代码太长,放在文末

    2. 效果

    image.png
    image.png

css 文件

  1. body {
  2. font-family: 'Montserrat', sans-serif;
  3. text-rendering : optimizeLegibility;
  4. -webkit-font-smoothing : antialiased;
  5. }
  6. #login-bg.container-fluid {
  7. padding: 0;
  8. height: 100%;
  9. position: absolute;
  10. }
  11. /* Background image an color divs*/
  12. .bg-img , .bg-color {
  13. min-width: 50%;
  14. vertical-align: top;
  15. padding: 0;
  16. margin-left: 0;
  17. height: 100%;
  18. background-color: #CAF0D3;
  19. display: inline-block;
  20. overflow: hidden;
  21. }
  22. .bg-color {
  23. margin-left: -5px;
  24. }
  25. .bg-img {
  26. /* background-image: url(./bg-image.jpg); */
  27. background-color: rgb(172, 215, 248);
  28. background-size: cover;
  29. }
  30. #login{
  31. padding-top: 10%;
  32. text-align: center;
  33. text-transform: uppercase;
  34. }
  35. .login {
  36. width: 100%;
  37. height: 500px;
  38. background-color: #fff;
  39. padding: 15px;
  40. padding-top: 30px;
  41. }
  42. .login h1 {
  43. margin-top: 30px;
  44. font-weight: bold;
  45. font-size: 60px;
  46. letter-spacing: 3px;
  47. }
  48. .login form {
  49. max-width: 420px;
  50. margin: 30px auto;
  51. }
  52. .login .btn {
  53. border-radius: 50px;
  54. text-transform: uppercase;
  55. font-weight: bold;
  56. letter-spacing: 2px;
  57. font-size: 20px;
  58. padding: 14px;
  59. background-color: #5dda7c;
  60. }
  61. .form-group input {
  62. font-size: 20px;
  63. font-weight: lighter;
  64. border: none;
  65. background-color: #F0F0F0;
  66. color: #465347!important;
  67. padding: 26px 30px;
  68. border-radius: 50px;
  69. transition : 0.2s;
  70. }
  71. /* Form check styles*/
  72. .form-check {
  73. padding: 0;
  74. text-align: left;
  75. }
  76. .form-check label {
  77. vertical-align: top;
  78. padding-top: 5px;
  79. padding-left: 5px;
  80. font-size: 15px;
  81. color: #606060;
  82. font-size: 14px;
  83. }
  84. .forgot-password {
  85. text-align: right;
  86. float: right;
  87. font-weight: bold;
  88. }
  89. .forgot-password a {
  90. color: #00B72E;
  91. opacity: 0.6;
  92. }
  93. .forgot-password a:hover {
  94. opacity: 1;
  95. }
  96. /* Switch styles */
  97. .switch {
  98. position: relative;
  99. display: inline-block;
  100. width: 60px;
  101. height: 30px;
  102. }
  103. /* Hide default HTML checkbox */
  104. .switch input {display:none;}
  105. /* The slider */
  106. .slider {
  107. position: absolute;
  108. cursor: pointer;
  109. top: 0;
  110. left: 0;
  111. right: 0;
  112. bottom: 0;
  113. background-color: #F0F0F0;
  114. -webkit-transition: .4s;
  115. transition: .4s;
  116. border-radius: 30px;
  117. }
  118. .slider:before {
  119. position: absolute;
  120. content: "";
  121. height: 22px;
  122. width: 22px;
  123. left: 4px;
  124. bottom: 4px;
  125. background-color: white;
  126. -webkit-transition: .4s;
  127. transition: .4s;
  128. border-radius: 50%;
  129. }
  130. input:checked + .slider {
  131. background-color: #00B72E;
  132. }
  133. input:focus + .slider {
  134. box-shadow: 0 0 1px #00B72E;
  135. }
  136. input:checked + .slider:before {
  137. -webkit-transform: translateX(30px);
  138. -ms-transform: translateX(30px);
  139. transform: translateX(30px);
  140. }
  141. /* Media queries */
  142. @media(max-width: 500px) {
  143. .bg-img , .bg-color {
  144. min-width: 100%;
  145. height: 50%;
  146. margin: 0;
  147. }
  148. .forgot-password {
  149. text-align: right;
  150. float: left;
  151. padding: 20px 0;
  152. }
  153. #login {
  154. padding-top: 50px;
  155. }
  156. }