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,49 @@
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"],
importpath = "go-common/app/interface/main/app-view/dao/creative",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-view/conf:go_default_library",
"//app/interface/main/app-view/model/creative: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,132 @@
package creative
import (
"context"
"net/url"
"strconv"
"go-common/app/interface/main/app-view/conf"
"go-common/app/interface/main/app-view/model/creative"
"go-common/library/ecode"
httpx "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
"github.com/pkg/errors"
)
const (
_special = "/x/internal/uper/special"
_follow = "/x/internal/uper/switch"
_bgm = "/x/internal/creative/archive/bgm"
_points = "/x/internal/creative/video/viewpoints"
)
// Dao is space dao
type Dao struct {
client *httpx.Client
special string
follow string
bgm string
points string
}
// New initial space dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPClient),
special: c.Host.APICo + _special,
follow: c.Host.APICo + _follow,
bgm: c.Host.APICo + _bgm,
points: c.Host.APICo + _points,
}
return
}
// FollowSwitch get auto follow switch .
func (d *Dao) FollowSwitch(c context.Context, vmid int64) (s *creative.FollowSwitch, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(vmid, 10))
params.Set("from", "0")
var res struct {
Code int `json:"code"`
Data *creative.FollowSwitch `json:"data"`
}
ip := metadata.String(c, metadata.RemoteIP)
if err = d.client.Get(c, d.follow, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.follow+"?"+params.Encode())
return
}
s = res.Data
return
}
// Bgm get archive bgm
func (d *Dao) Bgm(c context.Context, aid, cid int64) (bgm []*creative.Bgm, err error) {
params := url.Values{}
params.Set("aid", strconv.FormatInt(aid, 10))
params.Set("cid", strconv.FormatInt(cid, 10))
var res struct {
Code int `json:"code"`
Data []*creative.Bgm `json:"data"`
}
ip := metadata.String(c, metadata.RemoteIP)
if err = d.client.Get(c, d.bgm, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.bgm+"?"+params.Encode())
return
}
bgm = res.Data
return
}
// Points get video points
func (d *Dao) Points(c context.Context, aid, cid int64) (points []*creative.Points, err error) {
params := url.Values{}
params.Set("aid", strconv.FormatInt(aid, 10))
params.Set("cid", strconv.FormatInt(cid, 10))
var res struct {
Code int `json:"code"`
Data struct {
Points []*creative.Points `json:"points"`
} `json:"data"`
}
ip := metadata.String(c, metadata.RemoteIP)
if err = d.client.Get(c, d.points, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.points+"?"+params.Encode())
return
}
points = res.Data.Points
return
}
// Special is
func (d *Dao) Special(c context.Context) (midsM map[int64]struct{}, err error) {
params := url.Values{}
params.Set("group_id", "20")
var res struct {
Code int `json:"code"`
Data []struct {
Mid int64 `json:"mid"`
} `json:"data"`
}
if err = d.client.Get(c, d.special, "", params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.special+"?"+params.Encode())
return
}
midsM = make(map[int64]struct{})
for _, l := range res.Data {
midsM[l.Mid] = struct{}{}
}
return
}

View File

@@ -0,0 +1,89 @@
package creative
import (
"context"
"flag"
"os"
"testing"
"go-common/app/interface/main/app-view/conf"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.app-svr.app-view")
flag.Set("conf_token", "3a4CNLBhdFbRQPs7B4QftGvXHtJo92xw")
flag.Set("tree_id", "4575")
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)
m.Run()
os.Exit(0)
}
func TestMovie(t *testing.T) {
var (
c = context.TODO()
vmid = int64(0)
)
convey.Convey("Movie", t, func(ctx convey.C) {
_, err := d.FollowSwitch(c, vmid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
err = nil
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestBgm(t *testing.T) {
var (
c = context.TODO()
aid = int64(10110995)
cid = int64(10135146)
)
convey.Convey("Bgm", t, func(ctx convey.C) {
_, err := d.Bgm(c, aid, cid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
err = nil
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestPoints(t *testing.T) {
var (
c = context.TODO()
aid = int64(10110995)
cid = int64(10135146)
)
convey.Convey("Points", t, func(ctx convey.C) {
_, err := d.Points(c, aid, cid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
err = nil
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestSpecial(t *testing.T) {
convey.Convey("Special", t, func(ctx convey.C) {
midsM, err := d.Special(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.Println(midsM)
})
}