Compare commits

...

51 Commits
master ... dev

Author SHA1 Message Date
majun 6dd979d1ea 修改数据库配置 7 months ago
majun 82d527cc6b 修改config 7 months ago
majun 013a8d612c 订阅数一致修改 7 months ago
majun b8833bf0a0 错误响应格式修改 7 months ago
majun 553df493c8 订阅格式修改 7 months ago
majun c56e278ff6 查询格式修改 7 months ago
lijikun 46fcf21ee0 Merge branch 'lijikun' into dev 7 months ago
lijikun 5bdb50d4a6 12.5日传参错误判断、返回的修改 7 months ago
majun 1d2eef154d 修改格式 7 months ago
majun 9333bfe9b6 封装Result格式 7 months ago
lijikun b902e7ee52 12.4日晚发现接口从ALL改为GET时出错,改正 7 months ago
lijikun dee722c295 12.4日请求访问方式从ALL改为GET(重新修改3) 7 months ago
lijikun a749d99af1 12.4日请求访问方式从ALL改为GET(重新修改3) 7 months ago
lijikun 7d52f9e9c4 12.4日请求访问方式从ALL改为GET(重新修改2) 7 months ago
lijikun 173861297e 12.4日请求访问方式从ALL改为GET 7 months ago
lijikun 19818c205a Merge branch 'lijikun' into dev 7 months ago
lijikun 1203f6f7a9 12.4日跨域问题解决,返回到前端的格式调整 7 months ago
lijikun 06140b9a76 12.4日跨域问题解决,返回到前端的格式调整 7 months ago
majun afc66966be 添加Result格式 7 months ago
majun 80b41961c0 修改v1 7 months ago
majun ec0b0030f5 修改 7 months ago
majun 027a37585a 前后端对接 7 months ago
majun e997264375 配置跨域 7 months ago
lijikun 3f75331b40 12.3下午四个模块合并后提交 7 months ago
lijikun 403bb586c8 ljk尝试提交 7 months ago
lijikun cd59b9e2d9 12.3下午李继坤合并到dev 7 months ago
lijikun 789256d1bf 12.3日下午go版本修改后,非关键文件以及空文件 7 months ago
lijikun 5314db0194 12.3日下午go版本修改后 7 months ago
majun 49993ea248 Merge branch 'zhibo-mj' into majun 7 months ago
majun ea33550d65 Merge branch 'pindao-mj' into majun 7 months ago
majun 4524c0b941 增加频道列表 7 months ago
majun 2736d4d588 排序更新 7 months ago
majun a21c5ac7f3 初始化v2 7 months ago
majun 9c7157eb3a 初始化 7 months ago
majun 5c11d57d68 Merge branch 'zhibo-mj' into majun 7 months ago
majun 133b3b5935 直播完成 7 months ago
majun 2fdc9404c3 频道完成 7 months ago
majun 2a674d3b71 111 7 months ago
majun e26c366843 查询完成 7 months ago
majun 7db21eea0f 查询直播数据 7 months ago
majun 42f5ed8e7f 查询已完成 7 months ago
majun 1977d8021a 修正 7 months ago
majun 534e608286 Bug修正 7 months ago
majun b77b029b12 修bug 7 months ago
majun 472d86fc7a 编写接口 7 months ago
majun bd279fb85f 初始化v2 7 months ago
majun 5705c1c9ac 初始化 7 months ago
majun b7d9d0227f 环境搭建 7 months ago
majun 93150398bc 清空 7 months ago
majun 750776dbce 搭建框架 7 months ago
majun e78e7fbf86 清空 7 months ago
  1. 0
      .gitattributes
  2. 7
      .gitignore
  3. 0
      Makefile
  4. 0
      README.MD
  5. 17
      api/channel/channel.go
  6. 41
      api/channel/v1/channel.go
  7. 9
      api/live/live.go
  8. 21
      api/live/v1/live.go
  9. 17
      api/reservation/reservation.go
  10. 23
      api/reservation/v1/reservation.go
  11. 17
      api/subscription/subscription.go
  12. 23
      api/subscription/v1/subscription.go
  13. 12
      demo/api/hello/v1/hello.go
  14. 13
      demo/hack/config.yaml
  15. 30
      demo/internal/cmd/cmd.go
  16. 13
      demo/internal/controller/hello/hello_v1_hello.go
  17. 13
      demo/main.go
  18. 10
      go.mod
  19. 6
      go.sum
  20. 14
      hack/config.yaml
  21. 0
      hack/hack-cli.mk
  22. 0
      hack/hack.mk
  23. 89
      internal/cmd/cmd.go
  24. 0
      internal/consts/consts.go
  25. 5
      internal/controller/channel/channel.go
  26. 15
      internal/controller/channel/channel_new.go
  27. 25
      internal/controller/channel/channel_v1_get_channel.go
  28. 18
      internal/controller/channel/channel_v1_get_channel_list.go
  29. 66
      internal/controller/clubPage/clubPage.go
  30. 2
      internal/controller/live/live.go
  31. 9
      internal/controller/live/live_new.go
  32. 24
      internal/controller/live/live_v1_get_live.go
  33. 69
      internal/controller/mainPage/mainPage.go
  34. 5
      internal/controller/reservation/reservation.go
  35. 15
      internal/controller/reservation/reservation_new.go
  36. 23
      internal/controller/reservation/reservation_v1_add_reservation.go
  37. 19
      internal/controller/reservation/reservation_v1_delete_reservation.go
  38. 5
      internal/controller/subscription/subscription.go
  39. 15
      internal/controller/subscription/subscription_new.go
  40. 24
      internal/controller/subscription/subscription_v1_add_subscription.go
  41. 20
      internal/controller/subscription/subscription_v1_delete_subscription.go
  42. 0
      internal/dao/.gitkeep
  43. 27
      internal/dao/go_channel_subscriptions.go
  44. 27
      internal/dao/go_channels.go
  45. 27
      internal/dao/go_clubs.go
  46. 27
      internal/dao/go_live_reservations.go
  47. 27
      internal/dao/go_lives.go
  48. 27
      internal/dao/go_shows.go
  49. 27
      internal/dao/go_users.go
  50. 77
      internal/dao/internal/go_channel_subscriptions.go
  51. 81
      internal/dao/internal/go_channels.go
  52. 79
      internal/dao/internal/go_clubs.go
  53. 77
      internal/dao/internal/go_live_reservations.go
  54. 83
      internal/dao/internal/go_lives.go
  55. 95
      internal/dao/internal/go_shows.go
  56. 79
      internal/dao/internal/go_users.go
  57. 0
      internal/logic/.gitkeep
  58. 52
      internal/logic/clubs/clubs.go
  59. 8
      internal/logic/logic.go
  60. 60
      internal/logic/shows/shows.go
  61. 24
      internal/middleware/middleware.go
  62. 0
      internal/model/.gitkeep
  63. 0
      internal/model/do/.gitkeep
  64. 17
      internal/model/do/go_channel_subscriptions.go
  65. 19
      internal/model/do/go_channels.go
  66. 18
      internal/model/do/go_clubs.go
  67. 17
      internal/model/do/go_live_reservations.go
  68. 21
      internal/model/do/go_lives.go
  69. 27
      internal/model/do/go_shows.go
  70. 18
      internal/model/do/go_users.go
  71. 66
      internal/model/dto/Result.go
  72. 0
      internal/model/entity/.gitkeep
  73. 12
      internal/model/entity/go_channel_subscriptions.go
  74. 14
      internal/model/entity/go_channels.go
  75. 13
      internal/model/entity/go_clubs.go
  76. 12
      internal/model/entity/go_live_reservations.go
  77. 20
      internal/model/entity/go_lives.go
  78. 28
      internal/model/entity/go_shows.go
  79. 13
      internal/model/entity/go_users.go
  80. 0
      internal/packed/packed.go
  81. 0
      internal/service/.gitkeep
  82. 34
      internal/service/clubs.go
  83. 32
      internal/service/shows.go
  84. 38
      main.go
  85. 15
      manifest/config/config.yaml
  86. 0
      manifest/deploy/kustomize/base/deployment.yaml
  87. 0
      manifest/deploy/kustomize/base/kustomization.yaml
  88. 0
      manifest/deploy/kustomize/base/service.yaml
  89. 0
      manifest/deploy/kustomize/overlays/develop/configmap.yaml
  90. 0
      manifest/deploy/kustomize/overlays/develop/deployment.yaml
  91. 0
      manifest/deploy/kustomize/overlays/develop/kustomization.yaml
  92. 0
      manifest/docker/Dockerfile
  93. 0
      manifest/docker/docker.sh
  94. 0
      manifest/i18n/.gitkeep
  95. 0
      manifest/protobuf/.keep-if-necessary
  96. 0
      resource/public/html/.gitkeep
  97. 532
      resource/public/html/api.html
  98. 0
      resource/public/plugin/.gitkeep
  99. 0
      resource/public/resource/css/.gitkeep
  100. 0
      resource/public/resource/image/.gitkeep

