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,50 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["archive2_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive1.go",
"archive2.go",
"archive3.go",
],
importpath = "go-common/app/service/main/archive/api/gorpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
"//library/net/rpc: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,25 @@
package gorpc
import (
"go-common/library/net/rpc"
)
const (
_appid = "archive.service"
)
var (
_noArg = &struct{}{}
)
// Service2 is archive rpc client.
type Service2 struct {
client *rpc.Client2
}
// New2 new a archive rpc client.
func New2(c *rpc.ClientConfig) (s *Service2) {
s = &Service2{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}

View File

@@ -0,0 +1,96 @@
package gorpc
import (
"context"
"go-common/app/service/main/archive/api"
model "go-common/app/service/main/archive/model/archive"
)
const (
_types2 = "RPC.Types2"
_videoshot2 = "RPC.Videoshot2"
_upCount2 = "RPC.UpCount2"
_upsPassed2 = "RPC.UpsPassed2"
_upVideo2 = "RPC.UpVideo2"
_delVideo2 = "RPC.DelVideo2"
_description2 = "RPC.Description2"
_ranksTopCount2 = "RPC.RanksTopCount2"
_arcCache2 = "RPC.ArcCache2"
_arcFieldCache2 = "RPC.ArcFieldCache2"
_setStat2 = "RPC.SetStat2"
_setStatCache2 = "RPC.SetStatCache2"
)
// Types2 get all archive types
func (s *Service2) Types2(c context.Context) (res map[int16]*model.ArcType, err error) {
err = s.client.Call(c, _types2, _noArg, &res)
return
}
// Videoshot2 get videoshot.
func (s *Service2) Videoshot2(c context.Context, arg *model.ArgCid2) (res *model.Videoshot, err error) {
res = new(model.Videoshot)
err = s.client.Call(c, _videoshot2, arg, res)
return
}
// UpCount2 up count2
func (s *Service2) UpCount2(c context.Context, arg *model.ArgUpCount2) (count int, err error) {
err = s.client.Call(c, _upCount2, arg, &count)
return
}
// UpsPassed2 get UpsPassed aid and ptime
func (s *Service2) UpsPassed2(c context.Context, arg *model.ArgUpsArcs2) (res map[int64][]*model.AidPubTime, err error) {
err = s.client.Call(c, _upsPassed2, arg, &res)
return
}
// UpVideo2 update video cache by aid & cid
func (s *Service2) UpVideo2(c context.Context, arg *model.ArgVideo2) (err error) {
err = s.client.Call(c, _upVideo2, arg, _noArg)
return
}
// DelVideo2 delete video cache by aid & cid
func (s *Service2) DelVideo2(c context.Context, arg *model.ArgVideo2) (err error) {
err = s.client.Call(c, _delVideo2, arg, _noArg)
return
}
// Description2 add share.
func (s *Service2) Description2(c context.Context, arg *model.ArgAid) (des string, err error) {
err = s.client.Call(c, _description2, arg, &des)
return
}
// RanksTopCount2 get top region count.
func (s *Service2) RanksTopCount2(c context.Context, arg *model.ArgRankTopsCount2) (res map[int16]int, err error) {
err = s.client.Call(c, _ranksTopCount2, arg, &res)
return
}
// ArcCache2 add/update archive cache
func (s *Service2) ArcCache2(c context.Context, arg *model.ArgCache2) (err error) {
err = s.client.Call(c, _arcCache2, arg, _noArg)
return
}
// ArcFieldCache2 update archive field cache
func (s *Service2) ArcFieldCache2(c context.Context, arg *model.ArgFieldCache2) (err error) {
err = s.client.Call(c, _arcFieldCache2, arg, _noArg)
return
}
// SetStat2 set all stat info.
func (s *Service2) SetStat2(c context.Context, arg *api.Stat) (err error) {
err = s.client.Call(c, _setStat2, arg, _noArg)
return
}
// SetStatCache2 up stat.
func (s *Service2) SetStatCache2(c context.Context, arg *model.ArgStat2) (err error) {
err = s.client.Call(c, _setStatCache2, arg, _noArg)
return
}

View File

@@ -0,0 +1,252 @@
package gorpc
import (
"context"
"fmt"
"testing"
"time"
"go-common/app/service/main/archive/api"
"go-common/app/service/main/archive/model/archive"
)
func TestDynamic(t *testing.T) {
s := New2(nil)
time.Sleep(5 * time.Second)
testArchivesWithPlayer(t, s)
testMaxAID(t, s)
testVideo3(t, s)
testUpsArcs3(t, s)
testUpArcs3(t, s)
testRecommend3(t, s)
testArchive3(t, s)
testArchives3(t, s)
testAidPTime(t, s)
testTypes2(t, s)
testVideoshot2(t, s)
testUpCount2(t, s)
testView3(t, s)
testViews3(t, s)
testClick3(t, s)
testRankArcs3(t, s)
testRanksArcs3(t, s)
testRankTopArcs3(t, s)
testRankAllArcs3(t, s)
testPage3(t, s)
testRanksTopCount2(t, s)
testStat3(t, s)
testStats3(t, s)
testArcCache2(t, s)
testArcFieldCache2(t, s)
testSetStat2(t, s)
testUpVideo2(t, s)
testDelVideo2(t, s)
testDescription2(t, s)
}
func testViews3(t *testing.T, s *Service2) {
var vs, err = s.Views3(context.TODO(), &archive.ArgAids2{Aids: []int64{10097450, 10097454}})
if err != nil {
t.Log(err)
return
}
for _, v := range vs {
t.Log(v.Archive3)
}
}
func testClick3(t *testing.T, s *Service2) {
t.Log(s.Click3(context.TODO(), &archive.ArgAid2{Aid: 10097454}))
}
func testRankArcs3(t *testing.T, s *Service2) {
t.Log(s.RankArcs3(context.TODO(), &archive.ArgRank2{Rid: 20, Type: 0, Ps: 20, Pn: 1}))
}
func testRanksArcs3(t *testing.T, s *Service2) {
t.Log(s.RanksArcs3(context.TODO(), &archive.ArgRanks2{Rids: []int16{20, 24}, Type: 0, Ps: 20, Pn: 1}))
}
func testRankTopArcs3(t *testing.T, s *Service2) {
t.Log(s.RankTopArcs3(context.TODO(), &archive.ArgRankTop2{ReID: 1, Pn: 1, Ps: 10}))
}
func testRankAllArcs3(t *testing.T, s *Service2) {
am, err := s.RankAllArcs3(context.TODO(), &archive.ArgRankAll2{Pn: 1, Ps: 40})
if err != nil {
t.Log(err)
return
}
t.Logf("allRankTop(%d)", am.Count)
for _, arc := range am.Archives {
t.Logf("archive(%+v)", arc)
}
}
func testAidPTime(t *testing.T, s *Service2) {
res, err := s.UpsPassed2(context.TODO(), &archive.ArgUpsArcs2{Mids: []int64{15555180, 27515256}})
fmt.Println(len(res))
if err != nil {
t.Logf("s.UpsPassed2 error(%v)", err)
return
}
for mid, v := range res {
t.Logf("mid:%d", mid)
for _, aidAndPtime := range v {
t.Logf("mid:%d, aid:%d, ptime:%d, copyright:%d", mid, aidAndPtime.Aid, aidAndPtime.PubDate, aidAndPtime.Copyright)
}
}
}
func testArchivesWithPlayer(t *testing.T, s *Service2) {
arg := &archive.ArgPlayer{Aids: []int64{10097272, 1}, Qn: 16, Platform: "html5", RealIP: "222.73.196.18"}
res, err := s.ArchivesWithPlayer(context.TODO(), arg)
if err != nil {
t.Logf("s.ArchivesWithPlayer(%+v) error(%v)", arg, err)
return
}
for k, v := range res {
t.Logf("aid:%d, arc:%+v, player:%+v", k, v, v.PlayerInfo)
}
}
func testVideo3(t *testing.T, s *Service2) {
t.Log(s.Video3(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testRecommend3(t *testing.T, s *Service2) {
for i := 0; i < 50; i++ {
time.Sleep(100 * time.Millisecond)
res, err := s.Recommend3(context.TODO(), &archive.ArgAid2{Aid: 4052562})
if err != nil {
t.Logf("s.Recommend3 error(%v)", err)
continue
}
t.Log(res)
}
}
func testArchive3(t *testing.T, s *Service2) {
res, err := s.Archive3(context.TODO(), &archive.ArgAid2{Aid: 5463609})
if err != nil {
t.Logf("s.Archive3 error(%v)", err)
return
}
t.Log(res)
}
func testArchives3(t *testing.T, s *Service2) {
res, err := s.Archives3(context.TODO(), &archive.ArgAids2{Aids: []int64{5463609, 5463608, 10097657}})
if err != nil {
t.Logf("s.Archives3 error(%v)", err)
return
}
for _, a := range res {
t.Log(a)
}
}
func testMaxAID(t *testing.T, s *Service2) {
res, err := s.MaxAID(context.TODO())
if err != nil {
t.Error(err)
return
}
t.Logf("maxAID is %d", res)
}
func testTypes2(t *testing.T, s *Service2) {
res, err := s.Types2(context.TODO())
if err != nil {
t.Error(err)
return
}
for _, tp := range res {
t.Log(tp)
}
}
func testVideoshot2(t *testing.T, s *Service2) {
res, err := s.Videoshot2(context.TODO(), &archive.ArgCid2{Cid: 10108203})
t.Log(res, err)
}
func testUpArcs3(t *testing.T, s *Service2) {
res, err := s.UpArcs3(context.TODO(), &archive.ArgUpArcs2{Mid: 27515615, Pn: 1, Ps: 20})
if err != nil {
t.Error(err)
return
}
for _, a := range res {
t.Log(a)
}
}
func testUpCount2(t *testing.T, s *Service2) {
count, err := s.UpCount2(context.TODO(), &archive.ArgUpCount2{Mid: 27515615})
if err != nil {
t.Error(err)
return
}
t.Log(count)
}
func testUpsArcs3(t *testing.T, s *Service2) {
res, err := s.UpsArcs3(context.TODO(), &archive.ArgUpsArcs2{Mids: []int64{27515615, 1684013}})
if err != nil {
t.Error(err)
return
}
t.Log(res)
}
func testView3(t *testing.T, s *Service2) {
t.Log(s.View3(context.TODO(), &archive.ArgAid2{Aid: 10098067}))
}
func testPage3(t *testing.T, s *Service2) {
t.Log(s.Page3(context.TODO(), &archive.ArgAid2{Aid: 10097454}))
}
func testRanksTopCount2(t *testing.T, s *Service2) {
t.Log(s.RanksTopCount2(context.TODO(), &archive.ArgRankTopsCount2{ReIDs: []int16{1, 2}}))
}
func testStat3(t *testing.T, s *Service2) {
res, err := s.Stat3(context.TODO(), &archive.ArgAid2{Aid: 10989901})
if err != nil {
t.Errorf("testStats3 error(%v)", err)
return
}
t.Log(res, 1)
}
func testStats3(t *testing.T, s *Service2) {
res, err := s.Stats3(context.TODO(), &archive.ArgAids2{Aids: []int64{10989901, 10097453}})
if err != nil {
t.Logf("testStats3 error(%v)", err)
return
}
for aid, r := range res {
t.Logf("%d:%+v\n", aid, r)
}
}
func testArcCache2(t *testing.T, s *Service2) {
t.Log(s.ArcCache2(context.TODO(), &archive.ArgCache2{Aid: 10097454, Tp: archive.CacheUpdate}))
}
func testArcFieldCache2(t *testing.T, s *Service2) {
t.Log(s.ArcFieldCache2(context.TODO(), &archive.ArgFieldCache2{Aid: 10097454, TypeID: 20, OldTypeID: 10}))
}
func testSetStat2(t *testing.T, s *Service2) {
t.Log(s.SetStat2(context.TODO(), &api.Stat{Aid: 10097454, View: 0, Danmaku: 0, Reply: 10, Fav: 10, Coin: 10, Share: 10, HisRank: 10, NowRank: 10}))
}
func testUpVideo2(t *testing.T, s *Service2) {
t.Log(s.UpVideo2(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testDelVideo2(t *testing.T, s *Service2) {
t.Log(s.DelVideo2(context.TODO(), &archive.ArgVideo2{Aid: 10097760, Cid: 10107336}))
}
func testDescription2(t *testing.T, s *Service2) {
t.Log(s.Description2(context.TODO(), &archive.ArgAid{Aid: 10097454}))
}

View File

@@ -0,0 +1,141 @@
package gorpc
import (
"context"
"go-common/app/service/main/archive/api"
model "go-common/app/service/main/archive/model/archive"
)
const (
_archive3 = "RPC.Archive3"
_archives3 = "RPC.Archives3"
_view3 = "RPC.View3"
_views3 = "RPC.Views3"
_stat3 = "RPC.Stat3"
_stats3 = "RPC.Stats3"
_click3 = "RPC.Click3"
_upArcs3 = "RPC.UpArcs3"
_upsArcs3 = "RPC.UpsArcs3"
_page3 = "RPC.Page3"
_recommend3 = "RPC.Recommend3"
_rankArcs3 = "RPC.RankArcs3"
_ranksArcs3 = "RPC.RanksArcs3"
_rankTopArcs3 = "RPC.RankTopArcs3"
_rankAllArcs3 = "RPC.RankAllArcs3"
_video3 = "RPC.Video3"
_archivesWithPlayer = "RPC.ArchivesWithPlayer"
_maxAid = "RPC.MaxAID"
)
// MaxAID get max aid
func (s *Service2) MaxAID(c context.Context) (id int64, err error) {
err = s.client.Call(c, _maxAid, _noArg, &id)
return
}
// Archive3 Get receive aid, then init archive info.
func (s *Service2) Archive3(c context.Context, arg *model.ArgAid2) (res *api.Arc, err error) {
res = new(api.Arc)
err = s.client.Call(c, _archive3, arg, res)
return
}
// Archives3 receive aids, then init archives info.
func (s *Service2) Archives3(c context.Context, arg *model.ArgAids2) (res map[int64]*api.Arc, err error) {
err = s.client.Call(c, _archives3, arg, &res)
return
}
// View3 get archive info and view pages.
func (s *Service2) View3(c context.Context, arg *model.ArgAid2) (res *model.View3, err error) {
res = new(model.View3)
err = s.client.Call(c, _view3, arg, res)
return
}
// Views3 get archives info and view pages.
func (s *Service2) Views3(c context.Context, arg *model.ArgAids2) (res map[int64]*model.View3, err error) {
err = s.client.Call(c, _views3, arg, &res)
return
}
// Stat3 get archive stat
func (s *Service2) Stat3(c context.Context, arg *model.ArgAid2) (res *api.Stat, err error) {
err = s.client.Call(c, _stat3, arg, &res)
return
}
// ArchivesWithPlayer archives witch player
func (s *Service2) ArchivesWithPlayer(c context.Context, arg *model.ArgPlayer) (res map[int64]*model.ArchiveWithPlayer, err error) {
err = s.client.Call(c, _archivesWithPlayer, arg, &res)
return
}
// Stats3 get archive stat
func (s *Service2) Stats3(c context.Context, arg *model.ArgAids2) (res map[int64]*api.Stat, err error) {
err = s.client.Call(c, _stats3, arg, &res)
return
}
// Click3 get archive click
func (s *Service2) Click3(c context.Context, arg *model.ArgAid2) (res *api.Click, err error) {
err = s.client.Call(c, _click3, arg, &res)
return
}
// UpsArcs3 get archives of upper.
func (s *Service2) UpsArcs3(c context.Context, arg *model.ArgUpsArcs2) (res map[int64][]*api.Arc, err error) {
err = s.client.Call(c, _upsArcs3, arg, &res)
return
}
// UpArcs3 get archives of upper.
func (s *Service2) UpArcs3(c context.Context, arg *model.ArgUpArcs2) (res []*api.Arc, err error) {
err = s.client.Call(c, _upArcs3, arg, &res)
return
}
// Page3 get videos by aid
func (s *Service2) Page3(c context.Context, arg *model.ArgAid2) (res []*api.Page, err error) {
err = s.client.Call(c, _page3, arg, &res)
return
}
// Recommend3 from archive_recommend by aid
func (s *Service2) Recommend3(c context.Context, arg *model.ArgAid2) (res []*api.Arc, err error) {
err = s.client.Call(c, _recommend3, arg, &res)
return
}
// RankArcs3 get rank archives by type.
func (s *Service2) RankArcs3(c context.Context, arg *model.ArgRank2) (res *model.RankArchives3, err error) {
res = new(model.RankArchives3)
err = s.client.Call(c, _rankArcs3, arg, res)
return
}
// RanksArcs3 get rank archives by types.
func (s *Service2) RanksArcs3(c context.Context, arg *model.ArgRanks2) (res map[int16]*model.RankArchives3, err error) {
err = s.client.Call(c, _ranksArcs3, arg, &res)
return
}
// RankTopArcs3 get top region archives by reid
func (s *Service2) RankTopArcs3(c context.Context, arg *model.ArgRankTop2) (res []*api.Arc, err error) {
err = s.client.Call(c, _rankTopArcs3, arg, &res)
return
}
// RankAllArcs3 get left 7 days all archives
func (s *Service2) RankAllArcs3(c context.Context, arg *model.ArgRankAll2) (res *model.RankArchives3, err error) {
err = s.client.Call(c, _rankAllArcs3, arg, &res)
return
}
// Video3 get video by aid & cid.
func (s *Service2) Video3(c context.Context, arg *model.ArgVideo2) (res *api.Page, err error) {
res = new(api.Page)
err = s.client.Call(c, _video3, arg, res)
return
}