From 045319fca6902211c0485ef0dadf7a7db82b1b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E6=B5=B7=E4=BB=B2=E5=AD=90?= Date: Tue, 24 Mar 2020 15:12:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89gin=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/admin-handler.go | 4 +-- admin/integral-handler.go | 19 ++++++++++++ admin/user-handler.go | 7 +++++ admin/video-handler.go | 15 ++++++++++ app/integral-handler.go | 15 ++++++++++ app/user-handler.go | 15 ++++++++++ app/video-handler.go | 11 +++++++ community/community-handler.go | 7 +++++ community/community-service.go | 8 +++++ integral/integral-handler.go | 19 ++++++++++++ public/public-handler.go | 7 +++++ server.go | 53 +++++++++++++++++----------------- user/user-handler.go | 7 +++++ video/video-handler.go | 15 ++++++++++ 14 files changed, 174 insertions(+), 28 deletions(-) create mode 100644 admin/integral-handler.go create mode 100644 admin/user-handler.go create mode 100644 admin/video-handler.go create mode 100644 app/integral-handler.go create mode 100644 app/user-handler.go create mode 100644 app/video-handler.go create mode 100644 community/community-handler.go create mode 100644 community/community-service.go create mode 100644 integral/integral-handler.go create mode 100644 public/public-handler.go create mode 100644 user/user-handler.go create mode 100644 video/video-handler.go diff --git a/admin/admin-handler.go b/admin/admin-handler.go index b422e4e..497be1c 100644 --- a/admin/admin-handler.go +++ b/admin/admin-handler.go @@ -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) } diff --git a/admin/integral-handler.go b/admin/integral-handler.go new file mode 100644 index 0000000..56c8a29 --- /dev/null +++ b/admin/integral-handler.go @@ -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) { + +} diff --git a/admin/user-handler.go b/admin/user-handler.go new file mode 100644 index 0000000..c4d7c96 --- /dev/null +++ b/admin/user-handler.go @@ -0,0 +1,7 @@ +package admin + +import "github.com/gin-gonic/gin" + +func UserStatHandler(c *gin.Context) { + +} diff --git a/admin/video-handler.go b/admin/video-handler.go new file mode 100644 index 0000000..c7bcf5a --- /dev/null +++ b/admin/video-handler.go @@ -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) { + +} diff --git a/app/integral-handler.go b/app/integral-handler.go new file mode 100644 index 0000000..60fe37d --- /dev/null +++ b/app/integral-handler.go @@ -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) { + +} diff --git a/app/user-handler.go b/app/user-handler.go new file mode 100644 index 0000000..7ba4b92 --- /dev/null +++ b/app/user-handler.go @@ -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) { + +} diff --git a/app/video-handler.go b/app/video-handler.go new file mode 100644 index 0000000..cd8361f --- /dev/null +++ b/app/video-handler.go @@ -0,0 +1,11 @@ +package app + +import "github.com/gin-gonic/gin" + +func VideoUploadHandler(c *gin.Context) { + +} + +func VideoListHandler(c *gin.Context) { + +} diff --git a/community/community-handler.go b/community/community-handler.go new file mode 100644 index 0000000..ae3e3e2 --- /dev/null +++ b/community/community-handler.go @@ -0,0 +1,7 @@ +package community + +import "github.com/gin-gonic/gin" + +func ListHandler(c *gin.Context) { + +} diff --git a/community/community-service.go b/community/community-service.go new file mode 100644 index 0000000..cb606ac --- /dev/null +++ b/community/community-service.go @@ -0,0 +1,8 @@ +package community + +type CommunityService struct { +} + +func (c *CommunityService) Map() { + +} diff --git a/integral/integral-handler.go b/integral/integral-handler.go new file mode 100644 index 0000000..3a6b8df --- /dev/null +++ b/integral/integral-handler.go @@ -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) { + +} diff --git a/public/public-handler.go b/public/public-handler.go new file mode 100644 index 0000000..a0d598c --- /dev/null +++ b/public/public-handler.go @@ -0,0 +1,7 @@ +package public + +import "github.com/gin-gonic/gin" + +func CommunityListHandler(c *gin.Context) { + +} diff --git a/server.go b/server.go index c4bbc8c..b5afb89 100644 --- a/server.go +++ b/server.go @@ -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)) } diff --git a/user/user-handler.go b/user/user-handler.go new file mode 100644 index 0000000..2366a7b --- /dev/null +++ b/user/user-handler.go @@ -0,0 +1,7 @@ +package user + +import "github.com/gin-gonic/gin" + +func StatHandler(c *gin.Context) { + +} diff --git a/video/video-handler.go b/video/video-handler.go new file mode 100644 index 0000000..80e77cf --- /dev/null +++ b/video/video-handler.go @@ -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) { + +}