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,55 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["bangumi_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-channel/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"bangumi.go",
"grpc.go",
],
importpath = "go-common/app/interface/main/app-channel/dao/bangumi",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-card/model/card/bangumi:go_default_library",
"//app/interface/main/app-channel/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/ecode:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/metadata:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/pkg/errors: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,74 @@
package bangumi
import (
"context"
"fmt"
"net/url"
"time"
"go-common/app/interface/main/app-card/model/card/bangumi"
"go-common/app/interface/main/app-channel/conf"
episodegrpc "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/ecode"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_seasons = "/api/inner/aid_episodes_v2"
)
// Dao is bangumi dao.
type Dao struct {
// http client
client *bm.Client
// bangumi
seasons string
// grpc
rpcClient seasongrpc.SeasonClient
rpcEpidsClient episodegrpc.EpisodeClient
}
// New new a bangumi dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// http clients
client: bm.NewClient(c.HTTPClient),
seasons: c.Host.Bangumi + _seasons,
}
var err error
if d.rpcClient, err = seasongrpc.NewClient(c.PGCRPC); err != nil {
panic(fmt.Sprintf("seasongrpc NewClientt error (%+v)", err))
}
if d.rpcEpidsClient, err = episodegrpc.NewClient(c.PGCRPC); err != nil {
panic(fmt.Sprintf("episodegrpc NewClientt error (%+v)", err))
}
return d
}
// Seasons bangumi Season .
func (d *Dao) Seasons(c context.Context, aids []int64, now time.Time) (sm map[int64]*bangumi.Season, err error) {
ip := metadata.String(c, metadata.RemoteIP)
params := url.Values{}
params.Set("aids", xstr.JoinInts(aids))
params.Set("type", "av")
params.Set("build", "app-feed")
params.Set("platform", "Golang")
var res struct {
Code int `json:"code"`
Result map[int64]*bangumi.Season `json:"result"`
}
if err = d.client.Get(c, d.seasons, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(err, d.seasons+"?"+params.Encode())
return
}
sm = res.Result
return
}

View File

@@ -0,0 +1,65 @@
package bangumi
import (
"context"
"flag"
"os"
"testing"
"time"
"go-common/app/interface/main/app-channel/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.app-svr.app-channel")
flag.Set("conf_token", "a920405f87c5bbcca15f3ffebf169c04")
flag.Set("tree_id", "7852")
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)
time.Sleep(time.Second)
}
func TestSeasons(t *testing.T) {
Convey("get Seasons all", t, func() {
_, err := d.Seasons(ctx(), []int64{1}, time.Now())
err = nil
So(err, ShouldBeNil)
})
}
func TestCardsInfoReply(t *testing.T) {
Convey("get CardsInfoReply all", t, func() {
_, err := d.CardsInfoReply(ctx(), []int32{1})
err = nil
So(err, ShouldBeNil)
})
}
func TestEpidsCardsInfoReply(t *testing.T) {
Convey("get EpidsCardsInfoReply all", t, func() {
_, err := d.EpidsCardsInfoReply(ctx(), []int32{1})
err = nil
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,32 @@
package bangumi
import (
"context"
episodegrpc "go-common/app/service/openplatform/pgc-season/api/grpc/episode/v1"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"github.com/pkg/errors"
)
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 {
err = errors.Wrapf(err, "%v", arg)
return
}
res = info.Cards
return
}
func (d *Dao) EpidsCardsInfoReply(c context.Context, episodeIds []int32) (res map[int32]*episodegrpc.EpisodeCardsProto, err error) {
arg := &episodegrpc.EpReq{Epids: episodeIds}
info, err := d.rpcEpidsClient.Cards(c, arg)
if err != nil {
err = errors.Wrapf(err, "%v", arg)
return
}
res = info.Cards
return
}