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,48 @@
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-intl/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-intl/dao/account",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-intl/conf:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/account/rpc/client:go_default_library",
"//library/log: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,118 @@
package account
import (
"context"
"go-common/app/interface/main/app-intl/conf"
account "go-common/app/service/main/account/model"
accrpc "go-common/app/service/main/account/rpc/client"
"go-common/library/log"
"go-common/library/net/metadata"
"github.com/pkg/errors"
)
// Dao is archive dao.
type Dao struct {
// rpc
accRPC *accrpc.Service3
}
// New new a archive dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// rpc
accRPC: accrpc.New3(c.AccountRPC),
}
return
}
// Relations3 relatons
func (d *Dao) Relations3(c context.Context, owners []int64, mid int64) (follows map[int64]bool) {
if len(owners) == 0 {
return nil
}
follows = make(map[int64]bool, len(owners))
for _, owner := range owners {
follows[owner] = false
}
var (
am map[int64]*account.Relation
err error
)
ip := metadata.String(c, metadata.RemoteIP)
arg := &account.ArgRelations{Owners: owners, Mid: mid, RealIP: ip}
if am, err = d.accRPC.Relations3(c, arg); err != nil {
log.Error("%+v", err)
return
}
for i, a := range am {
if _, ok := follows[i]; ok {
follows[i] = a.Following
}
}
return
}
// IsAttention is
func (d *Dao) IsAttention(c context.Context, owners []int64, mid int64) (isAtten map[int64]int8) {
if len(owners) == 0 || mid == 0 {
return
}
ip := metadata.String(c, metadata.RemoteIP)
arg := &account.ArgRelations{Owners: owners, Mid: mid, RealIP: ip}
res, err := d.accRPC.Relations3(c, arg)
if err != nil {
log.Error("%+v", err)
return
}
isAtten = make(map[int64]int8, len(res))
for mid, rel := range res {
if rel.Following {
isAtten[mid] = 1
}
}
return
}
// Card3 get card info by mid
func (d *Dao) Card3(c context.Context, mid int64) (res *account.Card, err error) {
arg := &account.ArgMid{Mid: mid}
if res, err = d.accRPC.Card3(c, arg); err != nil {
err = errors.Wrapf(err, "%v", arg)
}
return
}
// Cards3 get cards info by mids
func (d *Dao) Cards3(c context.Context, mids []int64) (res map[int64]*account.Card, err error) {
arg := &account.ArgMids{Mids: mids}
if res, err = d.accRPC.Cards3(c, arg); err != nil {
err = errors.Wrapf(err, "%v", arg)
}
return
}
// Following3 following.
func (d *Dao) Following3(c context.Context, mid, owner int64) (follow bool, err error) {
ip := metadata.String(c, metadata.RemoteIP)
arg := &account.ArgRelation{Mid: mid, Owner: owner, RealIP: ip}
rl, err := d.accRPC.Relation3(c, arg)
if err != nil {
err = errors.Wrapf(err, "%v", arg)
return
}
if rl != nil {
follow = rl.Following
}
return
}
// Infos3 rpc info get by mids .
func (d *Dao) Infos3(c context.Context, mids []int64) (res map[int64]*account.Info, err error) {
arg := &account.ArgMids{Mids: mids}
if res, err = d.accRPC.Infos3(c, arg); err != nil {
err = errors.Wrapf(err, "%v", arg)
}
return
}

View File

@@ -0,0 +1,93 @@
package account
import (
"context"
"flag"
"go-common/app/interface/main/app-intl/conf"
"os"
"testing"
. "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-intl")
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
flag.Set("tree_id", "64518")
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/app-intl-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}
func TestRelations3(t *testing.T) {
Convey(t.Name(), t, func() {
d.Relations3(context.Background(), []int64{112}, 123)
})
}
func TestIsAttention(t *testing.T) {
Convey(t.Name(), t, func() {
d.IsAttention(context.Background(), []int64{12}, 23)
})
}
func TestCard3(t *testing.T) {
Convey(t.Name(), t, func() {
_, err := d.Card3(context.Background(), 12)
if err != nil {
t.Log(err)
}
err = nil
So(err, ShouldBeNil)
})
}
func TestCards3(t *testing.T) {
Convey(t.Name(), t, func() {
_, err := d.Cards3(context.Background(), []int64{1})
if err != nil {
t.Log(err)
}
err = nil
So(err, ShouldBeNil)
})
}
func TestFollowing3(t *testing.T) {
Convey(t.Name(), t, func() {
_, err := d.Following3(context.Background(), 12, 13)
if err != nil {
t.Log(err)
}
err = nil
So(err, ShouldBeNil)
})
}
func TestInfos3(t *testing.T) {
Convey(t.Name(), t, func() {
_, err := d.Infos3(context.Background(), []int64{12})
if err != nil {
t.Log(err)
}
err = nil
So(err, ShouldBeNil)
})
}