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,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["databus_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 = ["databus.go"],
importpath = "go-common/app/interface/main/app-show/dao/databus",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-show/conf:go_default_library",
"//library/log:go_default_library",
"//library/queue/databus: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,38 @@
package databus
import (
"context"
"strconv"
"go-common/app/interface/main/app-show/conf"
"go-common/library/log"
"go-common/library/queue/databus"
)
// Dao is show dao.
type Dao struct {
// databus
dataBus *databus.Databus
}
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// databus
dataBus: databus.New(c.DislikeDataBus),
}
return
}
func (d *Dao) Pub(ctx context.Context, buvid, gt string, id, mid int64) (err error) {
key := strconv.FormatInt(mid, 10)
msg := struct {
Buvid string `json:"buvid"`
Goto string `json:"goto"`
ID int64 `json:"id"`
Mid int64 `json:"mid"`
}{Buvid: buvid, Goto: gt, ID: id, Mid: mid}
if err = d.dataBus.Send(ctx, key, msg); err != nil {
log.Error("d.dataBus.Pub(%s,%v) error (%v)", key, msg, err)
}
return
}

View File

@@ -0,0 +1,36 @@
package databus
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/app-show/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
dir, _ := filepath.Abs("../../cmd/app-show-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func TestPub(t *testing.T) {
Convey("Pub", t, func() {
err := d.Pub(ctx(), "", "", 1, 1)
So(err, ShouldBeNil)
})
}