You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
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("flag_type").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("flag_type").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") }
|