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,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["fans_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/reply/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["fans.go"],
importpath = "go-common/app/interface/main/reply/dao/fans",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/reply/conf:go_default_library",
"//app/interface/main/reply/model/reply: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,58 @@
package fans
import (
"context"
"net/url"
"strconv"
"time"
"go-common/app/interface/main/reply/conf"
"go-common/app/interface/main/reply/model/reply"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
)
// Dao Dao
type Dao struct {
fansReceivedListURL string
fansReceivedListHTTPClient *httpx.Client
}
// New New
func New(c *conf.Config) *Dao {
d := &Dao{
fansReceivedListURL: c.Reply.FansReceivedListURL,
fansReceivedListHTTPClient: httpx.NewClient(c.HTTPClient),
}
return d
}
// Fetch Fetch
func (dao *Dao) Fetch(c context.Context, uids []int64, mid int64, now time.Time) (map[int64]*reply.FansDetail, error) {
fansMap := make(map[int64]*reply.FansDetail)
if len(uids) == 0 {
return fansMap, nil
}
params := url.Values{}
params.Set("target_id", strconv.FormatInt(mid, 10))
params.Set("source", strconv.FormatInt(2, 10))
for index := range uids {
params.Add("uid[]", strconv.FormatInt(uids[index], 10))
}
var res struct {
Code int `json:"code"`
Message string `json:"msg"`
Data []*reply.FansDetail `json:"data"`
}
if err := dao.fansReceivedListHTTPClient.Get(c, dao.fansReceivedListURL, "", params, &res); err != nil {
log.Error("fansFetch url(%v),err (%v)", dao.fansReceivedListURL+"?"+params.Encode(), err)
return fansMap, err
}
if res.Code != 0 {
return fansMap, nil
}
for _, d := range res.Data {
fansMap[d.UID] = d
}
return fansMap, nil
}

View File

@@ -0,0 +1,70 @@
package fans
import (
"context"
"flag"
"go-common/app/interface/main/reply/conf"
"os"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "")
flag.Set("conf_token", "")
flag.Set("tree_id", "")
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/reply-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}
func TestFansNew(t *testing.T) {
convey.Convey("New", t, func(ctx convey.C) {
var (
c = conf.Conf
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := New(c)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestFansFetch(t *testing.T) {
convey.Convey("Fetch", t, func(ctx convey.C) {
var (
c = context.Background()
uids = []int64{}
mid = int64(0)
now = time.Now()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1, err := d.Fetch(c, uids, mid, now)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}