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,55 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"card_test.go",
"dao_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/tv/conf:go_default_library",
"//app/service/main/account/model:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"card.go",
"dao.go",
],
importpath = "go-common/app/interface/main/tv/dao/account",
tags = ["automanaged"],
deps = [
"//app/interface/main/tv/conf:go_default_library",
"//app/service/main/account/api:go_default_library",
"//app/service/main/account/model:go_default_library",
"//library/ecode:go_default_library",
"//library/log: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,35 @@
package account
import (
"context"
accwar "go-common/app/service/main/account/api"
accmdl "go-common/app/service/main/account/model"
"go-common/library/ecode"
"go-common/library/log"
)
// Card3 get card info by mid
func (d *Dao) Card3(c context.Context, mid int64) (res *accmdl.Card, err error) {
var (
arg = &accwar.MidReq{Mid: mid}
reply *accwar.CardReply
)
if reply, err = d.accClient.Card3(c, arg); err != nil || reply == nil || reply.Card == nil {
if err != nil {
log.Error("s.accDao.Info(%d) error(%v)", mid, err)
}
err = ecode.AccessDenied
return
}
res = reply.Card
return
}
// IsVip checks whether the member is vip
func IsVip(card *accmdl.Card) bool {
if card.Vip.Type == 0 || card.Vip.Status == 0 || card.Vip.Status == 2 || card.Vip.Status == 3 {
return false
}
return true
}

View File

@@ -0,0 +1,51 @@
package account
import (
"context"
"testing"
accmdl "go-common/app/service/main/account/model"
"go-common/library/ecode"
"github.com/smartystreets/goconvey/convey"
)
func TestAccountCard3(t *testing.T) {
var (
c = context.Background()
mid = int64(27515256)
)
convey.Convey("Card3", t, func(ctx convey.C) {
res, err := d.Card3(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
res, err = d.Card3(c, 777777777777)
ctx.So(err, convey.ShouldEqual, ecode.AccessDenied)
ctx.So(res, convey.ShouldBeNil)
})
}
func TestAccountIsVip(t *testing.T) {
var (
cardFalse = &accmdl.Card{}
// card.Vip.Type == 0 || card.Vip.Status == 0 || card.Vip.Status == 2 || card.Vip.Status == 3
cardTrue = &accmdl.Card{
Vip: accmdl.VipInfo{
Type: 1,
Status: 1,
},
}
)
convey.Convey("IsVip", t, func(ctx convey.C) {
p1 := IsVip(cardFalse)
ctx.Convey("Then p1 should be false.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldBeFalse)
})
p2 := IsVip(cardTrue)
ctx.Convey("Then p2 should be true.", func(ctx convey.C) {
ctx.So(p2, convey.ShouldBeTrue)
})
})
}

View File

@@ -0,0 +1,22 @@
package account
import (
"go-common/app/interface/main/tv/conf"
accwar "go-common/app/service/main/account/api"
)
// Dao is account dao.
type Dao struct {
// rpc
accClient accwar.AccountClient
}
// New account dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{}
var err error
if d.accClient, err = accwar.NewClient(c.AccClient); err != nil {
panic(err)
}
return
}

View File

@@ -0,0 +1,34 @@
package account
import (
"flag"
"os"
"testing"
"go-common/app/interface/main/tv/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.web-svr.tv-interface")
flag.Set("conf_token", "07c1826c1f39df02a1411cdd6f455879")
flag.Set("tree_id", "15326")
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)
m.Run()
os.Exit(0)
}