shop-example/pkg/router/router.go
2023-08-14 08:44:10 +08:00

61 lines
2.5 KiB
Go

package router
import (
"github.com/gin-gonic/gin"
"worktest/pkg/controller"
"worktest/pkg/controller/front"
)
//api路由配置
func RegisterRoute(router *gin.Engine) {
//middleware: 服务错误处理 => 生成请求id => access log
//api版本
v1 := router.Group("/api")
{
backend := v1.Group("/backend")
backend.POST("list", controller.List)
backend.POST("all/cache/remove", controller.RemoveAllCache)
backend.POST("cache/remove", controller.RemoveCache)
backend.POST("syn/cache", controller.SynCache)
backend.POST("publish/msg", controller.PublishMsg)
backend.POST("publish/time/msg", controller.PublishMsgTime)
}
{
//首页列表部分
backend := v1.Group("/front")
backend.POST("mysql/list", front.MysqlList) //数据库连接
backend.POST("redis/list", front.RedisList) //缓存连接 string/hash
backend.POST("rec/list", front.RecList) //推荐列表 list
//#backend.POST("change/rec/list", front.List) //推荐列表 list
//#backend.POST("getlist", front.List) //推荐去除已买连接 set/zset
// jemter 对比
backend.POST("mysql/detail", front.MysqlDetail) //数据库连接
backend.POST("redis/detail", front.RedisDetail) //redis单商品详情 无锁保护 可缓存击穿
backend.POST("redis/lock/detail", front.RedisDetailLock) //redis单商品详情 有锁保护 可缓存击穿
backend.POST("redis/bitmap/detail", front.RedisDetailBitMap) //redis单商品详情 锁保护 bitmap缓存击穿保护
backend.POST("redis/bitmapcount/detail", front.RedisDetailBitMapCount) //redis单商品详情 锁保护 bitmap缓存击穿保护 增加访问统计
//增加bitmap的统计等
backend.POST("redis/bitmapcount/productcount", front.RedisCountProduct) //redis 增加bitmap的统计等
//抢购 watch事务 锁 list(未演示)
backend.POST("mysql/buy", front.NormalMysqlBuy) //抢购 mysql事务
backend.POST("mysql/tx/buy", front.MysqlBuy) //抢购 mysql事务
backend.POST("redis/tx/buy", front.RedisTxBuy) //redistab 事务抢购 watch unwatch mutile exec
backend.POST("redis/lock/buy", front.RedisLockBuy) //redistab 分布式锁抢购 setNx lua
backend.POST("channelLock/buy", front.GoroutineBuy ) //go语言锁抢购,协程模拟锁 分布部署则失效
//backend.POST("getlist", controller.List) //go语言锁抢购 略
//广播
backend.GET("channel/receive", front.RedisRecWebsocket) //websocket redistab 广播 receive
backend.GET("redis/receive", front.RedisWebsocket) //websocket redistab 广播 chain
}
}