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,63 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"banner.go",
"room.go",
"splash.go",
"topic.go",
],
importpath = "go-common/app/interface/live/app-blink/service/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-blink/api/http/v1:go_default_library",
"//app/interface/live/app-blink/conf:go_default_library",
"//app/interface/live/app-blink/dao:go_default_library",
"//app/service/live/resource/api/grpc/v1:go_default_library",
"//library/ecode:go_default_library",
"//library/net/metadata:go_default_library",
"//library/sync/errgroup: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"],
)
go_test(
name = "go_default_test",
srcs = [
"banner_test.go",
"room_test.go",
"splash_test.go",
"topic_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/live/app-blink/api/http/v1:go_default_library",
"//app/interface/live/app-blink/conf:go_default_library",
"//app/service/live/resource/api/grpc/v1:go_default_library",
"//library/net/metadata:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,39 @@
package v1
import (
"context"
"go-common/app/interface/live/app-blink/conf"
rspb "go-common/app/service/live/resource/api/grpc/v1"
)
// BannerService struct
type BannerService struct {
conf *conf.Config
// optionally add other properties here, such as dao
// dao *dao.Dao
rsCli *rspb.Client
}
//NewBannerService init
func NewBannerService(c *conf.Config) (s *BannerService) {
s = &BannerService{
conf: c,
}
var svc *rspb.Client
var err error
if svc, err = rspb.NewClient(s.conf.ResourceClient); err != nil {
panic(err)
}
s.rsCli = svc
return s
}
// GetBlinkBanner implementation
// 获取banner配置
// `dynamic:"true"`
func (s *BannerService) GetBlinkBanner(ctx context.Context, req *rspb.GetInfoReq) (resp *rspb.GetInfoResp, err error) {
resp, err = s.rsCli.GetBlinkBanner(ctx, req)
return
}

View File

@@ -0,0 +1,36 @@
package v1
import (
"context"
"flag"
"fmt"
"testing"
"go-common/app/interface/live/app-blink/conf"
rspb "go-common/app/service/live/resource/api/grpc/v1"
. "github.com/smartystreets/goconvey/convey"
)
var s *BannerService
func init() {
flag.Set("conf", "../../cmd/test.toml")
if err := conf.Init(); err != nil {
panic(err)
}
s = NewBannerService(conf.Conf)
}
// DEPLOY_ENV=uat go test -run TestBannerService_GetBlinkBanner
func TestBannerService_GetBlinkBanner(t *testing.T) {
Convey("TestGetBlinkBanner", t, func() {
res, err := s.GetBlinkBanner(context.TODO(), &rspb.GetInfoReq{
Platform: "android",
Build: 53100,
})
fmt.Println(res, err)
t.Logf("%v,%s", res, err)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,162 @@
package v1
import (
"context"
v1pb "go-common/app/interface/live/app-blink/api/http/v1"
"go-common/app/interface/live/app-blink/conf"
"go-common/app/interface/live/app-blink/dao"
"go-common/library/ecode"
"go-common/library/net/metadata"
"go-common/library/sync/errgroup"
)
// RoomService struct
type RoomService struct {
conf *conf.Config
// optionally add other properties here, such as dao
dao *dao.Dao
}
//NewRoomService init
func NewRoomService(c *conf.Config) (s *RoomService) {
s = &RoomService{
conf: c,
dao: dao.New(c),
}
return s
}
// GetInfo implementation
// 获取房间基本信息
// `method:"GET" midware:"auth"`
func (s *RoomService) GetInfo(ctx context.Context, req *v1pb.GetRoomInfoReq) (resp *v1pb.GetRoomInfoResp, err error) {
uid, ok := metadata.Value(ctx, metadata.Mid).(int64)
if uid <= 0 || !ok {
err = ecode.UidError
return
}
uidArr := make([]int64, 0)
uidArr = append(uidArr, uid)
resp = &v1pb.GetRoomInfoResp{}
resp.Uid = uid
resp.FullText = "V等级5级或UP等级10级才能开通粉丝勋章哦~加油!"
resp.OpenMedalLevel = dao.OpenFansMealLevel
resp.MaxLevel = 40
eg := errgroup.Group{}
eg.Go(func() (err error) {
room, err := s.dao.GetRoomInfosByUids(ctx, uidArr)
if err != nil {
err = ecode.CallRoomError
return
}
roomInfo := room[uid]
if roomInfo == nil {
return
}
LockStatus := 0
//if roomInfo.LockTill >= dao.PERMANENT_LOCK_TIME {
// LockStatus = 1
//}
resp.RoomId = roomInfo.RoomId
resp.Title = roomInfo.Title
resp.LiveStatus = roomInfo.LiveStatus
resp.AreaV2Id = roomInfo.AreaV2Id
resp.AreaV2Name = roomInfo.AreaV2Name
resp.LockTime = roomInfo.LockTill
resp.LockStatus = int64(LockStatus)
resp.ParentId = roomInfo.AreaV2ParentId
resp.ParentName = roomInfo.AreaV2ParentName
return
})
eg.Go(func() (err error) {
user, err := s.dao.GetUserInfo(ctx, uidArr)
if err != nil {
err = ecode.CallUserError
return
}
if user == nil {
err = ecode.UserNotFound
return
}
userInfo, ok := user[uid]
if !ok {
err = ecode.UserNotFound
return
}
resp.Face = userInfo.GetInfo().GetFace()
resp.Uname = userInfo.GetInfo().GetUname()
if userInfo.Exp != nil {
resp.MasterScore = userInfo.Exp.Rcost / 100
if userInfo.Exp.MasterLevel != nil {
masterLevel := userInfo.Exp.MasterLevel.Level
masterNextLevel := masterLevel + 1
if masterNextLevel > 40 {
masterNextLevel = 40
}
resp.MasterLevel = masterLevel
resp.MasterLevelColor = userInfo.Exp.MasterLevel.Color
resp.MasterNextLevel = masterNextLevel
if len(userInfo.Exp.MasterLevel.Next) >= 2 {
resp.MasterNextLevelScore = userInfo.Exp.MasterLevel.Next[1]
}
}
}
return
})
eg.Go(func() (err error) {
relation, err := s.dao.GetUserFc(ctx, uid)
if err != nil {
err = ecode.CallRelationError
return
}
resp.FcNum = relation.Fc
return
})
eg.Go(func() (err error) {
fansMedal, err := s.dao.GetFansMedalInfo(ctx, uid)
if err != nil {
err = ecode.CallFansMedalError
return
}
if fansMedal == nil {
return
}
resp.IsMedal = fansMedal.MasterStatus
resp.MedalName = fansMedal.MedalName
resp.MedalRenameStatus = fansMedal.RenameStatus
resp.MedalStatus = fansMedal.Status
return
})
eg.Go(func() (err error) {
identifyStatus, err := s.dao.GetIdentityStatus(ctx, uid)
if err != nil {
err = ecode.CallMainMemberError
return
}
resp.IdentifyStatus = int64(identifyStatus)
return
})
err = eg.Wait()
return
}
// Create implementation
// 创建房间
// `method:"POST" midware:"auth"`
func (s *RoomService) Create(ctx context.Context, req *v1pb.CreateReq) (resp *v1pb.CreateResp, err error) {
uid, ok := metadata.Value(ctx, metadata.Mid).(int64)
if uid <= 0 || !ok {
err = ecode.UidError
return
}
resp = &v1pb.CreateResp{}
room, err := s.dao.CreateRoom(ctx, uid)
if err != nil {
err = ecode.CallRoomError
return
}
resp.RoomId = room.Roomid
return
}

View File

@@ -0,0 +1,55 @@
package v1
import (
"context"
"flag"
"fmt"
"testing"
"go-common/app/interface/live/app-blink/api/http/v1"
"go-common/library/net/metadata"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/interface/live/app-blink/conf"
)
var room *RoomService
func init() {
flag.Set("conf", "../../cmd/test.toml")
if err := conf.Init(); err != nil {
panic(err)
}
room = NewRoomService(conf.Conf)
}
// group=qa01 DEPLOY_ENV=uat go test -run TestGetRoomInfo
func TestGetRoomInfo(t *testing.T) {
Convey("TestNewRoomService", t, func() {
ctx := metadata.NewContext(context.TODO(), metadata.MD{
metadata.Mid: int64(16299525),
})
res, err := room.GetInfo(ctx, &v1.GetRoomInfoReq{
Platform: "ios",
})
fmt.Println(1111, res, err, 22222)
t.Logf("%v,%s", res, err)
So(err, ShouldBeNil)
})
}
func TestCreate(t *testing.T) {
Convey("TestNewRoomService", t, func() {
ctx := metadata.NewContext(context.TODO(), metadata.MD{
metadata.Mid: int64(16299525),
})
res, err := room.Create(ctx, &v1.CreateReq{
Platform: "ios",
})
fmt.Println(1111, res, err, 22222)
t.Logf("%v,%s", res, err)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,39 @@
package v1
import (
"context"
"go-common/app/interface/live/app-blink/conf"
rspb "go-common/app/service/live/resource/api/grpc/v1"
)
// SplashService struct
type SplashService struct {
conf *conf.Config
// optionally add other properties here, such as dao
// dao *dao.Dao
rsCli *rspb.Client
}
//NewSplashService init
func NewSplashService(c *conf.Config) (s *SplashService) {
s = &SplashService{
conf: c,
}
var svc *rspb.Client
var err error
if svc, err = rspb.NewClient(s.conf.ResourceClient); err != nil {
panic(err)
}
s.rsCli = svc
return s
}
// GetInfo implementation
// 获取有效闪屏配置
// `dynamic:"true"`
func (s *SplashService) GetInfo(ctx context.Context, req *rspb.GetInfoReq) (resp *rspb.GetInfoResp, err error) {
resp, err = s.rsCli.GetInfo(ctx, req)
return
}

View File

@@ -0,0 +1,36 @@
package v1
import (
"context"
"flag"
"fmt"
"testing"
"go-common/app/interface/live/app-blink/conf"
rspb "go-common/app/service/live/resource/api/grpc/v1"
. "github.com/smartystreets/goconvey/convey"
)
var sp *SplashService
func init() {
flag.Set("conf", "../../cmd/test.toml")
if err := conf.Init(); err != nil {
panic(err)
}
sp = NewSplashService(conf.Conf)
}
// DEPLOY_ENV=uat go test -run TestNewSplashService
func TestNewSplashService(t *testing.T) {
Convey("TestNewSplashService", t, func() {
res, err := sp.GetInfo(context.TODO(), &rspb.GetInfoReq{
Platform: "android",
Build: 53100,
})
fmt.Println(res, err)
t.Logf("%v,%s", res, err)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,59 @@
package v1
import (
"context"
v1pb "go-common/app/interface/live/app-blink/api/http/v1"
"go-common/app/interface/live/app-blink/conf"
"go-common/app/interface/live/app-blink/dao"
"go-common/library/ecode"
)
// TopicService struct
type TopicService struct {
conf *conf.Config
// optionally add other properties here, such as dao
dao *dao.Dao
}
//NewTopicService init
func NewTopicService(c *conf.Config) (s *TopicService) {
s = &TopicService{
conf: c,
dao: dao.New(c),
}
return s
}
// GetTopicList implementation
// 获取话题列表
// `method:"GET" midware:"auth"`
func (s *TopicService) GetTopicList(ctx context.Context, req *v1pb.GetTopicListReq) (resp *v1pb.GetTopicListResp, err error) {
reply, err := s.dao.GetTopicList(ctx)
if err != nil {
err = ecode.CallResourceError
return
}
resp = &v1pb.GetTopicListResp{}
resp.TopicList = reply
return
}
// CheckTopic implementation
// 检验话题是否有效
// `method:"GET" midware:"auth"`
func (s *TopicService) CheckTopic(ctx context.Context, req *v1pb.CheckTopicReq) (resp *v1pb.CheckTopicResp, err error) {
msg := req.Topic
area := "live_biaoti"
reply, err := s.dao.CheckMsgIsLegal(ctx, msg, area, 0)
if err != nil {
err = ecode.Error(ecode.CallMainFilterError, "出错啦,再试试吧")
return
}
resp = &v1pb.CheckTopicResp{}
if reply {
err = ecode.Error(ecode.FILTERNOTPASS, "当前输入的话题里面包含敏感内容~请修改~")
return
}
return
}

View File

@@ -0,0 +1,55 @@
package v1
import (
"context"
"flag"
"fmt"
"testing"
"go-common/app/interface/live/app-blink/api/http/v1"
"go-common/library/net/metadata"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/interface/live/app-blink/conf"
)
var topic *TopicService
func init() {
flag.Set("conf", "../../cmd/test.toml")
if err := conf.Init(); err != nil {
panic(err)
}
topic = NewTopicService(conf.Conf)
}
// group=qa01 DEPLOY_ENV=uat go test -run TestGetTopicList
func TestGetTopicList(t *testing.T) {
Convey("TestGetTopicList", t, func() {
ctx := metadata.NewContext(context.TODO(), metadata.MD{
metadata.Mid: int64(16299525),
})
res, err := topic.GetTopicList(ctx, &v1.GetTopicListReq{
Platform: "ios",
})
fmt.Println(1111, res, err, 22222)
t.Logf("%v,%s", res, err)
So(err, ShouldBeNil)
})
}
func TestCheckTopic(t *testing.T) {
Convey("TestCheckTopic", t, func() {
ctx := metadata.NewContext(context.TODO(), metadata.MD{
metadata.Mid: int64(16299525),
})
res, err := topic.CheckTopic(ctx, &v1.CheckTopicReq{
Platform: "ios",
Topic: "我是习",
})
fmt.Println(1111, res, err, 22222)
t.Logf("%v,%s", res, err)
})
}