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,50 @@
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/interface/main/ugcpay-rank/internal/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/ugcpay-rank/internal/conf:go_default_library",
"//app/service/main/ugcpay-rank/api/v1: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"],
tags = ["automanaged"],
deps = [
"//app/interface/main/ugcpay-rank/internal/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,32 @@
package dao
import (
"context"
"go-common/app/interface/main/ugcpay-rank/internal/conf"
ugcpay_rank "go-common/app/service/main/ugcpay-rank/api/v1"
)
// Dao dao
type Dao struct {
ugcPayRankAPI ugcpay_rank.UGCPayRankClient
}
// New init mysql db
func New() (dao *Dao) {
dao = &Dao{}
var err error
if dao.ugcPayRankAPI, err = ugcpay_rank.NewClient(conf.Conf.UGCPayRankGRPC); err != nil {
panic(err)
}
return
}
// Close close the resource.
func (d *Dao) Close() {
}
// Ping dao ping
func (d *Dao) Ping(ctx context.Context) error {
return nil
}

View File

@@ -0,0 +1,35 @@
package dao
import (
"flag"
"os"
"testing"
"go-common/app/interface/main/ugcpay-rank/internal/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.account.ugcpay-rank-interface")
flag.Set("conf_token", "a1d2ed55cb091980e95cd94cfc9361cc")
flag.Set("tree_id", "72347")
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/test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New()
os.Exit(m.Run())
}

View File

@@ -0,0 +1,42 @@
package dao
import (
"context"
api "go-common/app/service/main/ugcpay-rank/api/v1"
)
// RankElecMonth .
func (d *Dao) RankElecMonth(ctx context.Context, avID, upMID int64, rankSize int) (resp *api.RankElecMonthResp, err error) {
var (
req = &api.RankElecMonthReq{
AVID: avID,
UPMID: upMID,
RankSize: rankSize,
}
)
return d.ugcPayRankAPI.RankElecMonth(ctx, req)
}
// RankElecMonthUP .
func (d *Dao) RankElecMonthUP(ctx context.Context, upMID int64, rankSize int) (rank *api.RankElecUPResp, err error) {
var (
req = &api.RankElecUPReq{
UPMID: upMID,
RankSize: rankSize,
}
)
return d.ugcPayRankAPI.RankElecMonthUP(ctx, req)
}
// RankElecAllAV .
func (d *Dao) RankElecAllAV(ctx context.Context, upMID int64, avID int64, rankSize int) (rank *api.RankElecAVResp, err error) {
var (
req = &api.RankElecAVReq{
UPMID: upMID,
AVID: avID,
RankSize: rankSize,
}
)
return d.ugcPayRankAPI.RankElecAllAV(ctx, req)
}

View File

@@ -0,0 +1,61 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoElecMonthRank(t *testing.T) {
convey.Convey("ElecMonthRank", t, func(ctx convey.C) {
var (
c = context.Background()
avID = int64(0)
upMID = int64(0)
rankSize = int(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
resp, err := d.RankElecMonth(c, avID, upMID, rankSize)
ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(resp, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoElecMonthRankUP(t *testing.T) {
convey.Convey("ElecMonthRankUP", t, func(ctx convey.C) {
var (
c = context.Background()
upMID = int64(0)
rankSize = int(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
rank, err := d.RankElecMonthUP(c, upMID, rankSize)
ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rank, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoElecTotalRankAV(t *testing.T) {
convey.Convey("ElecTotalRankAV", t, func(ctx convey.C) {
var (
c = context.Background()
upMID = int64(0)
avID = int64(0)
rankSize = int(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
rank, err := d.RankElecAllAV(c, upMID, avID, rankSize)
ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rank, convey.ShouldNotBeNil)
})
})
})
}