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 = ["drawyoo_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 = ["drawyoo.go"],
importpath = "go-common/app/interface/main/reply/dao/drawyoo",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/reply/conf:go_default_library",
"//app/interface/main/reply/model/drawyoo:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr: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,73 @@
package drawyoo
import (
"context"
"net/url"
"strconv"
"go-common/app/interface/main/reply/conf"
"go-common/app/interface/main/reply/model/drawyoo"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
"go-common/library/xstr"
)
// Dao Dao
type Dao struct {
url string
http *httpx.Client
}
// New New
func New(c *conf.Config) *Dao {
d := &Dao{
url: "http://h.bilibili.com/api/pushS",
http: httpx.NewClient(c.DrawyooHTTPClient),
}
return d
}
// Info Info
func (dao *Dao) Info(c context.Context, hid int64) (info *drawyoo.Drawyoo, err error) {
params := url.Values{}
params.Set("act", "getHidInfo")
params.Set("hid", strconv.FormatInt(hid, 10))
var res struct {
State int `json:"state"`
Data []*drawyoo.Drawyoo `json:"data"`
}
if err = dao.http.Post(c, dao.url, "", params, &res); err != nil {
log.Error("drawyoo url(%v),err (%v)", dao.url+"?"+params.Encode(), err)
return
}
if res.State != 200 || len(res.Data) == 0 {
log.Error("drawyoo url (%v),err (%v)", dao.url+"?"+params.Encode(), err)
return
}
info = res.Data[0]
return
}
// Infos Infos
func (dao *Dao) Infos(c context.Context, hids []int64) (info map[int64]interface{}, err error) {
params := url.Values{}
params.Set("act", "getHidInfo")
params.Set("hid", xstr.JoinInts(hids))
var res struct {
State int `json:"state"`
Data []*drawyoo.Drawyoo `json:"data"`
}
if err = dao.http.Post(c, dao.url, "", params, &res); err != nil {
log.Error("drawyoo url(%v),err (%v)", dao.url+"?"+params.Encode(), err)
return
}
if res.State != 200 || len(res.Data) == 0 {
log.Error("drawyoo url (%v),err (%v)", dao.url+"?"+params.Encode(), err)
return
}
info = make(map[int64]interface{}, len(res.Data))
for _, r := range res.Data {
info[r.Hid] = r
}
return
}

View File

@@ -0,0 +1,84 @@
package drawyoo
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 TestDrawyooNew(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 TestDrawyooInfo(t *testing.T) {
convey.Convey("Info", t, func(ctx convey.C) {
var (
c = context.Background()
hid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
info, err := d.Info(c, hid)
ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(info, convey.ShouldBeNil)
})
})
})
}
func TestDrawyooInfos(t *testing.T) {
convey.Convey("Infos", t, func(ctx convey.C) {
var (
c = context.Background()
hids = []int64{}
d = New(conf.Conf)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
info, err := d.Infos(c, hids)
ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(info, convey.ShouldBeNil)
})
})
})
}