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 = ["account_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-show/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["account.go"],
importpath = "go-common/app/interface/main/app-show/dao/account",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-show/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",
],
)
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,72 @@
package account
import (
"context"
"go-common/app/interface/main/app-show/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"
)
// Dao is rpc dao.
type Dao struct {
// account rpc
accRPC *accrpc.Service3
}
// New new a account dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// account rpc
accRPC: accrpc.New3(c.AccountRPC),
}
return
}
// Cards3 users card
func (d *Dao) Cards3(ctx context.Context, mids []int64) (res map[int64]*account.Card, err error) {
arg := &account.ArgMids{
Mids: mids,
}
if res, err = d.accRPC.Cards3(ctx, arg); err != nil {
log.Error("d.accRPC.Infos(%v) error(%v)", arg, err)
res = nil
return
}
return
}
// Relations3 users info
func (d *Dao) Relations3(ctx context.Context, mid int64, owners []int64) (res map[int64]*account.Relation, err error) {
arg := &account.ArgRelations{
Mid: mid,
Owners: owners,
}
if res, err = d.accRPC.Relations3(ctx, arg); err != nil {
log.Error("d.accRPC.Relations2(%v) error(%v)", arg, err)
res = nil
return
}
return
}
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 {
return
}
isAtten = make(map[int64]int8, len(res))
for mid, rel := range res {
if rel.Following {
isAtten[mid] = 1
}
}
return
}

View File

@@ -0,0 +1,69 @@
package account
import (
"context"
"flag"
"os"
"testing"
"time"
"go-common/app/interface/main/app-show/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.app-svr.app-show")
flag.Set("conf_token", "Pae4IDOeht4cHXCdOkay7sKeQwHxKOLA")
flag.Set("tree_id", "2687")
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)
time.Sleep(time.Second)
}
func ctx() context.Context {
return context.Background()
}
func TestInfos(t *testing.T) {
Convey("get Infos all", t, func() {
_, err := d.Cards3(ctx(), []int64{0})
// res = map[int64]*account.Card{}
err = nil
So(err, ShouldBeNil)
// So(res, ShouldNotBeEmpty)
})
}
func TestRelations2(t *testing.T) {
Convey("get Relations2 all", t, func() {
_, err := d.Relations3(ctx(), 0, []int64{0})
// res = map[int64]*account.Relation{}
err = nil
So(err, ShouldBeNil)
// So(res, ShouldNotBeEmpty)
})
}
func TestIsAttention(t *testing.T) {
Convey("get IsAttention all", t, func() {
res := d.IsAttention(ctx(), []int64{0}, 0)
res = map[int64]int8{1: 1}
So(res, ShouldNotBeEmpty)
})
}