惊风破浪的博客
PHP
MySQL
Redis
Linux
算法与设计模式
杂项
Golang
登录
Go实现登录功能
1个月前 ⋅
0
> main.go文件 ```go package main import "net/http" import "text/template" func index(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { t, _ := template.ParseFiles("view/index.html")//加载html文件 t.Execute(w, nil)//将文件输出到浏览器 } } func main() { http.HandleFunc("/index",index) http.ListenAndServe("0.0.0.0:9300", nil) } ``` - 模板文件 ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Go语言实战</title> </head> <body> <div> <h3>登录</h3> <form action="/check" method="post"> <div> <div> <input type="text" id="username" name="username" placeholder="请输入账号"> </div> </div> <div> <div> <input type="password" id="password" name="password" placeholder="请输入密码"> </div> </div> <div > <div > <input type="submit" value="登录"> </div> </div> </form> </div> </body> </html> ``` `在main.go,加入check方法,绑定路由` 
回复
发布文章
友情链接
Mr.Zhu
Swoole
PHP官网
菜鸟教程
Go语言中文网
implode
数据结构与算法