0
demo/.gitattributes → .gitattributes

7
demo/.gitignore → .gitignore

@ -16,4 +16,9 @@ manifest/output/
temp/
temp.yaml
bin
**/config/config.yaml
*.exe
*.exe~
*.dll
*.so
*.dylib

0
demo/Makefile → Makefile

0
demo/README.MD → README.MD

17
api/channel/channel.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package channel
import (
"context"
"practice_Go/api/channel/v1"
"practice_Go/internal/model/dto"
)
type IChannelV1 interface {
GetChannel(ctx context.Context, req *v1.GetChannelReq) (*dto.Result, error)
GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (*dto.Result, error)
}

41
api/channel/v1/channel.go

@ -0,0 +1,41 @@
package v1
import (
"practice_Go/internal/model/entity"
"github.com/gogf/gf/v2/frame/g"
)
type Channel struct {
Id int `json:"id" dc:"频道ID"`
Image string `json:"image" dc:"频道图片"`
Name string `json:"name" dc:"频道名称"`
SubscriptionCount int `json:"subscriptionCount" dc:"频道订阅数量"`
BackgroundImage string `json:"backgroundImage" dc:"频道背景图"`
Status bool `json:"status" dc:"订阅状态"`
}
type ChannelList struct {
Id int `json:"id" dc:"频道ID"`
Name string `json:"name" dc:"频道名称"`
}
type GetChannelReq struct {
g.Meta `path:"/channel" method:"post" tags:"Channel" summary:"获取单个频道"`
Id int `v:"required|min:1#频道ID不能为空|频道ID不能小于1" dc:"频道ID"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
FlagType int `v:"min:1|max:2#类型不能小于1|类型不能大于2" dc:"列表类型"`
}
type GetChannelRes struct {
*Channel `json:"channel" dc:"单个频道"`
List []*entity.GoShows `json:"shows" dc:"频道下的所有节目和对应创作人"`
}
type GetChannelListReq struct {
g.Meta `path:"/list" method:"get" tags:"ChannelList" summary:"获取频道列表"`
}
type GetChannelListRes struct {
List []*ChannelList `json:"list" dc:"频道列表"`
}

9
demo/api/hello/hello.go → api/live/live.go

@ -2,14 +2,15 @@
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package hello
package live
import (
"context"
"demo/api/hello/v1"
"practice_Go/api/live/v1"
"practice_Go/internal/model/dto"
)
type IHelloV1 interface {
Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error)
type ILiveV1 interface {
GetLive(ctx context.Context, req *v1.GetLiveReq) (*dto.Result, error)
}

21
api/live/v1/live.go

@ -0,0 +1,21 @@
package v1
import (
"practice_Go/internal/model/entity"
"github.com/gogf/gf/v2/frame/g"
)
type Live struct {
entity.GoLives
Reservation int `json:"reservation" dc:"预约状态"`
}
type GetLiveReq struct {
g.Meta `path:"/live" method:"post" tags:"Live" summary:"获取直播列表"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
}
type GetLiveRes struct {
List []*Live `json:"liveList" dc:"直播列表"`
}

17
api/reservation/reservation.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package reservation
import (
"context"
"practice_Go/api/reservation/v1"
"practice_Go/internal/model/dto"
)
type IReservationV1 interface {
AddReservation(ctx context.Context, req *v1.AddReservationReq) (*dto.Result, error)
DeleteReservation(ctx context.Context, req *v1.DeleteReservationReq) (*dto.Result, error)
}

23
api/reservation/v1/reservation.go

@ -0,0 +1,23 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type AddReservationReq struct {
g.Meta `path:"/reservation" method:"post" tags:"Reservation" summary:"添加预约信息"`
Id int `v:"required|min:1#直播ID不能为空|直播ID不能小于1" dc:"直播ID"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
}
type AddReservationRes struct {
Success bool `json:"success" dc:"预约是否成功"`
}
type DeleteReservationReq struct {
g.Meta `path:"/reservation" method:"delete" tags:"Reservation" summary:"删除预约信息"`
Id int `v:"required|min:1#直播ID不能为空|直播ID不能小于1" dc:"直播ID"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
}
type DeleteReservationRes struct {
Success bool `json:"success" dc:"取消预约是否成功"`
}

17
api/subscription/subscription.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package subscription
import (
"context"
"practice_Go/api/subscription/v1"
"practice_Go/internal/model/dto"
)
type ISubscriptionV1 interface {
AddSubscription(ctx context.Context, req *v1.AddSubscriptionReq) (*dto.Result, error)
DeleteSubscription(ctx context.Context, req *v1.DeleteSubscriptionReq) (*dto.Result, error)
}

23
api/subscription/v1/subscription.go

@ -0,0 +1,23 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type AddSubscriptionReq struct {
g.Meta `path:"/subscription" method:"post" tags:"Subscription" summary:"添加订阅信息"`
Id int `v:"required|min:1#频道ID不能为空|频道ID不能小于1" dc:"频道ID"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
}
type AddSubscriptionRes struct {
Success bool `json:"success" dc:"订阅是否成功"`
}
type DeleteSubscriptionReq struct {
g.Meta `path:"/subscription" method:"delete" tags:"Subscription" summary:"删除订阅信息"`
Id int `v:"required|min:1#频道ID不能为空|频道ID不能小于1" dc:"频道ID"`
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"`
}
type DeleteSubscriptionRes struct {
Success bool `json:"success" dc:"取消订阅是否成功"`
}

12
demo/api/hello/v1/hello.go

@ -1,12 +0,0 @@
package v1
import (
"github.com/gogf/gf/v2/frame/g"
)
type HelloReq struct {
g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"`
}
type HelloRes struct {
g.Meta `mime:"text/html" example:"string"`
}

13
demo/hack/config.yaml

@ -1,13 +0,0 @@
# CLI tool, only in development environment.
# https://goframe.org/docs/cli
gfcli:
gen:
dao:
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
descriptionTag: true
docker:
build: "-a amd64 -s linux -p temp -ew"
tagPrefixes:
- my.image.pub/my-app

30
demo/internal/cmd/cmd.go

@ -1,30 +0,0 @@
package cmd
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"demo/internal/controller/hello"
)
var (
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(
hello.NewV1(),
)
})
s.Run()
return nil
},
}
)

13
demo/internal/controller/hello/hello_v1_hello.go

@ -1,13 +0,0 @@
package hello
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"demo/api/hello/v1"
)
func (c *ControllerV1) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) {
g.RequestFromCtx(ctx).Response.Writeln("Hello World!")
return
}

13
demo/main.go

@ -1,13 +0,0 @@
package main
import (
_ "demo/internal/packed"
"github.com/gogf/gf/v2/os/gctx"
"demo/internal/cmd"
)
func main() {
cmd.Main.Run(gctx.GetInitCtx())
}

10
demo/go.mod → go.mod

