Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"av.go",
"bfs.go",
"dao.go",
"daoAnchor.go",
"video.go",
],
importpath = "go-common/app/job/live/dao-anchor-job/internal/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/live/dao-anchor-job/internal/conf:go_default_library",
"//app/service/live/av/api/liverpc:go_default_library",
"//app/service/live/av/api/liverpc/v1:go_default_library",
"//app/service/live/dao-anchor/api/grpc/v0:go_default_library",
"//app/service/live/dao-anchor/api/grpc/v1:go_default_library",
"//app/service/video/stream-mng/api/v1:go_default_library",
"//library/database/bfs:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/rpc/liverpc:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,24 @@
package dao
import (
"context"
"go-common/app/service/live/av/api/liverpc/v1"
"go-common/library/log"
)
// GetFansMedalInfo 获取粉丝勋章信息
func (d *Dao) GetPkStatus(c context.Context, roomId int64) (resp *v1.PkGetPkStatusResp_Data, err error) {
reply, err := d.AvApi.V1Pk.GetPkStatus(c, &v1.PkGetPkStatusReq{RoomId: roomId})
if err != nil {
log.Error("av_GetPkStatus_error:%v", err)
return
}
if reply.Code != 0 {
log.Error("av_GetPkStatus_error:%d,%s,%v", reply.Code, reply.Msg, reply.Data)
return
}
log.Info("av_GetPkStatus:%d,%s,$v", reply.Code, reply.Msg, reply.Data)
resp = reply.Data
return
}

View File

@ -0,0 +1,56 @@
package dao
import (
"context"
"errors"
"io/ioutil"
"net/http"
"strconv"
"go-common/library/database/bfs"
"go-common/library/log"
)
const BUCKET = "live"
const FILE_PATH = "/data/www/cover/"
//上传至bfs相关接口
//ImgUpload 上传图片至bfs
func (d *Dao) ImgUpload(ctx context.Context, roomId int64, pic string, file []byte) (resp string, err error) {
log.Info("ImgUpload_start")
fileName := strconv.Itoa(int(roomId)) + ".jpg"
reply, err := d.BfsClient.Upload(ctx, &bfs.Request{
Bucket: BUCKET,
Dir: "",
ContentType: "",
Filename: fileName,
File: []byte(file),
})
if err != nil {
log.Error("ImgUpload_bfs_Upload_failed,err:%v", err)
return
}
resp = reply
return
}
func (d *Dao) ImgDownload(ctx context.Context, pic string) (resp []byte, err error) {
reply, err := http.Get(pic)
if err != nil {
log.Warn("ImgDownload_failed_err:%v", err)
return
}
defer reply.Body.Close()
if reply.StatusCode != 200 {
err = errors.New("curl error http code not equal to 200")
log.Warn("ImgDownload_failed_httpCode:%d", reply.StatusCode)
return
}
resp, err = ioutil.ReadAll(reply.Body)
if err != nil {
log.Warn("ImgDownload_read_err:%v", err)
return
}
return
}

View File

@ -0,0 +1,70 @@
package dao
import (
"context"
"go-common/app/job/live/dao-anchor-job/internal/conf"
av_api "go-common/app/service/live/av/api/liverpc"
daoAnchor_api_v0 "go-common/app/service/live/dao-anchor/api/grpc/v0"
daoAnchor_api "go-common/app/service/live/dao-anchor/api/grpc/v1"
video_api "go-common/app/service/video/stream-mng/api/v1"
"go-common/library/database/bfs"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/rpc/liverpc"
)
// Dao dao
type Dao struct {
c *conf.Config
AvApi *av_api.Client
daoAnchorApi *daoAnchor_api.Client
VideoApi video_api.StreamClient
BfsClient *bfs.BFS
HttpClient *bm.Client
daoAnchorApiV0 *daoAnchor_api_v0.Client
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
AvApi: av_api.New(getConf("av")),
BfsClient: bfs.New(c.BfsCli),
HttpClient: bm.NewClient(c.HttpCli),
}
daoAnchorApi, err := daoAnchor_api.NewClient(c.GrpcCli)
if err != nil {
panic(err)
}
dao.daoAnchorApi = daoAnchorApi
videoApi, err := video_api.NewClient(c.GrpcCli)
if err != nil {
panic(err)
}
dao.VideoApi = videoApi
daoAnchorApiV0, err := daoAnchor_api_v0.NewClient(c.GrpcCli)
if err != nil {
panic(err)
}
dao.daoAnchorApiV0 = daoAnchorApiV0
return
}
// Close close the resource.
func (d *Dao) Close() {
}
// Ping dao ping
func (d *Dao) Ping(ctx context.Context) error {
// TODO: add mc,redis... if you use
return nil
}
func getConf(appName string) *liverpc.ClientConfig {
c := conf.Conf.LiveRpc
if c != nil {
return c[appName]
}
return nil
}

View File

