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,58 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"account.go",
"resource.go",
],
importpath = "go-common/app/interface/main/mcn/dao/global",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/mcn/conf:go_default_library",
"//app/interface/main/tag/api:go_default_library",
"//app/service/main/account/api:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/member/api:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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"],
)
go_test(
name = "go_default_test",
srcs = [
"account_test.go",
"resource_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/main/mcn/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,49 @@
package global
import (
"context"
accgrpc "go-common/app/service/main/account/api"
accmdl "go-common/app/service/main/account/model"
"go-common/library/log"
)
//GetInfo get info
func GetInfo(c context.Context, mid int64) (res *accmdl.Info, err error) {
if mid == 0 {
return
}
var infoReply *accgrpc.InfoReply
if infoReply, err = accGRPC.Info3(c, &accgrpc.MidReq{Mid: mid}); err != nil {
return
}
res = infoReply.Info
return
}
//GetInfos get many infos
func GetInfos(c context.Context, mids []int64) (res map[int64]*accmdl.Info, err error) {
if len(mids) == 0 {
return
}
var infosReply *accgrpc.InfosReply
if infosReply, err = accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
return
}
res = infosReply.Infos
return
}
//GetName get user name
func GetName(c context.Context, mid int64) (nickname string) {
accInfos, e := GetInfos(c, []int64{mid})
if e == nil && accInfos != nil {
var info, ok = accInfos[mid]
if ok {
nickname = info.Name
}
} else {
log.Warn("get up info fail, err=%s", e)
}
return
}

View File

@@ -0,0 +1,55 @@
package global
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestGlobalGetInfo(t *testing.T) {
convey.Convey("GetInfo", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(417851)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := GetInfo(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)
})
})
})
}
func TestGlobalGetInfos(t *testing.T) {
convey.Convey("GetInfos", t, func(ctx convey.C) {
var (
c = context.Background()
mid = []int64{417851}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := GetInfos(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)
})
})
})
}
func TestGlobalGetName(t *testing.T) {
convey.Convey("GetName", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
nickname := GetName(c, mid)
ctx.Convey("Then nickname should not be nil.", func(ctx convey.C) {
ctx.So(nickname, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,74 @@
package global
import (
"go-common/app/interface/main/mcn/conf"
taggrpc "go-common/app/interface/main/tag/api"
accgrpc "go-common/app/service/main/account/api"
arcgrpc "go-common/app/service/main/archive/api"
memgrpc "go-common/app/service/main/member/api"
"go-common/library/cache/memcache"
bm "go-common/library/net/http/blademaster"
"github.com/pkg/errors"
)
var (
accGRPC accgrpc.AccountClient
memGRPC memgrpc.MemberClient
arcGRPC arcgrpc.ArchiveClient
tagGRPC taggrpc.TagRPCClient
mc *memcache.Pool
bmClient *bm.Client
)
// GetAccGRPC .
func GetAccGRPC() accgrpc.AccountClient {
return accGRPC
}
// GetMemGRPC .
func GetMemGRPC() memgrpc.MemberClient {
return memGRPC
}
// GetArcGRPC .
func GetArcGRPC() arcgrpc.ArchiveClient {
return arcGRPC
}
// GetTagGRPC .
func GetTagGRPC() taggrpc.TagRPCClient {
return tagGRPC
}
// GetMc get mc
func GetMc() *memcache.Pool {
return mc
}
// GetBMClient get http client
func GetBMClient() *bm.Client {
return bmClient
}
//Init init global
func Init(c *conf.Config) {
var err error
if accGRPC, err = accgrpc.NewClient(c.GRPCClient.Account); err != nil {
panic(errors.WithMessage(err, "Failed to dial account service"))
}
if memGRPC, err = memgrpc.NewClient(c.GRPCClient.Member); err != nil {
panic(errors.WithMessage(err, "Failed to dial member service"))
}
if arcGRPC, err = arcgrpc.NewClient(c.GRPCClient.Archive); err != nil {
panic(errors.WithMessage(err, "Failed to dial archive service"))
}
if tagGRPC, err = taggrpc.NewClient(c.GRPCClient.Tag); err != nil {
panic(errors.WithMessage(err, "Failed to dial tag service"))
}
mc = memcache.NewPool(&c.Memcache.Config)
bmClient = bm.NewClient(c.HTTPClient)
}

View File

@@ -0,0 +1,69 @@
package global
import (
"flag"
"os"
"testing"
"go-common/app/interface/main/mcn/conf"
"github.com/smartystreets/goconvey/convey"
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.mcn-interface")
flag.Set("conf_token", "49e4671bafbf93059aeb602685052ca0")
flag.Set("tree_id", "58909")
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/mcn-interface.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/mcn-interface.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
Init(conf.Conf)
os.Exit(m.Run())
}
func TestGlobalGetAccGRPC(t *testing.T) {
convey.Convey("GetAccGRPC", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := GetAccGRPC()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalGetMemGRPC(t *testing.T) {
convey.Convey("GetMemGRPC", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := GetMemGRPC()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalGetArcGRPC(t *testing.T) {
convey.Convey("GetArcGRPC", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := GetArcGRPC()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}