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 = ["vip_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 = ["vip.go"],
importpath = "go-common/app/interface/main/reply/dao/vip",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/reply/conf:go_default_library",
"//app/interface/main/reply/model/vip: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,87 @@
package vip
import (
"context"
"net/url"
"go-common/app/interface/main/reply/conf"
"go-common/app/interface/main/reply/model/vip"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const (
_emojiURL = "/internal/v1/emoji/list"
)
type result struct {
Code int `json:"code"`
Data []*struct {
ID int64 `json:"id"`
Name string `json:"name"`
URL string `json:"path"`
State int8 `json:"deleted"`
Emojis []*struct {
ID int64 `json:"id"`
Name string `json:"name"`
URL string `json:"path"`
State int8 `json:"deleted"`
Remark string `json:"remark"`
} `json:"emojiList"`
} `json:"data"`
}
// Dao dao.
type Dao struct {
emojiURL string
httpClient *bm.Client
}
// New new a dao and return.
func New(c *conf.Config) *Dao {
d := &Dao{
httpClient: bm.NewClient(c.HTTPClient),
emojiURL: c.Reply.VipURL + _emojiURL,
}
return d
}
// Emoji return emojis to cache
func (dao *Dao) Emoji(c context.Context) (emjs []*vip.Emoji, emjM map[string]int64, err error) {
var res result
params := url.Values{}
if err = dao.httpClient.Get(c, dao.emojiURL, "", params, &res); err != nil {
log.Error("vip url(%s) error(%v)", dao.emojiURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("vip url(%s) error(%v)", dao.emojiURL+"?"+params.Encode(), res.Code)
return
}
emjs = make([]*vip.Emoji, 0, len(res.Data))
emjM = make(map[string]int64)
for _, d := range res.Data {
var tmp = &vip.Emoji{
Pid: d.ID,
Pname: d.Name,
Purl: d.URL,
Pstate: d.State,
}
emoTmps := make([]*vip.Face, 0, len(d.Emojis))
for _, e := range d.Emojis {
var emoTmp = &vip.Face{
ID: e.ID,
Name: e.Name,
URL: e.URL,
State: e.State,
}
emoTmps = append(emoTmps, emoTmp)
if d.State == 0 && e.State == 0 {
emjM[e.Name] = e.ID
}
}
tmp.Emojis = emoTmps
emjs = append(emjs, tmp)
}
return
}

View File

@@ -0,0 +1,67 @@
package vip
import (
"context"
"flag"
"go-common/app/interface/main/reply/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", "")
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 TestVipNew(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 TestVipEmoji(t *testing.T) {
convey.Convey("Emoji", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
emjs, emjM, err := d.Emoji(c)
ctx.Convey("Then err should be nil.emjs,emjM should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(emjM, convey.ShouldNotBeNil)
ctx.So(emjs, convey.ShouldNotBeNil)
})
})
})
}