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,52 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-view/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"grpc.go",
],
importpath = "go-common/app/interface/main/app-view/dao/bangumi",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-view/conf:go_default_library",
"//app/interface/main/app-view/model/bangumi: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",
"//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,120 @@
package bangumi
import (
"context"
"net/url"
"strconv"
"time"
"go-common/app/interface/main/app-view/conf"
"go-common/app/interface/main/app-view/model/bangumi"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"go-common/library/ecode"
httpx "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
"github.com/pkg/errors"
)
const (
_pgc = "/pgc/internal/season/appview"
_movie = "/internal_api/movie_aid_info"
_seasonidAidURL = "/api/inner/archive/seasonid2aid"
)
// Dao is bangumi dao
type Dao struct {
client *httpx.Client
pgc string
movie string
seasonidAidURL string
// grpc
rpcClient seasongrpc.SeasonClient
}
// New bangumi dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPBangumi),
pgc: c.Host.APICo + _pgc,
movie: c.Host.Bangumi + _movie,
seasonidAidURL: c.Host.Bangumi + _seasonidAidURL,
}
var err error
if d.rpcClient, err = seasongrpc.NewClient(nil); err != nil {
panic(errors.WithMessage(err, "panic by seasongrpc"))
}
return
}
// PGC bangumi Season .
func (d *Dao) PGC(c context.Context, aid, mid int64, build int, mobiApp, device string) (s *bangumi.Season, err error) {
ip := metadata.String(c, metadata.RemoteIP)
params := url.Values{}
params.Set("aid", strconv.FormatInt(aid, 10))
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("build", strconv.Itoa(build))
params.Set("device", device)
params.Set("mobi_app", mobiApp)
params.Set("platform", "Golang")
var res struct {
Code int `json:"code"`
Result *bangumi.Season `json:"result"`
}
if err = d.client.Get(c, d.pgc, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.pgc+"?"+params.Encode())
return
}
s = res.Result
return
}
// Movie bangumi Movie
func (d *Dao) Movie(c context.Context, aid, mid int64, build int, mobiApp, device string) (m *bangumi.Movie, err error) {
ip := metadata.String(c, metadata.RemoteIP)
params := url.Values{}
params.Set("id", strconv.FormatInt(aid, 10))
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("build", strconv.Itoa(build))
params.Set("device", device)
params.Set("mobi_app", mobiApp)
params.Set("platform", "Golang")
var res struct {
Code int `json:"code"`
Result *bangumi.Movie `json:"result"`
}
if err = d.client.Get(c, d.movie, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.movie+"?"+params.Encode())
return
}
m = res.Result
return
}
// SeasonidAid moive_id by aid
func (d *Dao) SeasonidAid(c context.Context, moiveID int64, now time.Time) (data map[int64]int64, err error) {
params := url.Values{}
params.Set("build", "app-api")
params.Set("platform", "Golang")
params.Set("season_id", strconv.FormatInt(moiveID, 10))
params.Set("season_type", "2")
var res struct {
Code int `json:"code"`
Result map[int64]int64 `json:"result"`
}
if err = d.client.Get(c, d.seasonidAidURL, "", params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.seasonidAidURL+"?"+params.Encode())
return
}
data = res.Result
return
}

View File

@@ -0,0 +1,53 @@
package bangumi
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/app-view/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
dir, _ := filepath.Abs("../../cmd/app-view-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func ctx() context.Context {
return context.Background()
}
func TestMovie(t *testing.T) {
Convey("get Movie all", t, func() {
res, err := d.Movie(ctx(), 1, 1, 1, "iphone", "phone")
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func TestPGC(t *testing.T) {
Convey("get PGC all", t, func() {
res, err := d.PGC(ctx(), 1, 1, 1, "iphone", "phone")
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func TestSeasonidAid(t *testing.T) {
Convey("get SeasonidAid all", t, func() {
res, err := d.SeasonidAid(ctx(), 1, time.Now())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}

View File

@@ -0,0 +1,21 @@
package bangumi
import (
"context"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"github.com/pkg/errors"
)
// CardsInfoReply pgc cards info
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
}