@ -1,8 +1,12 @@
module demo
module practice_Go
go 1.18
require github.com/gogf/gf/v2 v2.8.1
require (
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1
github.com/gogf/gf/v2 v2.8.1
github.com/rs/cors v1.11.1
)
require (
github.com/BurntSushi/toml v1.4.0 // indirect
@ -12,6 +16,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
@ -20,6 +25,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/cors v1.11.1
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect

6
demo/go.sum → go.sum

@ -14,6 +14,10 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1 h1:jbaPawkb8qmaYzrmBDbTa8Zkhzacq1RBOZw+qRJExI4=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1/go.mod h1:s2aI1fV9AvKi4NtMpv3pV0EHtazkvfUNVQmzapr7UJQ=
github.com/gogf/gf/v2 v2.8.1 h1:1oVQg3G5OgCats4qWFTH3pHLe92nfUQeUDta05tUs1g=
github.com/gogf/gf/v2 v2.8.1/go.mod h1:6iYuZZ+A0ZcH8+4MDS/P0SvTPCvKzRvyAsY1kbkJYJc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@ -37,6 +41,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=

14
hack/config.yaml

@ -0,0 +1,14 @@
# CLI tool, only in development environment.
# https://goframe.org/docs/cli
gfcli:
gen:
dao:
- link: "mysql:root:80083@tcp(127.0.0.1:3306)/linktest?charset=utf8mb4&parseTime=True&loc=Local"
table: "go_users, go_shows, go_lives, go_live_reservations, go_club, go_channels,go_channel_subscriptions"
descriptionTag: true
docker:
build: "-a amd64 -s linux -p temp -ew"
tagPrefixes:
- my.image.pub/my-app

0
demo/hack/hack-cli.mk → hack/hack-cli.mk

0
demo/hack/hack.mk → hack/hack.mk

89
internal/cmd/cmd.go

@ -0,0 +1,89 @@
package cmd
import (
"context"
"practice_Go/internal/controller/channel"
"practice_Go/internal/controller/clubPage"
"practice_Go/internal/controller/live"
"practice_Go/internal/controller/reservation"
"practice_Go/internal/controller/subscription"
"practice_Go/internal/middleware"
"practice_Go/internal/controller/mainPage"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
)
/*自定义的允许跨域请求中间件*/
func MiddlewareCORS(r *ghttp.Request) {
/* 没有起到应起到的作用,还是所有的都可以访问
//自定义授权跨域的Origin
corsOptions := r.Response.DefaultCORSOptions()
corsOptions.AllowDomain = []string{"localhost"} //数组中的为允许访问的
if !r.Response.CORSAllowedOrigin(corsOptions) {
r.Response.WriteStatus(http.StatusForbidden)
return
}
r.Response.CORS(corsOptions)
r.Middleware.Next()*/
//默认的跨域设置
r.Response.CORSDefault()
r.Middleware.Next()
}
var (
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Middleware(middleware.CustomResponseMiddleware)
group.Bind(
channel.NewV1(),
subscription.NewV1(),
live.NewV1(),
reservation.NewV1(),
)
})
// 定义一个路由组,路径为/mainpage
s.Group("/mainpage", func(group *ghttp.RouterGroup) {
// 添加中间件,用于处理响应
//group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Middleware(MiddlewareCORS)
// 绑定路由,将mainPage.NewMainPage()绑定到该路由组
//group.Bind(
// mainPage.NewMainPage(),
//)
group.GET("/get-shows", mainPage.NewMainPage().GetShows)
group.GET("/get-videos", mainPage.NewMainPage().GetVideos)
})
// 定义一个路由组,路径为/clubpage
s.Group("/clubpage", func(group *ghttp.RouterGroup) {
// 添加中间件,用于处理响应
//group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Middleware(MiddlewareCORS)
// 绑定路由,将mainPage.NewMainPage()绑定到该路由组
//group.Bind(
// clubPage.NewClubPage(),
//)
group.GET("/get-club", clubPage.NewClubPage().GetClub)
group.GET("/get-club-shows", clubPage.NewClubPage().GetClubShows)
})
//开启静态资源
s.SetServerRoot("resource/public")
s.SetOpenApiPath("/api.json") //启用OpenAPIv3,并设置OpenAPI文档的路径
s.SetSwaggerPath("/swagger") //启用内置的Swagger接口文档UI,并设置Swagger文档的路径
s.Run()
return nil
},
}
)

0
demo/internal/consts/consts.go → internal/consts/consts.go

5
internal/controller/channel/channel.go

@ -0,0 +1,5 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package channel

15
internal/controller/channel/channel_new.go

@ -0,0 +1,15 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package channel
import (
"practice_Go/api/channel"
)
type ControllerV1 struct{}
func NewV1() channel.IChannelV1 {
return &ControllerV1{}
}

25
internal/controller/channel/channel_v1_get_channel.go

@ -0,0 +1,25 @@
package channel
import (
"context"
"practice_Go/api/channel/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/dto"
"practice_Go/internal/model/entity"
)
func (c *ControllerV1) GetChannel(ctx context.Context, req *v1.GetChannelReq) (*dto.Result, error) {
res := v1.GetChannelRes{}
err := dao.GoChannels.Ctx(ctx).WherePri(req.Id).Scan(&res.Channel)
query := dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).Where("channel_id =?", req.Id)
if req.FlagType != 0 {
query = query.Where("flag_type =?", req.FlagType)
}
err = query.Scan(&res.List)
res.Channel.Status, err = dao.GoChannelSubscriptions.Ctx(ctx).Wheref("channel_id =? and user_id =?", req.Id, req.UserId).Exist()
if err != nil {
return dto.Error(err.Error()), nil
}
return dto.SuccessWithData(res), nil
}

18
internal/controller/channel/channel_v1_get_channel_list.go

@ -0,0 +1,18 @@
package channel
import (
"context"
"practice_Go/api/channel/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/dto"
)
func (c *ControllerV1) GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (*dto.Result, error) {
res := v1.GetChannelListRes{}
err := dao.GoChannels.Ctx(ctx).Fields("id, name").Scan(&res.List)
if err!= nil {
return dto.Error(err.Error()), nil
}
return dto.SuccessWithData(res.List), nil
}

66
internal/controller/clubPage/clubPage.go

@ -0,0 +1,66 @@
package clubPage
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"practice_Go/internal/model/dto"
"practice_Go/internal/service"
)
type ClubPage struct{}
func NewClubPage() *ClubPage {
return &ClubPage{}
}
// GetClub 获取俱乐部信息
func (c ClubPage) GetClub(req *ghttp.Request) {
i := ghttp.RequestFromCtx(req.Context()).Get("id").Int()
if i > 0 && i <= 4 {
club, err := service.GetClubs().GetClubs(req.Context())
if err == nil {
req.Response.WriteJson(dto.Result{
Code: 200,
Message: "success",
Data: club,
})
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "error",
Data: err,
})
}
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "传来俱乐部id信息不对",
})
}
}
func (c ClubPage) GetClubShows(req *ghttp.Request) {
i := g.RequestFromCtx(req.Context()).Get("id").Int()
if i > 0 && i <= 4 {
shows, err := service.GetClubs().GetClubShows(req.Context())
if err == nil {
req.Response.WriteJson(dto.Result{
Code: 200,
Message: "success",
Data: shows,
})
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "error",
Data: err,
})
}
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "传来俱乐部id信息不对",
})
}
}

2
demo/internal/controller/hello/hello.go → internal/controller/live/live.go

@ -2,4 +2,4 @@
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package hello
package live

9
demo/internal/controller/hello/hello_new.go → internal/controller/live/live_new.go

