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,60 @@
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",
"rpc_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/job/main/creative/conf:go_default_library",
"//vendor/github.com/go-sql-driver/mysql:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"rpc.go",
],
importpath = "go-common/app/job/main/creative/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/openplatform/article/model:go_default_library",
"//app/interface/openplatform/article/rpc/client:go_default_library",
"//app/job/main/creative/conf:go_default_library",
"//app/job/main/creative/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/api/gorpc:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,77 @@
package archive
import (
"context"
"net/url"
"strconv"
article "go-common/app/interface/openplatform/article/rpc/client"
"go-common/app/job/main/creative/conf"
"go-common/app/job/main/creative/model"
archive "go-common/app/service/main/archive/api/gorpc"
"go-common/library/ecode"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
)
// Dao is archive dao.
type Dao struct {
// config
c *conf.Config
// rpc
arc *archive.Service2
art *article.Service
// http client
client *httpx.Client
viewURL string
}
// New init api url
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
arc: archive.New2(c.ArchiveRPC),
art: article.New(c.ArticleRPC),
// http client
client: httpx.NewClient(c.HTTPClient.Normal),
viewURL: c.Host.Videoup + "/videoup/view",
}
return
}
// Ping fn
func (d *Dao) Ping(c context.Context) (err error) {
return
}
// Close fn
func (d *Dao) Close() (err error) {
return
}
// View get archive
func (d *Dao) View(c context.Context, mid, aid int64) (av *model.ArcVideo, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("aid", strconv.FormatInt(aid, 10))
var res struct {
Code int `json:"code"`
Data *model.ArcVideo `json:"data"`
}
if err = d.client.Get(c, d.viewURL, "", params, &res); err != nil {
log.Error("archive.view url(%s) mid(%d) error(%v)", d.viewURL+"?"+params.Encode(), mid, err)
err = ecode.CreativeArchiveAPIErr
return
}
if res.Code != 0 {
log.Error("archive.view url(%s) mid(%d) res(%v)", d.viewURL+"?"+params.Encode(), mid, res)
err = ecode.Int(res.Code)
return
}
if res.Data.Archive == nil {
log.Error("archive.view url(%s) mid(%d) res(%v)", d.viewURL+"?"+params.Encode(), mid, res)
return
}
av = res.Data
return
}

View File

@@ -0,0 +1,55 @@
package archive
import (
"context"
"flag"
"os"
"testing"
"go-common/app/job/main/creative/conf"
_ "github.com/go-sql-driver/mysql"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.creative-job")
flag.Set("conf_token", "43943fda0bb311e8865c66d44b23cda7")
flag.Set("tree_id", "16037")
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")
} else {
flag.Set("conf", "../../cmd/creative-job.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}
func Test_UpCount(t *testing.T) {
var (
err error
c = context.TODO()
mid = int64(123)
)
convey.Convey("UpCount", t, func(ctx convey.C) {
ctx.Convey("When everything gose positive", func(ctx convey.C) {
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
_, err = d.UpCount(c, mid)
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}

View File

@@ -0,0 +1,65 @@
package archive
import (
"context"
"strconv"
"go-common/app/interface/openplatform/article/model"
"go-common/app/service/main/archive/api"
"go-common/app/service/main/archive/model/archive"
"go-common/library/ecode"
"go-common/library/log"
)
// UpCount get archives count.
func (d *Dao) UpCount(c context.Context, mid int64) (count int, err error) {
var arg = &archive.ArgUpCount2{Mid: mid}
if count, err = d.arc.UpCount2(c, arg); err != nil {
log.Error("rpc UpCount2 (%v) error(%v)", mid, err)
err = ecode.CreativeArcServiceErr
}
return
}
// Archives get archive list.
func (d *Dao) Archives(c context.Context, aids []int64) (a map[int64]*api.Arc, err error) {
var arg = &archive.ArgAids2{Aids: aids, RealIP: ""}
if a, err = d.arc.Archives3(c, arg); err != nil {
log.Error("d.arc.Archive3 aids(%v+)|error(%v)", aids, err)
err = ecode.CreativeArcServiceErr
}
return
}
// Archive get archive info.
func (d *Dao) Archive(c context.Context, aid int64) (a *api.Arc, err error) {
var arg = &archive.ArgAid2{Aid: aid, RealIP: ""}
if a, err = d.arc.Archive3(c, arg); err != nil {
log.Error("d.arc.Archive3 aid(%d)|error(%v)", aid, err)
err = ecode.CreativeArcServiceErr
}
return
}
// Stats get archives stat.
func (d *Dao) Stats(c context.Context, aids []int64) (a map[int64]*api.Stat, err error) {
var arg = &archive.ArgAids2{Aids: aids, RealIP: ""}
if a, err = d.arc.Stats3(c, arg); err != nil {
log.Error("rpc Stats (%v) error(%v)", aids, err)
err = ecode.CreativeArcServiceErr
}
return
}
// ArticleMetas batch get articles by aids.
func (d *Dao) ArticleMetas(c context.Context, aids []int64) (res map[int64]*model.Meta, err error) {
arg := &model.ArgAids{Aids: aids, RealIP: ""}
if res, err = d.art.ArticleMetas(c, arg); err != nil {
log.Error("d.art.ArticleMetas aids(%+v)|error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}

View File

@@ -0,0 +1,83 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveUpCount(t *testing.T) {
convey.Convey("UpCount", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.UpCount(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}
func TestArchiveArchives(t *testing.T) {
convey.Convey("Archives", t, func(ctx convey.C) {
var (
c = context.Background()
aids = []int64{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.Archives(c, aids)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}
func TestArchiveArchive(t *testing.T) {
convey.Convey("Archive", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.Archive(c, aid)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}
func TestArchiveStats(t *testing.T) {
convey.Convey("Stats", t, func(ctx convey.C) {
var (
c = context.Background()
aids = []int64{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.Stats(c, aids)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}
func TestArchiveArticleMetas(t *testing.T) {
convey.Convey("ArticleMetas", t, func(ctx convey.C) {
var (
c = context.Background()
aids = []int64{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.ArticleMetas(c, aids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}