beego框架 golang web框架-小米商城
beego小米商城功能介绍
首页 菜单分类展示 图片轮播 商品详情 登录注册 个人中心 购物车 我的订单 收货地址
后台管理 登录 管理员管理 角色管理 菜单权限管理 轮播图管理 商品管理 商品分类管理
使用技术
beego框架
Mysql数据库
Redis
html前端
js框架bootstrap
功能展示
beego初时化
main.go
package main
import (
"encoding/gob"
"github.com/astaxie/beego"
_ "github.com/astaxie/beego/session/redis"
"mi/models"
_ "mi/routers"
)
func init() {
gob.Register(models.Manager{})
}
func main() {
// 注册模板函数
beego.AddFuncMap("unixToDate",models.UnixToDate)
beego.AddFuncMap("formatImg",models.FormatImg)
beego.AddFuncMap("formatAttr",models.FormatAttr)
beego.AddFuncMap("cutStr",models.CutStr)
beego.AddFuncMap("mul",models.Mul)
beego.AddFuncMap("judge",models.Judge)
// 配置session保存在redis里面
beego.BConfig.WebConfig.Session.SessionProvider = "redis"
beego.BConfig.WebConfig.Session.SessionProviderConfig = "127.0.0.1:6379"
beego.Run()
defer models.DB.Close()
}
beego路由
package routers
import (
"mi/controllers/mindex"
"github.com/astaxie/beego"
"mi/middleware"
)
func init() {
beego.Router("/", &mindex.IndexController{})
beego.Router("/login", &mindex.LoginController{})
beego.Router("/pass", &mindex.LoginController{},"get:Pass")
beego.Router("/pass/login", &mindex.LoginController{},"post:Login")
beego.Router("/pass/loginOut", &mindex.LoginController{},"get:LoginOut")
beego.Router("/pass/setpass", &mindex.LoginController{},"post:SetPass")
beego.Router("/pass/verifyUrl", &mindex.LoginController{},"get:VerifyUrl")
beego.Router("/category_:id([0-9]+).html", &mindex.ProductController{},"get:CategoryList")
beego.Router("/item_:id([0-9]+).html", &mindex.ProductController{},"get:ProductItem")
beego.Router("/product/getImgList", &mindex.ProductController{},"get:GetImgList")
beego.Router("/cart", &mindex.CartController{})
beego.Router("/cart/addCart", &mindex.CartController{}, "get:AddCart")
beego.Router("/cart/decCart", &mindex.CartController{}, "get:DecCart")
beego.Router("/cart/incCart", &mindex.CartController{}, "get:IncCart")
beego.Router("/cart/changeOneCart", &mindex.CartController{}, "get:ChangeOneCart")
beego.Router("/cart/changeAllCart", &mindex.CartController{}, "get:ChangeAllCart")
beego.Router("/cart/delCart", &mindex.CartController{}, "get:DelCart")
// 配置中间件判断权限
beego.InsertFilter("/buy/*",beego.BeforeRouter,middleware.DefaultAuth)
beego.Router("/buy/checkout", &mindex.BuyController{}, "get:CheckOut")
beego.Router("/buy/doOrder", &mindex.BuyController{}, "post:DoOrder")
beego.Router("/buy/confirm", &mindex.BuyController{}, "get:Confirm")
beego.InsertFilter("/address/*",beego.BeforeRouter,middleware.DefaultAuth)
beego.Router("/address/addAddress", &mindex.AddressController{}, "post:AddAddress")
beego.Router("/address/getOneAddressList", &mindex.AddressController{}, "get:GetOneAddressList")
beego.Router("/address/doEditAddressList", &mindex.AddressController{}, "post:DoEditAddressList")
beego.Router("/address/changeDefaultAddress", &mindex.AddressController{}, "get:ChangeDefaultAddress")
beego.InsertFilter("/user/*",beego.BeforeRouter,middleware.DefaultAuth)
beego.Router("/user", &mindex.UserController{})
beego.Router("/user/order", &mindex.UserController{},"get:OrderList")
beego.Router("/user/orderinfo", &mindex.UserController{},"get:OrderInfo")
beego.Router("/user/delOrder", &mindex.UserController{},"get:DelOrder")
}
运行
创建数据库, 然后修改数据库连接相关信息。
go mod init
bee run 或 go run main.go
浏览器访问 http://127.0.0.1:8080/ (前台)
默认用户:liang@qq.com 密码:123456
后台地址 http://127.0.0.1:8080/admin
管理员账号:liang 密码:123456