@ -1,16 +1,15 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package hello
package live
import (
"demo/api/hello"
"practice_Go/api/live"
)
type ControllerV1 struct{}
func NewV1() hello.IHelloV1 {
func NewV1() live.ILiveV1 {
return &ControllerV1{}
}

24
internal/controller/live/live_v1_get_live.go

@ -0,0 +1,24 @@
package live
import (
"context"
"time"
"practice_Go/api/live/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/dto"
"practice_Go/internal/model/entity"
)
func (c *ControllerV1) GetLive(ctx context.Context, req *v1.GetLiveReq) (*dto.Result, error) {
res := v1.GetLiveRes{}
now := time.Now()
err := dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).Where("start_time >=? or status = 1", now).Order("status desc, start_time asc").Scan(&res.List)
for i, live := range res.List {
res.List[i].Reservation, err = dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", live.Id, req.UserId).Count()
}
if err != nil {
return dto.Error(err.Error()), nil
}
return dto.SuccessWithData(res.List), nil
}

69
internal/controller/mainPage/mainPage.go

@ -0,0 +1,69 @@
package mainPage
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"practice_Go/internal/model/dto"
"practice_Go/internal/service"
)
// 定义一个MainPage结构体
type MainPage struct{}
// 创建一个新的MainPage实例 初始化
func NewMainPage() *MainPage {
return &MainPage{}
}
// 获取文章,视频
func (c *MainPage) GetShows(req *ghttp.Request) {
i := g.RequestFromCtx(req.Context()).Get("flagType").Int()
if i >= 0 && i <= 2 {
shows, err := service.GetShows().GetShows(req.Context())
if err == nil {
req.Response.WriteJson(dto.Result{
Code: 200,
Message: "success",
Data: shows,
})
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "error",
Data: err,
})
}
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "传参不对",
})
}
}
// 获取视频
func (c *MainPage) GetVideos(req *ghttp.Request) {
i := g.RequestFromCtx(req.Context()).Get("flagType").Int()
if i == 0 || i == 1 || i == 2 {
shows, err := service.GetShows().GetVideos(req.Context())
if err == nil {
req.Response.WriteJson(dto.Result{
Code: 200,
Message: "success",
Data: shows,
})
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "error",
Data: err,
})
}
} else {
req.Response.WriteJson(dto.Result{
Code: 500,
Message: "传参不对",
})
}
}

5
internal/controller/reservation/reservation.go

@ -0,0 +1,5 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package reservation

15
internal/controller/reservation/reservation_new.go

@ -0,0 +1,15 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package reservation
import (
"practice_Go/api/reservation"
)
type ControllerV1 struct{}
func NewV1() reservation.IReservationV1 {
return &ControllerV1{}
}

23
internal/controller/reservation/reservation_v1_add_reservation.go

@ -0,0 +1,23 @@
package reservation
import (
"context"
"practice_Go/api/reservation/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/do"
"practice_Go/internal/model/dto"
)
func (c *ControllerV1) AddReservation(ctx context.Context, req *v1.AddReservationReq) (*dto.Result, error) {
res := &v1.AddReservationRes{}
_, err := dao.GoLiveReservations.Ctx(ctx).Data(do.GoLiveReservations{
LiveId: req.Id,
UserId: req.UserId,
}).Insert()
if err != nil {
return dto.Error(err.Error()), nil
}
res.Success = true
return dto.SuccessWithData(res), nil
}

19
internal/controller/reservation/reservation_v1_delete_reservation.go

@ -0,0 +1,19 @@
package reservation
import (
"context"
"practice_Go/api/reservation/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/dto"
)
func (c *ControllerV1) DeleteReservation(ctx context.Context, req *v1.DeleteReservationReq) (*dto.Result, error) {
res := &v1.DeleteReservationRes{}
_, err := dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", req.Id, req.UserId).Delete()
if err != nil {
return dto.Error(err.Error()), nil
}
res.Success = true
return dto.SuccessWithData(res), nil
}

5
internal/controller/subscription/subscription.go

@ -0,0 +1,5 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package subscription

15
internal/controller/subscription/subscription_new.go

@ -0,0 +1,15 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package subscription
import (
"practice_Go/api/subscription"
)
type ControllerV1 struct{}
func NewV1() subscription.ISubscriptionV1 {
return &ControllerV1{}
}

24
internal/controller/subscription/subscription_v1_add_subscription.go

@ -0,0 +1,24 @@
package subscription
import (
"context"
"practice_Go/api/subscription/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/do"
"practice_Go/internal/model/dto"
)
func (c *ControllerV1) AddSubscription(ctx context.Context, req *v1.AddSubscriptionReq) (*dto.Result, error) {
res := v1.AddSubscriptionRes{}
_, err := dao.GoChannelSubscriptions.Ctx(ctx).Data(do.GoChannelSubscriptions{
ChannelId: req.Id,
UserId: req.UserId,
}).Insert()
_, err = dao.GoChannels.Ctx(ctx).Where("id",req.Id).Increment("subscription_count",1)
if err != nil {
return dto.Error(err.Error()), nil
}
res.Success = true
return dto.SuccessWithData(res), nil
}

20
internal/controller/subscription/subscription_v1_delete_subscription.go

@ -0,0 +1,20 @@
package subscription
import (
"context"
"practice_Go/api/subscription/v1"
"practice_Go/internal/dao"
"practice_Go/internal/model/dto"
)
func (c *ControllerV1) DeleteSubscription(ctx context.Context, req *v1.DeleteSubscriptionReq) (*dto.Result, error) {
res := &v1.DeleteSubscriptionRes{}
_, err := dao.GoChannelSubscriptions.Ctx(ctx).Wheref("channel_id =? and user_id =?", req.Id, req.UserId).Delete()
_, err = dao.GoChannels.Ctx(ctx).Where("id",req.Id).Decrement("subscription_count",1)
if err != nil {
return dto.Error(err.Error()), nil
}
res.Success = true
return dto.SuccessWithData(res), nil
}

0
demo/internal/dao/.gitkeep → internal/dao/.gitkeep

