rubbishclass-srv/server.go

99 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"
"yyjishu.com/rubbish-class/rubbish"
)
var (
endpoint = flag.String("s", "localhost:8080", "service endpoint")
)
func main() {
rubbish.Addr = flag.String("d", "root:root@tcp(127.0.0.1:3306)/rubbish?charset=utf8mb4\u0026parseTime=True\u0026loc=Local", "address for mysql")
flag.Parse()
rubbish.Init()
//启动时检查与创建文件夹video用于存放用户上传的视频文件
_, err := os.Stat("data")
if err != nil {
if os.IsNotExist(err) {
os.Mkdir("./data", os.ModePerm)
os.Chmod("./data", 0755)
}
}
r := gin.Default()
r.Use(gin.Recovery())
rbGroup := r.Group(`/rubbish`)
{
rbGroup.GET(`/community/list`, public.CommunityListHandler) //社区列表,OK
rbGroup.POST(`/community/create`, public.CommunityCreateHandler) //社区创建,测试维护使用,OK
rbGroup.StaticFS(`/video`, http.Dir("./data"))
authorized := rbGroup.Group(`/admin`, gin.BasicAuth(gin.Accounts{
"foo": "bar",
"admin": "admin",
}))
{
authorized.GET(`/index`, admin.HomeHandler)
userGroup := authorized.Group(`/user`)
{
userGroup.GET(`/stat/:commid`, admin.UserStatHandler) //统计社区当天的活跃用户数据
userGroup.GET(`/stat`, admin.UserStatHandler) //统计当天活跃用户、当天新增用户、历史用户
}
integralGroup := authorized.Group(`/integral`) //积分
{
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`, admin.VideoStatHandler) //视频数量及大小统计
videoGroup.GET(`/list/:commid/:month`, admin.VideoListHandler) //视频地址按社区及月份
videoGroup.GET(`/download/:commid/:month`, admin.VideoDownloadHandler) //视频下载
}
}
rbGroup.GET(`/app/code2session/:jscode`, app.Code2SessionHandler) //微信小程序用户认证
appGroup := rbGroup.Group(`/app`, app.UserCheckHandler)
{
userGroup := appGroup.Group(`/user`)
{
userGroup.GET(`/info`, app.UserInfoHandler)
userGroup.PUT(`/info`, app.UserInfoHandler)
userGroup.GET(`/list/:houseid`, app.UserListHandler)
userGroup.GET(`/fee/:houseid`, app.FeeListHandler) //住户付费号码列表
}
videoGroup := appGroup.Group(`/video`)
{
videoGroup.PUT(`/upload`, app.VideoUploadHandler) //视频上传
videoGroup.GET(`/list/:houseid`, app.VideoListHandler) // 住户视频URL列表
}
integralGroup := appGroup.Group(`/integral`) //积分
{
integralGroup.GET(`/query`, app.IntegralQueryHandler) //查询住户积分、社区积表
integralGroup.POST(`/apply`, app.IntegralApplyHandler) //积分兑换申请
integralGroup.GET(`/history`, app.IntegralHistoryHandler) //积分兑换历史列表
}
}
}
log.Fatal(r.Run(*endpoint))
}