@ -0,0 +1,146 @@
package dao
import (
"context"
"time"
"go-common/library/ecode"
"fmt"
daoAnchorV0 "go-common/app/service/live/dao-anchor/api/grpc/v0"
"go-common/app/service/live/dao-anchor/api/grpc/v1"
"go-common/library/log"
)
//LIVE_OPEN 开播
const LIVE_OPEN = 1
//LIVE_CLOSE 关播
const LIVE_CLOSE = 0
//LIVE_ROUND 轮播
const LIVE_ROUND = 2
//PAGE_SIZE 分页数据量
const PAGE_SIZE = 100
//RETRY_TIME 接口充实次数
const RETRY_TIME = 3
//GetAllLiveRoom 获取在播列表
func (d *Dao) GetAllLiveRoom(c context.Context, fields []string) (resp map[int64]*v1.RoomData, err error) {
page := 0
resp = map[int64]*v1.RoomData{}
retry := 1
for true {
reply, err := d.daoAnchorApi.RoomOnlineList(c, &v1.RoomOnlineListReq{Fields: fields, Page: int64(page), PageSize: PAGE_SIZE})
if err != nil {
if retry >= RETRY_TIME {
break
}
retry++
time.Sleep(time.Second * 3)
log.Errorw(c, "log", fmt.Sprintf("getAllLiveRoom_RoomOnlineList_error:page=%d;err=%v", page, err))
continue
}
if len(reply.RoomDataList) <= 0 {
break
}
page = page + 1
roomDataList := reply.RoomDataList
for roomId, info := range roomDataList {
v := info
resp[roomId] = v
}
time.Sleep(time.Millisecond)
}
return
}
//GetAllLiveRoomIds 获取在播列表
func (d *Dao) GetAllLiveRoomIds(c context.Context) (resp []int64, err error) {
page := 0
reply, err := d.daoAnchorApi.RoomOnlineListByArea(c, &v1.RoomOnlineListByAreaReq{})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("GetAllLiveRoomIds_RoomOnlineList_error:page=%d;err=%v", page, err))
return
}
if len(reply.RoomIds) <= 0 {
return
}
resp = reply.RoomIds
return
}
//GetInfosByRoomIds 获取主播房间信息
func (d *Dao) GetInfosByRoomIds(c context.Context, roomIds []int64, fields []string) (resp map[int64]*v1.RoomData, err error) {
if roomIds == nil {
err = ecode.InvalidParam
log.Errorw(c, "log", fmt.Sprintf("getInfosByRoomIds_params_error:%v", roomIds))
return
}
reply, err := d.daoAnchorApi.FetchRoomByIDs(c, &v1.RoomByIDsReq{RoomIds: roomIds, Fields: fields})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("getInfosByRoomIds_FetchRoomByIDs_error:reply=%v;err=%v", reply, err))
return
}
if reply == nil {
err = ecode.CallDaoAnchorError
log.Errorw(c, "log", "getInfosByRoomIds_FetchRoomByIDs_error")
return
}
resp = reply.RoomDataSet
return
}
//UpdateRoomEx ...
func (d *Dao) UpdateRoomEx(c context.Context, roomId int64, fields []string, keyFrame string) (resp int64, err error) {
if roomId < 0 {
err = ecode.InvalidParam
log.Errorw(c, "log", fmt.Sprintf("updateRoom_params_error:%v", roomId))
return
}
reply, err := d.daoAnchorApi.RoomExtendUpdate(c, &v1.RoomExtendUpdateReq{Fields: fields, RoomId: roomId, Keyframe: keyFrame})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("updateRoom_RoomUpdate_error:reply=%v;err=%v", reply, err))
return
}
resp = reply.AffectedRows
return
}
func (d *Dao) CreateCacheList(c context.Context, roomIds []int64, content string) (err error) {
if len(roomIds) <= 0 || content == "" {
log.Errorw(c, "log", fmt.Sprintf("CreateCacheList_params_error:room_id=%v;content=%s", roomIds, content))
return
}
reply, err := d.daoAnchorApiV0.CreateLiveCacheList(c, &daoAnchorV0.CreateLiveCacheListReq{RoomIds: roomIds, Content: content})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("CreateCacheList_error:reply=%v;err=%v", reply, err))
return
}
log.Info("CreateCacheList_info:roomIds=%v;content=%s;reply=%v", roomIds, content, reply)
return
}
func (d *Dao) GetContentMap(c context.Context) (resp map[string]int64, err error) {
reply, err := d.daoAnchorApiV0.GetContentMap(c, &daoAnchorV0.GetContentMapReq{})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("GetContentMap_error:reply=%v;err=%v", reply, err))
return
}
resp = reply.List
return
}
func (d *Dao) CreateDBData(c context.Context, roomIds []int64, content string) (err error) {
if len(roomIds) <= 0 || content == "" {
log.Errorw(c, "log", fmt.Sprintf("CreateCacheList_params_error:room_id=%v;content=%s", roomIds, content))
return
}
reply, err := d.daoAnchorApiV0.CreateDBData(c, &daoAnchorV0.CreateDBDataReq{RoomIds: roomIds, Content: content})
if err != nil {
log.Errorw(c, "log", fmt.Sprintf("CreateCacheList_error:reply=%v;err=%v", reply, err))
return
}
return
}

View File

@ -0,0 +1,26 @@
package dao
import (
"context"
"time"
"go-common/app/service/video/stream-mng/api/v1"
"go-common/library/log"
)
//视频云接口调用
//GetPicsByRoomId 根据房间id获取当前关键帧
func (d *Dao) GetPicsByRoomId(c context.Context, roomId int64, startTime time.Time, endTime time.Time) (resp []string, err error) {
reply, err := d.VideoApi.GetSingleScreeShot(c, &v1.GetSingleScreeShotReq{RoomId: roomId, StartTime: startTime.Format("2006-01-02 15:04:05"), EndTime: endTime.Format("2006-01-02 15:04:05")})
if err != nil {
log.Error("getPicsByRoomId_GetSingleScreeShot_error:reply:%v;err=%v", reply, err)
return
}
if reply == nil {
log.Error("getPicsByRoomId_GetSingleScreeShot_error")
return
}
resp = reply.List
return
}