27
internal/dao/go_channel_subscriptions.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoChannelSubscriptionsDao is internal type for wrapping internal DAO implements.
type internalGoChannelSubscriptionsDao = *internal.GoChannelSubscriptionsDao
// goChannelSubscriptionsDao is the data access object for table go_channel_subscriptions.
// You can define custom methods on it to extend its functionality as you wish.
type goChannelSubscriptionsDao struct {
internalGoChannelSubscriptionsDao
}
var (
// GoChannelSubscriptions is globally public accessible object for table go_channel_subscriptions operations.
GoChannelSubscriptions = goChannelSubscriptionsDao{
internal.NewGoChannelSubscriptionsDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_channels.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoChannelsDao is internal type for wrapping internal DAO implements.
type internalGoChannelsDao = *internal.GoChannelsDao
// goChannelsDao is the data access object for table go_channels.
// You can define custom methods on it to extend its functionality as you wish.
type goChannelsDao struct {
internalGoChannelsDao
}
var (
// GoChannels is globally public accessible object for table go_channels operations.
GoChannels = goChannelsDao{
internal.NewGoChannelsDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_clubs.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoClubsDao is internal type for wrapping internal DAO implements.
type internalGoClubsDao = *internal.GoClubsDao
// goClubsDao is the data access object for table go_clubs.
// You can define custom methods on it to extend its functionality as you wish.
type goClubsDao struct {
internalGoClubsDao
}
var (
// GoClubs is globally public accessible object for table go_clubs operations.
GoClubs = goClubsDao{
internal.NewGoClubsDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_live_reservations.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoLiveReservationsDao is internal type for wrapping internal DAO implements.
type internalGoLiveReservationsDao = *internal.GoLiveReservationsDao
// goLiveReservationsDao is the data access object for table go_live_reservations.
// You can define custom methods on it to extend its functionality as you wish.
type goLiveReservationsDao struct {
internalGoLiveReservationsDao
}
var (
// GoLiveReservations is globally public accessible object for table go_live_reservations operations.
GoLiveReservations = goLiveReservationsDao{
internal.NewGoLiveReservationsDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_lives.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoLivesDao is internal type for wrapping internal DAO implements.
type internalGoLivesDao = *internal.GoLivesDao
// goLivesDao is the data access object for table go_lives.
// You can define custom methods on it to extend its functionality as you wish.
type goLivesDao struct {
internalGoLivesDao
}
var (
// GoLives is globally public accessible object for table go_lives operations.
GoLives = goLivesDao{
internal.NewGoLivesDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_shows.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoShowsDao is internal type for wrapping internal DAO implements.
type internalGoShowsDao = *internal.GoShowsDao
// goShowsDao is the data access object for table go_shows.
// You can define custom methods on it to extend its functionality as you wish.
type goShowsDao struct {
internalGoShowsDao
}
var (
// GoShows is globally public accessible object for table go_shows operations.
GoShows = goShowsDao{
internal.NewGoShowsDao(),
}
)
// Fill with you ideas below.

27
internal/dao/go_users.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"practice_Go/internal/dao/internal"
)
// internalGoUsersDao is internal type for wrapping internal DAO implements.
type internalGoUsersDao = *internal.GoUsersDao
// goUsersDao is the data access object for table go_users.
// You can define custom methods on it to extend its functionality as you wish.
type goUsersDao struct {
internalGoUsersDao
}
var (
// GoUsers is globally public accessible object for table go_users operations.
GoUsers = goUsersDao{
internal.NewGoUsersDao(),
}
)
// Fill with you ideas below.

77
internal/dao/internal/go_channel_subscriptions.go

@ -0,0 +1,77 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoChannelSubscriptionsDao is the data access object for table go_channel_subscriptions.
type GoChannelSubscriptionsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoChannelSubscriptionsColumns // columns contains all the column names of Table for convenient usage.
}
// GoChannelSubscriptionsColumns defines and stores column names for table go_channel_subscriptions.
type GoChannelSubscriptionsColumns struct {
Id string // 频道订阅关系唯一ID,自增
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ChannelId string // 关联的频道ID,指向go_channels表的id,不能为空
}
// goChannelSubscriptionsColumns holds the columns for table go_channel_subscriptions.
var goChannelSubscriptionsColumns = GoChannelSubscriptionsColumns{
Id: "id",
UserId: "user_id",
ChannelId: "channel_id",
}
// NewGoChannelSubscriptionsDao creates and returns a new DAO object for table data access.
func NewGoChannelSubscriptionsDao() *GoChannelSubscriptionsDao {
return &GoChannelSubscriptionsDao{
group: "default",
table: "go_channel_subscriptions",
columns: goChannelSubscriptionsColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoChannelSubscriptionsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoChannelSubscriptionsDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoChannelSubscriptionsDao) Columns() GoChannelSubscriptionsColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoChannelSubscriptionsDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoChannelSubscriptionsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoChannelSubscriptionsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

81
internal/dao/internal/go_channels.go

@ -0,0 +1,81 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoChannelsDao is the data access object for table go_channels.
type GoChannelsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoChannelsColumns // columns contains all the column names of Table for convenient usage.
}
// GoChannelsColumns defines and stores column names for table go_channels.
type GoChannelsColumns struct {
Id string // 频道唯一ID,自增
Image string // 频道图片路径或相关标识,可为空
Name string // 频道名称,最大长度255字符,不能为空
SubscriptionCount string // 频道订阅数量,初始值为0,可累加
BackgroundImage string // 频道背景图路径或相关标识,可为空
}
// goChannelsColumns holds the columns for table go_channels.
var goChannelsColumns = GoChannelsColumns{
Id: "id",
Image: "image",
Name: "name",
SubscriptionCount: "subscription_count",
BackgroundImage: "background_image",
}
// NewGoChannelsDao creates and returns a new DAO object for table data access.
func NewGoChannelsDao() *GoChannelsDao {
return &GoChannelsDao{
group: "default",
table: "go_channels",
columns: goChannelsColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoChannelsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoChannelsDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoChannelsDao) Columns() GoChannelsColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoChannelsDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoChannelsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoChannelsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

79
internal/dao/internal/go_clubs.go

@ -0,0 +1,79 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoClubsDao is the data access object for table go_clubs.
type GoClubsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoClubsColumns // columns contains all the column names of Table for convenient usage.
}
// GoClubsColumns defines and stores column names for table go_clubs.
type GoClubsColumns struct {
Id string // 俱乐部唯一ID,自增
Image string // 俱乐部图片路径或相关标识,可为空
Name string // 俱乐部名称,最大长度255字符,不能为空
Introduction string // 俱乐部简介,文本内容,可为空
}
// goClubsColumns holds the columns for table go_clubs.
var goClubsColumns = GoClubsColumns{
Id: "id",
Image: "image",
Name: "name",
Introduction: "introduction",
}
// NewGoClubsDao creates and returns a new DAO object for table data access.
func NewGoClubsDao() *GoClubsDao {
return &GoClubsDao{
group: "default",
table: "go_clubs",
columns: goClubsColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoClubsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoClubsDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoClubsDao) Columns() GoClubsColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoClubsDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoClubsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoClubsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

77
internal/dao/internal/go_live_reservations.go

@ -0,0 +1,77 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoLiveReservationsDao is the data access object for table go_live_reservations.
type GoLiveReservationsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoLiveReservationsColumns // columns contains all the column names of Table for convenient usage.
}
// GoLiveReservationsColumns defines and stores column names for table go_live_reservations.
type GoLiveReservationsColumns struct {
Id string // 直播预约关系唯一ID,自增
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveId string // 关联的直播ID,指向go_lives表的id,不能为空
}
// goLiveReservationsColumns holds the columns for table go_live_reservations.
var goLiveReservationsColumns = GoLiveReservationsColumns{
Id: "id",
UserId: "user_id",
LiveId: "live_id",
}
// NewGoLiveReservationsDao creates and returns a new DAO object for table data access.
func NewGoLiveReservationsDao() *GoLiveReservationsDao {
return &GoLiveReservationsDao{
group: "default",
table: "go_live_reservations",
columns: goLiveReservationsColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoLiveReservationsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoLiveReservationsDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoLiveReservationsDao) Columns() GoLiveReservationsColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoLiveReservationsDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoLiveReservationsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoLiveReservationsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

83
internal/dao/internal/go_lives.go

@ -0,0 +1,83 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoLivesDao is the data access object for table go_lives.
type GoLivesDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoLivesColumns // columns contains all the column names of Table for convenient usage.
}
// GoLivesColumns defines and stores column names for table go_lives.
type GoLivesColumns struct {
Id string // 直播唯一ID,自增
Cover string // 直播封面路径或相关标识,可为空
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveName string // 直播名称,最大长度255字符,不能为空
StartTime string // 直播开始时间,不能为空
Status string // 直播状态,0:未开播 1:已开播,不能为空
}
// goLivesColumns holds the columns for table go_lives.
var goLivesColumns = GoLivesColumns{
Id: "id",
Cover: "cover",
UserId: "user_id",
LiveName: "live_name",
StartTime: "start_time",
Status: "status",
}
// NewGoLivesDao creates and returns a new DAO object for table data access.
func NewGoLivesDao() *GoLivesDao {
return &GoLivesDao{
group: "default",
table: "go_lives",
columns: goLivesColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoLivesDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoLivesDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoLivesDao) Columns() GoLivesColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoLivesDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoLivesDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoLivesDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

95
internal/dao/internal/go_shows.go

@ -0,0 +1,95 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoShowsDao is the data access object for table go_shows.
type GoShowsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoShowsColumns // columns contains all the column names of Table for convenient usage.
}
// GoShowsColumns defines and stores column names for table go_shows.
type GoShowsColumns struct {
Id string // 展示内容唯一ID,自增
Cover string // 展示内容封面路径或相关标识,可为空
Name string // 展示内容名称,最大长度255字符,不能为空
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ReleaseTime string // 展示内容发布时间,可为空
VideoDuration string // 展示内容视频时长,格式根据实际情况定,可为空
ViewCount string // 展示内容观看数量,初始值为0,可累加
Comments string // 展示内容评论数量,初始值为0,可累加
Likes string // 展示内容点赞数量,初始值为0,可累加
FlagType string // 展示内容标识类型,按业务规则确定,可为空
ClubId string // 关联的俱乐部ID,指向go_clubs表的id,可为空
ChannelId string // 关联的频道ID,指向go_channels表的id,可为空
}
// goShowsColumns holds the columns for table go_shows.
var goShowsColumns = GoShowsColumns{
Id: "id",
Cover: "cover",
Name: "name",
UserId: "user_id",
ReleaseTime: "release_time",
VideoDuration: "video_duration",
ViewCount: "view_count",
Comments: "comments",
Likes: "likes",
FlagType: "flag_type",
ClubId: "club_id",
ChannelId: "channel_id",
}
// NewGoShowsDao creates and returns a new DAO object for table data access.
func NewGoShowsDao() *GoShowsDao {
return &GoShowsDao{
group: "default",
table: "go_shows",
columns: goShowsColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoShowsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoShowsDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoShowsDao) Columns() GoShowsColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoShowsDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoShowsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoShowsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

79
internal/dao/internal/go_users.go

@ -0,0 +1,79 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GoUsersDao is the data access object for table go_users.
type GoUsersDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GoUsersColumns // columns contains all the column names of Table for convenient usage.
}
// GoUsersColumns defines and stores column names for table go_users.
type GoUsersColumns struct {
Id string // 用户唯一ID,自增,长度为8位整数
Username string // 用户名,最大长度255字符,不能为空
Avatar string // 用户头像路径或相关标识,可为空
Password string // 用户登录密码,最大长度255字符,不能为空
}
// goUsersColumns holds the columns for table go_users.
var goUsersColumns = GoUsersColumns{
Id: "id",
Username: "username",
Avatar: "avatar",
Password: "password",
}
// NewGoUsersDao creates and returns a new DAO object for table data access.
func NewGoUsersDao() *GoUsersDao {
return &GoUsersDao{
group: "default",
table: "go_users",
columns: goUsersColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GoUsersDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GoUsersDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GoUsersDao) Columns() GoUsersColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GoUsersDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GoUsersDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GoUsersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

0
demo/internal/logic/.gitkeep → internal/logic/.gitkeep

52
internal/logic/clubs/clubs.go

@ -0,0 +1,52 @@
package clubs
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"practice_Go/internal/dao"
"practice_Go/internal/model/do"
"practice_Go/internal/model/entity"
"practice_Go/internal/service"
)
// 1.注册
func init() {
service.RegisterClubs(&sClubs{})
}
type sClubs struct{}
func (c sClubs) GetClubs(ctx context.Context) (clubs []entity.GoClubs, err error) {
clubId := g.RequestFromCtx(ctx).Get("id").Int()
if clubId == 0 {
panic("获取俱乐部信息时id不能为空")
} else {
err = dao.GoClubs.Ctx(ctx).Where("id", clubId).Scan(&clubs) //查询数据库, 并将可能出现的错误赋给err
}
return
}
func (c sClubs) GetClubShows(ctx context.Context) (shows []entity.GoShows, err error) {
clubId := g.RequestFromCtx(ctx).Get("id").Int()
if clubId == 0 {
panic("获取俱乐部内容时id不能为空")
} else {
err = dao.GoShows.Ctx(ctx).FieldsEx("club").With(entity.GoUsers{}).Where("club_id", clubId).Scan(&shows)
}
return
}
func (c sClubs) AddClub(ctx context.Context, club do.GoShows) (err error) {
//TODO implement me
panic("implement me")
}
func (c sClubs) EditClub(ctx context.Context, club do.GoClubs) (err error) {
//TODO implement me
panic("implement me")
}
func (c sClubs) DeleteClub(ctx context.Context) (err error) {
//TODO implement me
panic("implement me")
}

8
internal/logic/logic.go

@ -0,0 +1,8 @@
package logic
import (
_ "practice_Go/internal/logic/clubs"
_ "practice_Go/internal/logic/shows"
)
//如果这里导入了文件后还是说未注册就将在main.go文件中导入logic包

60
internal/logic/shows/shows.go

@ -0,0 +1,60 @@
package shows
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"practice_Go/internal/dao"
"practice_Go/internal/model/do"
"practice_Go/internal/model/entity"
"practice_Go/internal/service"
)
func init() {
//GoFrame没有自动注册, 将sShow结构体的实例注册到服务中, 供其他部分访问
service.RegisterShows(&sShow{}) //GoFrame没有自动注册 另外还需要在logic包下创建一个logic.go文件,并在其中导入本文件所在的shows包
}
// 定义一个sShow结构体,供其他部分访问下面的方法
type sShow struct{}
// 定义一个方法,用于获取所有节目
func (s sShow) GetShows(ctx context.Context) (shows []entity.GoShows, err error) {
// 使用dao包中的GoShows结构体,在指定的上下文中扫描数据,并将结果存储在shows变量中
flagType := g.RequestFromCtx(ctx).Get("flagType").Int()
if flagType != 0 {
err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}, entity.GoClubs{}).Where("flag_type", flagType).Scan(&shows) //err用于存储过程中可能出现的错误,结果直接存到shows中了
} else {
err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).With(entity.GoClubs{}).Scan(&shows)
}
// 返回结果
return
}
// 定义一个方法,用于获取视频列表
func (s sShow) GetVideos(ctx context.Context) (videos []entity.GoShows, err error) {
// 使用dao包中的GoShows结构体,在指定的上下文中扫描视频列表
flagType := g.RequestFromCtx(ctx).Get("flagType").Int()
if flagType != 0 {
err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}, entity.GoClubs{}).Where("flag_type", flagType).OrderDesc("release_time").Scan(&videos) //err用于存储过程中可能出现的错误,结果直接存到shows中了
} else {
err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).With(entity.GoClubs{}).OrderDesc("release_time").Scan(&videos)
}
// 返回视频列表和错误信息
return
}
func (s sShow) AddShow(ctx context.Context, show do.GoShows) (err error) {
//TODO implement me
panic("implement me")
}
func (s sShow) EditShow(ctx context.Context, show do.GoShows) (err error) {
//TODO implement me
panic("implement me")
}
func (s sShow) DeleteShow(ctx context.Context) (err error) {
//TODO implement me
panic("implement me")
}

24
internal/middleware/middleware.go

@ -0,0 +1,24 @@
package middleware
import (
"github.com/gogf/gf/v2/net/ghttp"
)
// CustomResponseMiddleware 自定义响应中间件,处理嵌套问题
func CustomResponseMiddleware(r *ghttp.Request) {
// 执行下一个中间件或处理程序
r.Middleware.Next()
// 获取处理程序的响应内容
response := r.GetHandlerResponse()
if response == nil {
// 如果没有响应内容,则直接返回
return
}
// 清空原始响应缓冲区,避免重复输出
r.Response.ClearBuffer()
// 自定义返回格式,避免嵌套
r.Response.WriteJson(response)
}

0
demo/internal/model/.gitkeep → internal/model/.gitkeep

0
demo/internal/model/do/.gitkeep → internal/model/do/.gitkeep

17
internal/model/do/go_channel_subscriptions.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GoChannelSubscriptions is the golang structure of table go_channel_subscriptions for DAO operations like Where/Data.
type GoChannelSubscriptions struct {
g.Meta `orm:"table:go_channel_subscriptions, do:true"`
Id interface{} // 频道订阅关系唯一ID,自增
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ChannelId interface{} // 关联的频道ID,指向go_channels表的id,不能为空
}

19
internal/model/do/go_channels.go

@ -0,0 +1,19 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GoChannels is the golang structure of table go_channels for DAO operations like Where/Data.
type GoChannels struct {
g.Meta `orm:"table:go_channels, do:true"`
Id interface{} // 频道唯一ID,自增
Image interface{} // 频道图片路径或相关标识,可为空
Name interface{} // 频道名称,最大长度255字符,不能为空
SubscriptionCount interface{} // 频道订阅数量,初始值为0,可累加
BackgroundImage interface{} // 频道背景图路径或相关标识,可为空
}

18
internal/model/do/go_clubs.go

@ -0,0 +1,18 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GoClubs is the golang structure of table go_clubs for DAO operations like Where/Data.
type GoClubs struct {
g.Meta `orm:"table:go_clubs, do:true"`
Id interface{} // 俱乐部唯一ID,自增
Image interface{} // 俱乐部图片路径或相关标识,可为空
Name interface{} // 俱乐部名称,最大长度255字符,不能为空
Introduction interface{} // 俱乐部简介,文本内容,可为空
}

17
internal/model/do/go_live_reservations.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GoLiveReservations is the golang structure of table go_live_reservations for DAO operations like Where/Data.
type GoLiveReservations struct {
g.Meta `orm:"table:go_live_reservations, do:true"`
Id interface{} // 直播预约关系唯一ID,自增
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveId interface{} // 关联的直播ID,指向go_lives表的id,不能为空
}

21
internal/model/do/go_lives.go

@ -0,0 +1,21 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// GoLives is the golang structure of table go_lives for DAO operations like Where/Data.
type GoLives struct {
g.Meta `orm:"table:go_lives, do:true"`
Id interface{} // 直播唯一ID,自增
Cover interface{} // 直播封面路径或相关标识,可为空
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveName interface{} // 直播名称,最大长度255字符,不能为空
StartTime *gtime.Time // 直播开始时间,不能为空
Status interface{} // 直播状态,0:未开播 1:已开播,不能为空
}

27
internal/model/do/go_shows.go

@ -0,0 +1,27 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// GoShows is the golang structure of table go_shows for DAO operations like Where/Data.
type GoShows struct {
g.Meta `orm:"table:go_shows, do:true"`
Id interface{} // 展示内容唯一ID,自增
Cover interface{} // 展示内容封面路径或相关标识,可为空
Name interface{} // 展示内容名称,最大长度255字符,不能为空
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ReleaseTime *gtime.Time // 展示内容发布时间,可为空
VideoDuration *gtime.Time // 展示内容视频时长,格式根据实际情况定,可为空
ViewCount interface{} // 展示内容观看数量,初始值为0,可累加
Comments interface{} // 展示内容评论数量,初始值为0,可累加
Likes interface{} // 展示内容点赞数量,初始值为0,可累加
FlagType interface{} // 展示内容标识类型,按业务规则确定,可为空
ClubId interface{} // 关联的俱乐部ID,指向go_clubs表的id,可为空
ChannelId interface{} // 关联的频道ID,指向go_channels表的id,可为空
}

18
internal/model/do/go_users.go

@ -0,0 +1,18 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GoUsers is the golang structure of table go_users for DAO operations like Where/Data.
type GoUsers struct {
g.Meta `orm:"table:go_users, do:true"`
Id interface{} // 用户唯一ID,自增,长度为8位整数
Username interface{} // 用户名,最大长度255字符,不能为空
Avatar interface{} // 用户头像路径或相关标识,可为空
Password interface{} // 用户登录密码,最大长度255字符,不能为空
}

66
internal/model/dto/Result.go

@ -0,0 +1,66 @@
package dto
import (
"github.com/gogf/gf/v2/frame/g"
)
// 定义响应结构
type Result struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"` // 修改为实体类型
}
/*成功,没有数据*/
func Success() *Result {
return &Result{
Code: 200,
Message: "success",
Data: g.Map{},
}
}
/*成功,有数据*/
func SuccessWithData(data interface{}) *Result {
return &Result{
Code: 200,
Message: "success",
Data: data,
}
}
/*错误,只有错误信息,错误码0*/
func Error(msg string) *Result {
return &Result{
Code: 0, // 错误码
Message: msg, // 错误信息
Data: g.Map{},
}
}
/*错误,有错误信息,有错误码*/
func ErrorWithCode(code int, msg string) *Result {
return &Result{
Code: code, // 错误码
Message: msg, // 错误信息
Data: g.Map{},
}
}
/*未授权,有错误信息,错误码为401*/
func Unauthorized(msg string) *Result {
return &Result{
Code: 401, // 错误码
Message: msg, // 错误信息
Data: g.Map{},
}
}
/*未授权,有错误信息,允许自定义错误码*/
func UnauthorizedWithCode(code int, msg string) *Result {
return &Result{
Code: code, // 错误码
Message: msg, // 错误信息
Data: g.Map{},
}
}

