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,53 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"grpc.go",
],
importpath = "go-common/app/admin/main/feed/dao/pgc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/service/openplatform/pgc-season/api/grpc/episode/v1:go_default_library",
"//app/service/openplatform/pgc-season/api/grpc/season/v1:go_default_library",
"//library/log: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 = [
"dao_test.go",
"grpc_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,34 @@
package pgc
import (
"go-common/app/admin/main/feed/conf"
epgrpc "go-common/app/service/openplatform/pgc-season/api/grpc/episode/v1"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"go-common/library/log"
)
// Dao is show dao.
type Dao struct {
// grpc
rpcClient seasongrpc.SeasonClient
epClient epgrpc.EpisodeClient
}
// New new a bangumi dao.
func New(c *conf.Config) (*Dao, error) {
var ep epgrpc.EpisodeClient
rpcClient, err := seasongrpc.NewClient(nil)
if err != nil {
log.Error("seasongrpc NewClientt error(%v)", err)
return nil, err
}
if ep, err = epgrpc.NewClient(nil); err != nil {
log.Error("eprpc NewClientt error(%v)", err)
return nil, err
}
d := &Dao{
rpcClient: rpcClient,
epClient: ep,
}
return d, nil
}

View File

@@ -0,0 +1,34 @@
package pgc
import (
"flag"
"os"
"testing"
"go-common/app/admin/main/feed/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app", "feed-admin")
flag.Set("app_id", "main.web-svr.feed-admin")
flag.Set("conf_token", "e0d2b216a460c8f8492473a2e3cdd218")
flag.Set("tree_id", "45266")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d, _ = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,38 @@
package pgc
import (
"context"
epgrpc "go-common/app/service/openplatform/pgc-season/api/grpc/episode/v1"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"go-common/library/log"
)
//CardsInfoReply pgc grpc
func (d *Dao) CardsInfoReply(c context.Context, seasonIds []int32) (res map[int32]*seasongrpc.CardInfoProto, err error) {
arg := &seasongrpc.SeasonInfoReq{
SeasonIds: seasonIds,
}
info, err := d.rpcClient.Cards(c, arg)
if err != nil {
log.Error("d.rpcClient.Cards error(%v)", err)
return nil, err
}
res = info.Cards
return
}
//CardsEpInfoReply get pgc ep cards values by epid
func (d *Dao) CardsEpInfoReply(c context.Context, epIds []int32) (res map[int32]*epgrpc.EpisodeCardsProto, err error) {
var epInfo *epgrpc.EpisodeCardsReply
arg := &epgrpc.EpReq{
Epids: epIds,
}
epInfo, err = d.epClient.Cards(c, arg)
if err != nil {
log.Error("d.rpcClient.Cards error(%v)", err)
return nil, err
}
res = epInfo.Cards
return
}

View File

@@ -0,0 +1,40 @@
package pgc
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestPgcCardsInfoReply(t *testing.T) {
convey.Convey("CardsInfoReply", t, func(ctx convey.C) {
var (
c = context.Background()
seasonIds = []int32{33730}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CardsInfoReply(c, seasonIds)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestPgcCardsEpInfoReply(t *testing.T) {
convey.Convey("CardsEpInfoReply", t, func(ctx convey.C) {
var (
c = context.Background()
epIds = []int32{117117}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CardsEpInfoReply(c, epIds)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}