定义gin路由结构

This commit is contained in:
suguo.yao 2020-03-24 15:12:31 +08:00
parent 018806e37e
commit 045319fca6
14 changed files with 174 additions and 28 deletions

View File

@ -6,11 +6,11 @@ import (
"github.com/gin-gonic/gin"
)
//HomeHandle 基础验证试验
//HomeHandler 基础验证试验
//HTTP基本认证(Basic Authentication)
//"用户名+冒号+密码"用BASE64算法加密后的字符串放在http request 中的header的Authorization中发送给服务端
//最终格式Authorization: Basic BASE64("用户名+冒号+密码")
func HomeHandle(c *gin.Context) {
func HomeHandler(c *gin.Context) {
user := c.MustGet(gin.AuthUserKey).(string)
c.JSON(http.StatusOK, user)
}

19
admin/integral-handler.go Normal file
View File

@ -0,0 +1,19 @@
package admin
import "github.com/gin-gonic/gin"
func IntegralStatHandler(c *gin.Context) {
}
func IntegralListHandler(c *gin.Context) {
}
func IntegralApplylistHandler(c *gin.Context) {
}
func IntegralSortHandler(c *gin.Context) {
}

7
admin/user-handler.go Normal file
View File

@ -0,0 +1,7 @@
package admin
import "github.com/gin-gonic/gin"
func UserStatHandler(c *gin.Context) {
}

15
admin/video-handler.go Normal file
View File

@ -0,0 +1,15 @@
package admin
import "github.com/gin-gonic/gin"
func VideoStatHandler(c *gin.Context) {
}
func VideoListHandler(c *gin.Context) {
}
func VideoDownloadHandler(c *gin.Context) {
}

15
app/integral-handler.go Normal file
View File

@ -0,0 +1,15 @@
package app
import "github.com/gin-gonic/gin"
func IntegralQueryHandler(c *gin.Context) {
}
func IntegralApplyHandler(c *gin.Context) {
}
func IntegralHistoryHandler(c *gin.Context) {
}

15
app/user-handler.go Normal file
View File

@ -0,0 +1,15 @@
package app
import "github.com/gin-gonic/gin"
func UserInfoHandler(c *gin.Context) {
}
func UserListHandler(c *gin.Context) {
}
func FeeListHandler(c *gin.Context) {
}

11
app/video-handler.go Normal file
View File

@ -0,0 +1,11 @@
package app
import "github.com/gin-gonic/gin"
func VideoUploadHandler(c *gin.Context) {
}
func VideoListHandler(c *gin.Context) {
}

View File

@ -0,0 +1,7 @@
package community
import "github.com/gin-gonic/gin"
func ListHandler(c *gin.Context) {
}

View File

@ -0,0 +1,8 @@
package community
type CommunityService struct {
}
func (c *CommunityService) Map() {
}

View File

@ -0,0 +1,19 @@
package integral
import "github.com/gin-gonic/gin"
func StatHandler(c *gin.Context) {
}
func ListHandler(c *gin.Context) {
}
func ApplylistHandler(c *gin.Context) {
}
func SortHandler(c *gin.Context) {
}

7
public/public-handler.go Normal file
View File

@ -0,0 +1,7 @@
package public
import "github.com/gin-gonic/gin"
func CommunityListHandler(c *gin.Context) {
}

View File

@ -2,12 +2,14 @@ package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/admin"
"yyjishu.com/rubbish-class/app"
"yyjishu.com/rubbish-class/public"
)
var (
@ -18,11 +20,11 @@ func main() {
flag.Parse()
//启动时检查与创建文件夹video用于存放用户上传的视频文件
_, err := os.Stat("video")
_, err := os.Stat("data")
if err != nil {
if os.IsNotExist(err) {
os.Mkdir("./video", os.ModePerm)
os.Chmod("./video", 0755)
os.Mkdir("./data", os.ModePerm)
os.Chmod("./data", 0755)
}
}
@ -32,33 +34,33 @@ func main() {
rbGroup := r.Group(`/rubbish`)
{
rbGroup.Group(`/community/list`) //社区列表
rbGroup.StaticFS(`/movies`, http.Dir("./video"))
rbGroup.GET(`/community/list`, public.CommunityListHandler) //社区列表
rbGroup.StaticFS(`/video`, http.Dir("./data"))
authorized := rbGroup.Group(`/admin`, gin.BasicAuth(gin.Accounts{
"foo": "bar",
"admin": "admin",
}))
{
authorized.GET(`/index`, admin.HomeHandle)
authorized.GET(`/index`, admin.HomeHandler)
userGroup := authorized.Group(`/user`)
{
userGroup.GET(`/stat/:commid`)
userGroup.GET(`/stat`) //统计当天活跃用户、当天新增用户、历史用户
userGroup.GET(`/stat/:commid`, admin.UserStatHandler)
userGroup.GET(`/stat`, admin.UserStatHandler) //统计当天活跃用户、当天新增用户、历史用户
}
integralGroup := authorized.Group(`/integral`) //积分
{
integralGroup.GET(`/stat/:count`) //积分日统计数据
integralGroup.GET(`/list`) //积分兑换列表
integralGroup.GET(`/applylist`) //积分兑换申请列表
integralGroup.GET(`/sort/:houseid`) //住户总积分排序
integralGroup.GET(`/stat/:count`, admin.IntegralStatHandler) //积分日统计数据
integralGroup.GET(`/list`, admin.IntegralListHandler) //积分兑换列表
integralGroup.GET(`/applylist`, admin.IntegralApplylistHandler) //积分兑换申请列表
integralGroup.GET(`/sort/:houseid`, admin.IntegralSortHandler) //住户总积分排序
}
videoGroup := authorized.Group(`/video`)
{
videoGroup.GET(`/stat`) //视频数量及大小统计
videoGroup.GET(`/list/:commid/:month`) //视频地址按社区及月份
videoGroup.GET(`/download/:commid/:month`) //视频下载
videoGroup.GET(`/stat`, admin.VideoStatHandler) //视频数量及大小统计
videoGroup.GET(`/list/:commid/:month`, admin.VideoListHandler) //视频地址按社区及月份
videoGroup.GET(`/download/:commid/:month`, admin.VideoDownloadHandler) //视频下载
}
}
@ -66,26 +68,25 @@ func main() {
{
userGroup := appGroup.Group(`/user`)
{
userGroup.GET(`/info`, app.Indexhandle)
userGroup.POST(`/info`)
userGroup.GET(`/list/:houseid`)
userGroup.GET(`/info`, app.UserInfoHandler)
userGroup.POST(`/info`, app.UserInfoHandler)
userGroup.GET(`/list/:houseid`, app.UserListHandler)
userGroup.GET(`/code2session/:jscode`, app.Code2SessionHandler)
userGroup.GET(`/fee/:houseid`) //住户付费号码列表
userGroup.GET(`/fee/:houseid`, app.FeeListHandler) //住户付费号码列表
}
videoGroup := appGroup.Group(`/video`)
{
videoGroup.PUT(`/upload`, app.UploadHandler) //视频上传
videoGroup.GET(`/list/:houseid`) // 住户视频URL列表
videoGroup.PUT(`/upload`, app.VideoUploadHandler) //视频上传
videoGroup.GET(`/list/:houseid`, app.VideoListHandler) // 住户视频URL列表
}
integralGroup := appGroup.Group(`/integral`) //积分
{
integralGroup.GET(`/query`) //查询住户积分、社区积表
integralGroup.POST(`/apply`) //积分兑换申请
integralGroup.GET(`/history`) //积分兑换历史列表
integralGroup.GET(`/query`, app.IntegralQueryHandler) //查询住户积分、社区积表
integralGroup.POST(`/apply`, app.IntegralApplyHandler) //积分兑换申请
integralGroup.GET(`/history`, app.IntegralHistoryHandler) //积分兑换历史列表
}
}
}
}
r.Run(*endpoint)
log.Fatal(r.Run(*endpoint))
}

7
user/user-handler.go Normal file
View File

@ -0,0 +1,7 @@
package user
import "github.com/gin-gonic/gin"
func StatHandler(c *gin.Context) {
}

15
video/video-handler.go Normal file
View File

@ -0,0 +1,15 @@
package video
import "github.com/gin-gonic/gin"
func StatHandler(c *gin.Context) {
}
func ListHandler(c *gin.Context) {
}
func DownloadHandler(c *gin.Context) {
}