0
demo/internal/model/entity/.gitkeep → internal/model/entity/.gitkeep

12
internal/model/entity/go_channel_subscriptions.go

@ -0,0 +1,12 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GoChannelSubscriptions is the golang structure for table go_channel_subscriptions.
type GoChannelSubscriptions struct {
Id int `json:"id" orm:"id" description:"频道订阅关系唯一ID,自增"` // 频道订阅关系唯一ID,自增
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ChannelId int `json:"channelId" orm:"channel_id" description:"关联的频道ID,指向go_channels表的id,不能为空"` // 关联的频道ID,指向go_channels表的id,不能为空
}

14
internal/model/entity/go_channels.go

@ -0,0 +1,14 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GoChannels is the golang structure for table go_channels.
type GoChannels struct {
Id int `json:"id" orm:"id" description:"频道唯一ID,自增"` // 频道唯一ID,自增
Image string `json:"image" orm:"image" description:"频道图片路径或相关标识,可为空"` // 频道图片路径或相关标识,可为空
Name string `json:"name" orm:"name" description:"频道名称,最大长度255字符,不能为空"` // 频道名称,最大长度255字符,不能为空
SubscriptionCount int `json:"subscriptionCount" orm:"subscription_count" description:"频道订阅数量,初始值为0,可累加"` // 频道订阅数量,初始值为0,可累加
BackgroundImage string `json:"backgroundImage" orm:"background_image" description:"频道背景图路径或相关标识,可为空"` // 频道背景图路径或相关标识,可为空
}

