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,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"databus.go",
],
importpath = "go-common/app/job/main/favorite/dao/pub",
tags = ["automanaged"],
deps = [
"//app/job/main/favorite/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,24 @@
package pub
import (
"go-common/app/job/main/favorite/conf"
"go-common/library/queue/databus"
)
// Dao stat dao.
type Dao struct {
databus2 *databus.Databus
consumersMap map[int8]string
}
// New new a stat dao and return.
func New(c *conf.Config) *Dao {
consumersMap := make(map[int8]string)
for name, typ := range c.StatFavDatabus.Consumers {
consumersMap[typ] = name
}
return &Dao{
databus2: databus.New(c.StatFavDatabus.Config),
consumersMap: consumersMap,
}
}

View File

@@ -0,0 +1,32 @@
package pub
import (
"context"
"strconv"
"time"
"go-common/library/log"
)
type statMessage struct {
Type string `json:"type"`
ID int64 `json:"id"`
Count int64 `json:"count"`
TimeStamp int64 `json:"timestamp"`
}
// PubStats update object's fav count
func (d *Dao) PubStats(c context.Context, typ int8, oid int64, cnt int64) (err error) {
if name, ok := d.consumersMap[typ]; ok {
msg := &statMessage{
Type: name,
ID: oid,
Count: cnt,
TimeStamp: time.Now().Unix(),
}
if err = d.databus2.Send(c, strconv.FormatInt(oid, 10), msg); err != nil {
log.Error("d.databus2.Send(%d,%d,%v) error(%v)", typ, oid, msg, err)
}
}
return
}