13
internal/model/entity/go_clubs.go

@ -0,0 +1,13 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GoClubs is the golang structure for table go_clubs.
type GoClubs struct {
Id int `json:"id" orm:"id" description:"俱乐部唯一ID,自增"` // 俱乐部唯一ID,自增
Image string `json:"image" orm:"image" description:"俱乐部图片路径或相关标识,可为空"` // 俱乐部图片路径或相关标识,可为空
Name string `json:"name" orm:"name" description:"俱乐部名称,最大长度255字符,不能为空"` // 俱乐部名称,最大长度255字符,不能为空
Introduction string `json:"introduction" orm:"introduction" description:"俱乐部简介,文本内容,可为空"` // 俱乐部简介,文本内容,可为空
}

12
internal/model/entity/go_live_reservations.go

@ -0,0 +1,12 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GoLiveReservations is the golang structure for table go_live_reservations.
type GoLiveReservations struct {
Id int `json:"id" orm:"id" description:"直播预约关系唯一ID,自增"` // 直播预约关系唯一ID,自增
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveId int `json:"liveId" orm:"live_id" description:"关联的直播ID,指向go_lives表的id,不能为空"` // 关联的直播ID,指向go_lives表的id,不能为空
}

20
internal/model/entity/go_lives.go

@ -0,0 +1,20 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// GoLives is the golang structure for table go_lives.
type GoLives struct {
Id int `json:"id" orm:"id" description:"直播唯一ID,自增"` // 直播唯一ID,自增
Cover string `json:"cover" orm:"cover" description:"直播封面路径或相关标识,可为空"` // 直播封面路径或相关标识,可为空
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
User *GoUsers `json:"user" orm:"with:id=user_id" description:"关联的用户信息"` // 关联的用户信息
LiveName string `json:"liveName" orm:"live_name" description:"直播名称,最大长度255字符,不能为空"` // 直播名称,最大长度255字符,不能为空
StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"直播开始时间,不能为空"` // 直播开始时间,不能为空
Status int `json:"status" orm:"status" description:"直播状态,0:未开播 1:已开播,不能为空"` // 直播状态,0:未开播 1:已开播,不能为空
}

28
internal/model/entity/go_shows.go

@ -0,0 +1,28 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// GoShows is the golang structure for table go_shows.
type GoShows struct {
Id int `json:"id" orm:"id" description:"展示内容唯一ID,自增"` // 展示内容唯一ID,自增
Cover string `json:"cover" orm:"cover" description:"展示内容封面路径或相关标识,可为空"` // 展示内容封面路径或相关标识,可为空
Name string `json:"name" orm:"name" description:"展示内容名称,最大长度255字符,不能为空"` // 展示内容名称,最大长度255字符,不能为空
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
ReleaseTime *gtime.Time `json:"releaseTime" orm:"release_time" description:"展示内容发布时间,可为空"` // 展示内容发布时间,可为空
VideoDuration *gtime.Time `json:"videoDuration" orm:"video_duration" description:"展示内容视频时长,格式根据实际情况定,可为空"` // 展示内容视频时长,格式根据实际情况定,可为空
ViewCount int `json:"viewCount" orm:"view_count" description:"展示内容观看数量,初始值为0,可累加"` // 展示内容观看数量,初始值为0,可累加
Comments int `json:"comments" orm:"comments" description:"展示内容评论数量,初始值为0,可累加"` // 展示内容评论数量,初始值为0,可累加
Likes int `json:"likes" orm:"likes" description:"展示内容点赞数量,初始值为0,可累加"` // 展示内容点赞数量,初始值为0,可累加
FlagType int `json:"flagType" orm:"flag_type" description:"展示内容标识类型,按业务规则确定,可为空"` // 展示内容标识类型,按业务规则确定,可为空
ClubId int `json:"clubId" orm:"club_id" description:"关联的俱乐部ID,指向go_clubs表的id,可为空"` // 关联的俱乐部ID,指向go_clubs表的id,可为空
ChannelId int `json:"channelId" orm:"channel_id" description:"关联的频道ID,指向go_channels表的id,可为空"` // 关联的频道ID,指向go_channels表的id,可为空
User *GoUsers `json:"user" orm:"with:id=user_id"`
Club *GoClubs `json:"club" orm:"with:id=club_id"`
}

13
internal/model/entity/go_users.go

@ -0,0 +1,13 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GoUsers is the golang structure for table go_users.
type GoUsers struct {
Id int `json:"id" orm:"id" description:"用户唯一ID,自增,长度为8位整数"` // 用户唯一ID,自增,长度为8位整数
Username string `json:"username" orm:"username" description:"用户名,最大长度255字符,不能为空"` // 用户名,最大长度255字符,不能为空
Avatar string `json:"avatar" orm:"avatar" description:"用户头像路径或相关标识,可为空"` // 用户头像路径或相关标识,可为空
//Password string `json:"password" orm:"password" description:"用户登录密码,最大长度255字符,不能为空"` // 用户登录密码,最大长度255字符,不能为空
}

0
demo/internal/packed/packed.go → internal/packed/packed.go

0
demo/internal/service/.gitkeep → internal/service/.gitkeep

34
internal/service/clubs.go

@ -0,0 +1,34 @@
package service
import (
"context"
"practice_Go/internal/model/do"
"practice_Go/internal/model/entity"
)
// 1.定义接口
type IClubs interface {
GetClubs(ctx context.Context) (clubs []entity.GoClubs, err error)
GetClubShows(ctx context.Context) (shows []entity.GoShows, err error)
AddClub(ctx context.Context, club do.GoShows) (err error)
EditClub(ctx context.Context, club do.GoClubs) (err error)
DeleteClub(ctx context.Context) (err error)
}
// 2.定义接口变量
var localClub IClubs
// 3.定义获取接口实例的函数
func GetClubs() IClubs {
if localClub == nil {
panic("IClubs接口未实现或未注册")
} else {
return localClub
}
}
// 4.定义一个接口实现的注册方法
func RegisterClubs(club IClubs) {
localClub = club
}

32
internal/service/shows.go

@ -0,0 +1,32 @@
package service
import (
"context"
"practice_Go/internal/model/do"
"practice_Go/internal/model/entity"
)
// 1.定义接口
type IShows interface {
GetShows(ctx context.Context) (shows []entity.GoShows, err error)
GetVideos(ctx context.Context) (videos []entity.GoShows, err error)
AddShow(ctx context.Context, show do.GoShows) (err error)
EditShow(ctx context.Context, show do.GoShows) (err error)
DeleteShow(ctx context.Context) (err error) //id通过路径中获取
}
// 2.定义接口变量
var localShow IShows
// 3.定义获取接口实例的函数
func GetShows() IShows {
if localShow == nil {
panic("IShows未实现或未注册")
}
return localShow
}
// 4.定义一个接口实现的注册方法
func RegisterShows(show IShows) {
localShow = show
}

38
main.go

@ -0,0 +1,38 @@
package main
import (
_ "practice_Go/internal/logic"
_ "practice_Go/internal/packed"
"github.com/gogf/gf/v2/os/gctx"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
"practice_Go/internal/cmd"
"fmt"
"log"
"net/http"
"github.com/rs/cors"
)
func main() {
cmd.Main.Run(gctx.GetInitCtx())
mux := http.NewServeMux()
mux.HandleFunc("/mainpage/get-shows", func(w http.ResponseWriter, r *http.Request) {
fmt.Println(w, "Show data")
})
// 创建CORS中间件,配置允许的源等信息
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://192.168.9.*:5173"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type, Authorization"},
})
handler := c.Handler(mux)
log.Fatal(http.ListenAndServe(":8080", handler))
}

15
manifest/config/config.yaml

@ -0,0 +1,15 @@
# https://goframe.org/docs/web/server-config-file-template
server:
address: ":8080"
openapiPath: "/api.json"
swaggerPath: "/swagger"
# https://goframe.org/docs/core/glog-config
logger:
level : "all"
stdout: true
# https://goframe.org/docs/core/gdb-config-file
database:
default:
link: "mysql:root:123456@tcp(127.0.0.1:3306)/practice?charset=utf8mb4&parseTime=True&loc=Local"

0
demo/manifest/deploy/kustomize/base/deployment.yaml → manifest/deploy/kustomize/base/deployment.yaml

0
demo/manifest/deploy/kustomize/base/kustomization.yaml → manifest/deploy/kustomize/base/kustomization.yaml

0
demo/manifest/deploy/kustomize/base/service.yaml → manifest/deploy/kustomize/base/service.yaml

0
demo/manifest/deploy/kustomize/overlays/develop/configmap.yaml → manifest/deploy/kustomize/overlays/develop/configmap.yaml

0
demo/manifest/deploy/kustomize/overlays/develop/deployment.yaml → manifest/deploy/kustomize/overlays/develop/deployment.yaml

0
demo/manifest/deploy/kustomize/overlays/develop/kustomization.yaml → manifest/deploy/kustomize/overlays/develop/kustomization.yaml

0
demo/manifest/docker/Dockerfile → manifest/docker/Dockerfile

0
demo/manifest/docker/docker.sh → manifest/docker/docker.sh

0
demo/manifest/i18n/.gitkeep → manifest/i18n/.gitkeep

0
demo/manifest/protobuf/.keep-if-necessary → manifest/protobuf/.keep-if-necessary

0
demo/resource/public/html/.gitkeep → resource/public/html/.gitkeep

532
resource/public/html/api.html
File diff suppressed because it is too large
View File

0
demo/resource/public/plugin/.gitkeep → resource/public/plugin/.gitkeep

0
demo/resource/public/resource/css/.gitkeep → resource/public/resource/css/.gitkeep

0
demo/resource/public/resource/image/.gitkeep → resource/public/resource/image/.gitkeep

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save