Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# v1.0.0
1. 上线房间内大航海购买提示

View File

@@ -0,0 +1,9 @@
# Owner
wujunchen
# Author
wujunchen
# Reviewer
xiehaishen
zhaohailin

View File

@@ -0,0 +1,14 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- wujunchen
labels:
- live
- service
- service/live/xuserex
options:
no_parent_owners: true
reviewers:
- wujunchen
- xiehaishen
- zhaohailin

View File

@@ -0,0 +1,12 @@
# xuserex-service
# 项目简介
1.
# 编译环境
# 依赖包
# 编译执行

View File

@@ -0,0 +1,62 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "v1_proto",
srcs = ["roomNotice.proto"],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v1_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/live/xuserex/api/grpc/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"roomNotice.bm.go",
],
embed = [":v1_go_proto"],
importpath = "go-common/app/service/live/xuserex/api/grpc/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/binding:go_default_library",
"//library/net/rpc/warden:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context: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,29 @@
package v1
import (
"context"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
// AppID unique app id for service discovery
const AppID = "live.xuserex"
// Client client
type Client struct {
RoomNoticeClient
}
// NewClient new resource gRPC client
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (*Client, error) {
client := warden.NewClient(cfg, opts...)
conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
if err != nil {
return nil, err
}
cli := &Client{}
cli.RoomNoticeClient = NewRoomNoticeClient(conn)
return cli, nil
}

View File

@@ -0,0 +1,80 @@
// Code generated by protoc-gen-bm v0.1, DO NOT EDIT.
// source: roomNotice.proto
/*
Package v1 is a generated blademaster stub package.
This code was generated with go-common/app/tool/bmgen/protoc-gen-bm v0.1.
It is generated from these files:
roomNotice.proto
*/
package v1
import (
"context"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
)
// to suppressed 'imported but not used warning'
var _ *bm.Context
var _ context.Context
var _ binding.StructValidator
var PathRoomNoticeBuyGuard = "/live.xuserex.v1.RoomNotice/buy_guard"
var PathRoomNoticeIsTaskFinish = "/live.xuserex.v1.RoomNotice/is_task_finish"
var PathRoomNoticeSetTaskFinish = "/live.xuserex.v1.RoomNotice/set_task_finish"
// ====================
// RoomNotice Interface
// ====================
// 房间提示 相关服务
type RoomNoticeBMServer interface {
// 是否弹出大航海购买提示
BuyGuard(ctx context.Context, req *RoomNoticeBuyGuardReq) (resp *RoomNoticeBuyGuardResp, err error)
// habse 任务是否结束
IsTaskFinish(ctx context.Context, req *RoomNoticeIsTaskFinishReq) (resp *RoomNoticeIsTaskFinishResp, err error)
// 手动设置base 任务结束
SetTaskFinish(ctx context.Context, req *RoomNoticeSetTaskFinishReq) (resp *RoomNoticeSetTaskFinishResp, err error)
}
var v1RoomNoticeSvc RoomNoticeBMServer
func roomNoticeBuyGuard(c *bm.Context) {
p := new(RoomNoticeBuyGuardReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RoomNoticeSvc.BuyGuard(c, p)
c.JSON(resp, err)
}
func roomNoticeIsTaskFinish(c *bm.Context) {
p := new(RoomNoticeIsTaskFinishReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RoomNoticeSvc.IsTaskFinish(c, p)
c.JSON(resp, err)
}
func roomNoticeSetTaskFinish(c *bm.Context) {
p := new(RoomNoticeSetTaskFinishReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RoomNoticeSvc.SetTaskFinish(c, p)
c.JSON(resp, err)
}
// RegisterRoomNoticeBMServer Register the blademaster route
func RegisterRoomNoticeBMServer(e *bm.Engine, server RoomNoticeBMServer) {
v1RoomNoticeSvc = server
e.GET("/live.xuserex.v1.RoomNotice/buy_guard", roomNoticeBuyGuard)
e.GET("/live.xuserex.v1.RoomNotice/is_task_finish", roomNoticeIsTaskFinish)
e.GET("/live.xuserex.v1.RoomNotice/set_task_finish", roomNoticeSetTaskFinish)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
syntax = "proto3";
package live.xuserex.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// 房间提示 相关服务
service RoomNotice {
// 是否弹出大航海购买提示
rpc buy_guard (RoomNoticeBuyGuardReq) returns (RoomNoticeBuyGuardResp);
// habse 任务是否结束
rpc is_task_finish (RoomNoticeIsTaskFinishReq) returns (RoomNoticeIsTaskFinishResp);
// 手动设置base 任务结束
rpc set_task_finish (RoomNoticeSetTaskFinishReq) returns (RoomNoticeSetTaskFinishResp);
}
message RoomNoticeBuyGuardReq {
// UID
int64 uid = 1 [(gogoproto.moretags) = 'form:"uid" validate:"required"'];
// 主播UID
int64 target_id = 2 [(gogoproto.moretags) = 'form:"target_id" validate:"required"'];
}
message RoomNoticeIsTaskFinishReq {
}
message RoomNoticeSetTaskFinishReq {
// 是否完成
int64 result = 1 [(gogoproto.moretags) = 'form:"result"'];
}
message RoomNoticeBuyGuardResp {
// 是否提示 1:弹出提示,0:不弹出
int64 should_notice = 1;
// 状态有效开始时间
int64 begin = 2;
// 状态有效结束时间
int64 end = 3;
// 当前的时间戳
int64 now = 7;
// 标题
string title = 4;
// 内容
string content = 5;
// 按钮
string button = 6;
}
message RoomNoticeIsTaskFinishResp {
// 是否完成
int64 result = 1;
}
message RoomNoticeSetTaskFinishResp {
// 是否完成
int64 result = 1;
}

View File

@@ -0,0 +1,89 @@
<!-- package=live.xuserex.v1 -->
- [/live.xuserex.v1.RoomNotice/buy_guard](#live.xuserex.v1.RoomNoticebuy_guard) 是否弹出大航海购买提示
- [/live.xuserex.v1.RoomNotice/is_task_finish](#live.xuserex.v1.RoomNoticeis_task_finish) habse 任务是否结束
- [/live.xuserex.v1.RoomNotice/set_task_finish](#live.xuserex.v1.RoomNoticeset_task_finish) 手动设置base 任务结束
## /live.xuserex.v1.RoomNotice/buy_guard
### 是否弹出大航海购买提示
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|uid|是|integer| UID|
|target_id|是|integer| 主播UID|
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
// 是否提示 1:弹出提示,0:不弹出
"should_notice": 0,
// 状态有效开始时间
"begin": 0,
// 状态有效结束时间
"end": 0,
// 当前的时间戳
"now": 0,
// 标题
"title": "",
// 内容
"content": "",
// 按钮
"button": ""
}
}
```
## /live.xuserex.v1.RoomNotice/is_task_finish
### habse 任务是否结束
#### 方法GET
#### 请求参数
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
// 是否完成
"result": 0
}
}
```
## /live.xuserex.v1.RoomNotice/set_task_finish
### 手动设置base 任务结束
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|result|否|integer| 是否完成|
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
// 是否完成
"result": 0
}
}
```

View File

@@ -0,0 +1 @@
# HTTP API文档

View File

@@ -0,0 +1,49 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["test.toml"],
importpath = "go-common/app/service/live/xuserex/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/resource/sdk:go_default_library",
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/server/grpc:go_default_library",
"//app/service/live/xuserex/server/http:go_default_library",
"//app/service/live/xuserex/service:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/trace:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/xuserex/cmd/client:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,40 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "client",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "go-common/app/service/live/xuserex/cmd/client",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/time: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,41 @@
package main
import (
"context"
"flag"
"go-common/app/service/live/xuserex/api/grpc/v1"
"log"
"time"
"fmt"
"go-common/library/net/rpc/warden"
xtime "go-common/library/time"
)
var name, addr string
func init() {
flag.StringVar(&name, "name", "lily", "name")
flag.StringVar(&addr, "addr", "127.0.0.1:9004", "server addr")
}
func main() {
flag.Parse()
cfg := &warden.ClientConfig{
Dial: xtime.Duration(time.Second * 3),
Timeout: xtime.Duration(time.Second * 3),
}
cc, err := warden.NewClient(cfg).Dial(context.Background(), addr)
if err != nil {
log.Fatalf("new client failed!err:=%v", err)
return
}
client := v1.NewRoomNoticeClient(cc)
resp, err := client.BuyGuard(context.Background(), &v1.RoomNoticeBuyGuardReq{
Uid: 10000,
TargetId: 11,
})
fmt.Printf("****** buyguard :******* \n %v \n %v \n", resp, err)
}

View File

@@ -0,0 +1,58 @@
package main
import (
"context"
"flag"
"fmt"
"go-common/app/service/live/xuserex/server/http"
"go-common/app/service/live/xuserex/service"
"os"
"os/signal"
"syscall"
"go-common/app/service/live/resource/sdk"
"go-common/app/service/live/xuserex/conf"
"go-common/app/service/live/xuserex/server/grpc"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
log.Info("[xuserex] start")
trace.Init(conf.Conf.Tracer)
defer trace.Close()
ecode.Init(conf.Conf.Ecode)
http.Init(conf.Conf)
svc := service.New(conf.Conf)
svr, err := grpc.New(svc)
if err != nil {
panic(fmt.Sprintf("start xuser grpc server fail! %s", err))
}
titansSdk.Init(conf.Conf.Titan)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
svc.Close()
if svr != nil {
svr.Shutdown(context.Background())
}
log.Info("[xuserex] exit")
return
case syscall.SIGHUP:
default:
return
}
}
}

View File

@@ -0,0 +1,43 @@
[log]
stdout = true
[titan]
treeId = 82470
[memcache]
name = "xuserex-memcache"
proto = "tcp"
addr = "127.0.0.1:11211"
active = 50
idle = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "24h"
[hbase]
master = ""
meta = ""
dialTimeout = "1s"
readTimeout = "150ms"
readsTimeout = "600ms"
writeTimeout = "200ms"
writesTimeout = "600ms"
[hbase.zookeeper]
root = ""
addrs = ["172.18.33.163:2181","172.18.33.164:2181","172.18.33.165:2181"]
timeout = "30s"
[bmClient]
key = "837f620f5c0a8010"
secret = "2a9057021014b4b843b635664c69d5df"
dial = "500ms"
timeout = "1s"
keepAlive = "60s"
[httpClient.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100

View File

@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["conf.go"],
importpath = "go-common/app/service/live/xuserex/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/resource/sdk:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/conf:go_default_library",
"//library/database/hbase.v2:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/net/trace:go_default_library",
"//vendor/github.com/BurntSushi/toml: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,91 @@
package conf
import (
"errors"
"flag"
"go-common/app/service/live/resource/sdk"
"go-common/library/cache/memcache"
"go-common/library/conf"
"go-common/library/database/hbase.v2"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
"go-common/library/net/trace"
"github.com/BurntSushi/toml"
"go-common/library/net/rpc/warden"
)
var (
confPath string
client *conf.Client
// Conf config
Conf = &Config{}
)
// Config .
type Config struct {
Log *log.Config
BM *bm.ServerConfig
Verify *verify.Config
Tracer *trace.Config
Memcache *memcache.Config
Ecode *ecode.Config
Titan *titansSdk.Config
BMClient *bm.ClientConfig
HBase *hbase.Config
Warden *warden.ClientConfig
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init init conf
func Init() error {
if confPath != "" {
return local()
}
return remote()
}
func local() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}

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"],
importpath = "go-common/app/service/live/xuserex/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//library/cache/memcache:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/xuserex/dao/notice:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,33 @@
package dao
import (
"context"
"go-common/app/service/live/xuserex/conf"
"go-common/library/cache/memcache"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
}
return
}
// Close close the resource.
func (d *Dao) Close() {
d.mc.Close()
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) error {
return nil
}

View File

@@ -0,0 +1,62 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.cache.go",
"mc.cache.go",
"roomNotice.go",
],
importpath = "go-common/app/service/live/xuserex/dao/notice",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/resource/sdk:go_default_library",
"//app/service/live/xuser/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/model/roomNotice:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/hbase.v2:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/stat/prom: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 = [
"dao.cache_test.go",
"mc.cache_test.go",
"roomNotice_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/model/roomNotice:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,57 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package roomNotice is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -sync=true -nullcache=&roomNotice.MonthConsume{Amount:-1} -check_null_code=$.Amount==-1
MonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
}
*/
package notice
import (
"context"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _cache
// MonthConsume get data from cache if miss will call source method, then add to cache.
func (d *Dao) MonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
addCache := true
res, err = d.CacheMonthConsume(c, id, targetID, date)
if err != nil {
addCache = false
err = nil
}
defer func() {
if nil != res && res.Amount == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("MonthConsume")
return
}
prom.CacheMiss.Incr("MonthConsume")
res, err = d.RawMonthConsume(c, id, targetID, date)
log.Info("MonthConsume_RawMonthConsume uid (%v) targetId (%v) date (%v) res (%+v)", id, targetID, date, res)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &roomNotice.MonthConsume{Amount: -1}
}
if !addCache {
return
}
d.AddCacheMonthConsume(c, id, targetID, date, miss)
return
}

View File

@@ -0,0 +1,26 @@
package notice
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestRoomNoticeMonthConsume(t *testing.T) {
convey.Convey("MonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.MonthConsume(c, id, targetID, date)
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)
})
})
})
}

View File

@@ -0,0 +1,67 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package roomNotice is a generated mc cache package.
It is generated from:
type _mc interface {
// 获取某个月消费
// mc: -key=keyShouldNotice
CacheMonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
// 保存获取某个月消费
// mc: -key=keyShouldNotice -expire=d.keyShouldNoticeExpire -encode=json|gzip
AddCacheMonthConsume(c context.Context, UID int64, targetID int64, date string, value *roomNotice.MonthConsume) error
}
*/
package notice
import (
"context"
"fmt"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// CacheMonthConsume 获取某个月消费
func (d *Dao) CacheMonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyShouldNotice(id, targetID, date)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &roomNotice.MonthConsume{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheMonthConsume 保存获取某个月消费
func (d *Dao) AddCacheMonthConsume(c context.Context, id int64, targetID int64, date string, value *roomNotice.MonthConsume) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyShouldNotice(id, targetID, date)
item := &memcache.Item{Key: key, Object: value, Expiration: keyShouldNoticeExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheMonthConsume")
log.Errorv(c, log.KV("AddCacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}

View File

@@ -0,0 +1,52 @@
package notice
import (
"context"
"go-common/app/service/live/xuserex/model/roomNotice"
"testing"
"github.com/smartystreets/goconvey/convey"
)
// TestRoomNoticeAddCacheMonthConsume test.
func TestRoomNoticeAddCacheMonthConsume(t *testing.T) {
convey.Convey("AddCacheMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
value = &roomNotice.MonthConsume{
Uid: id,
Ruid: targetID,
Amount: 10,
Date: -1,
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.AddCacheMonthConsume(c, id, targetID, date, value)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
// TestRoomNoticeCacheMonthConsume auto test.
func TestRoomNoticeCacheMonthConsume(t *testing.T) {
convey.Convey("CacheMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.CacheMonthConsume(c, id, targetID, date)
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)
})
})
})
}

View File

@@ -0,0 +1,345 @@
package notice
import (
"context"
"go-common/app/service/live/xuser/api/grpc/v1"
v1pb "go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/app/service/live/xuserex/conf"
"go-common/library/cache/memcache"
"bytes"
"encoding/json"
"fmt"
"go-common/app/service/live/resource/sdk"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/database/hbase.v2"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/stat/prom"
"strconv"
"time"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
// acc rpc
client *bm.Client
hbase *hbase.Client
xuser *v1.Client
}
type guardGuideConf struct {
Open int64 `json:"open"`
Threshold int64 `json:"threshold"`
}
const (
// 缓存过期时间
keyShouldNoticeExpire = 3600
keyNoticePre = "kn_v1_%d_%d_%s"
// HBaseMonthlyConsumeTable .
HBaseMonthlyConsumeTable = "livemonthconsume"
// BuyGuardGuideTitanKey .
BuyGuardGuideTitanKey = "buy_guard_guide"
// TaskFinishKey .
TaskFinishKey = "task_finish_%s"
)
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
client: bm.NewClient(c.BMClient),
hbase: hbase.NewClient(c.HBase),
}
conn, err := v1.NewClient(c.Warden)
if err != nil {
panic(err)
}
dao.xuser = conn
return
}
func keyShouldNotice(UID int64, targetID int64, date string) string {
return fmt.Sprintf(keyNoticePre, UID, targetID, date)
}
// IsNotice returns whether should pop a purchase notice.
func (dao *Dao) IsNotice(c context.Context, UID int64, targetID int64) (*v1pb.RoomNoticeBuyGuardResp, error) {
term := dao.GetTermBegin()
begin := term.Unix()
end := dao.GetTermEnd()
resp := &v1pb.RoomNoticeBuyGuardResp{
Begin: begin,
End: end.Unix(),
Now: time.Now().Unix(),
Title: "感谢支持主播",
Content: "成为船员为主播保驾护航吧~",
Button: "开通大航海",
}
shouldNotice, err := dao.getShouldNotice(c, UID, targetID, term)
if err != nil {
log.Error("dao getShouldNotice uid(%v)roomid(%v)term(%v) error(%v)", UID, targetID, term.Format("2006-01-02"), err)
err = nil
return resp, err
}
resp.ShouldNotice = int64(shouldNotice)
return resp, nil
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -sync=true -nullcache=&roomNotice.MonthConsume{Amount:-1} -check_null_code=$.Amount==-1
MonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
// 获取某个月消费
// mc: -key=keyShouldNotice
CacheMonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
// 保存获取某个月消费
// mc: -key=keyShouldNotice -expire=d.keyShouldNoticeExpire -encode=json|gzip
AddCacheMonthConsume(c context.Context, UID int64, targetID int64, date string, value *roomNotice.MonthConsume) error
}
func (dao *Dao) getThreshold() (threshold *guardGuideConf, err error) {
threshold = &guardGuideConf{}
guideConf, err := titansSdk.Get(BuyGuardGuideTitanKey)
log.Info("getThreshold_key(%v) conf(%+v)", BuyGuardGuideTitanKey, guideConf)
if err != nil {
log.Error("getThreshold(%v) error(%v)", BuyGuardGuideTitanKey, err)
return
}
if "" == guideConf {
return
}
if err = json.Unmarshal([]byte(guideConf), threshold); err != nil {
log.Error("json Unmarshal guideconf(%+v) error(%v)", guideConf, err)
return
}
log.Info("getThreshold_unmarshal_succ key(%v) conf (%v) Threshold(%+v)", BuyGuardGuideTitanKey, guideConf, threshold)
return
}
func (dao *Dao) getShouldNotice(ctx context.Context, UID int64, targetID int64, term time.Time) (shouldNotice int, err error) {
shouldNotice = 0
taskFinish, err := dao.GetTaskFinish(ctx, term)
if err != nil {
return shouldNotice, err
}
if !taskFinish {
log.Info("task_not_finish")
return shouldNotice, err
}
// 获取配置的收入门槛
threshold, err := dao.getThreshold()
if err != nil {
log.Error("get_threshold_error(%v)", err)
return
}
if nil == threshold {
log.Error("get_threshold_nil")
return
}
if 0 == threshold.Open {
log.Info("guard_guide not Open (%+v)", threshold)
return
}
monthConsume, err := dao.MonthConsume(ctx, UID, targetID, dao.termToString(term))
log.Info("get_monthConsume(%+v) Threshold (%+v)", monthConsume, threshold)
if err != nil {
log.Error("get_monthConsum_err uid(%d) targetid(%v) term (%v) error(%v)", UID, targetID, term, err)
return
}
if nil == monthConsume {
return
}
if int64(monthConsume.Amount) >= threshold.Threshold*1000 { // coin to rmb
isGuard, err := dao.isGuard(ctx, UID, targetID)
log.Info("show guard guide uid(%v) target (%v) guard (%v) Threshold (%v)", UID, targetID, isGuard, threshold)
if err != nil {
log.Error("get gaurd UID(%v) targetid (%v) error(%v)", UID, targetID, err)
return shouldNotice, err
}
if !isGuard {
shouldNotice = 1
}
}
return
}
func hbaseRowKey(UID int64, targetID int64, date string) string {
return fmt.Sprintf("%s_%d_%d", date, UID, targetID)
}
//RawMonthConsume get month consume from hbase
func (dao *Dao) RawMonthConsume(ctx context.Context, UID int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
var (
tableName = HBaseMonthlyConsumeTable
key = hbaseRowKey(UID, targetID, date)
)
result, err := dao.hbase.GetStr(ctx, tableName, key)
log.Info("RawMonthConsume_getstr tableName (%v) key (%v) res (%v)", tableName, key, result)
if err != nil {
log.Error("dao.hbase.GetStr tableName(%s)|mid(%d)|key(%v)|error(%v)", tableName, UID, key, err)
err = ecode.CreativeDataErr
return
}
if result == nil {
return
}
res = &roomNotice.MonthConsume{}
for _, c := range result.Cells {
if c == nil {
continue
}
v, _ := strconv.ParseInt(string(c.Value[:]), 10, 64)
if !bytes.Equal(c.Family, []byte("info")) {
log.Error("family_type_err(%v) error", c.Family)
continue
}
switch {
case bytes.Equal(c.Qualifier, []byte("uid")):
res.Uid = v
case bytes.Equal(c.Qualifier, []byte("ruid")):
res.Ruid = v
case bytes.Equal(c.Qualifier, []byte("amount")):
res.Amount = v
case bytes.Equal(c.Qualifier, []byte("time")):
res.Date = v
}
}
log.Info("RawMonthConsume_succ uid (%v) target (%v) date (%v) res (%+v)", UID, targetID, date, res)
return
}
// GetTermBegin return first day of last month
func (dao *Dao) GetTermBegin() time.Time {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
return thisMonth.AddDate(0, -1, 0)
}
// GetTermEnd returns last second of last month
func (dao *Dao) GetTermEnd() time.Time {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
second, _ := time.ParseDuration("-1s")
return thisMonth.Add(second)
}
// IsValidTerm returns whether a term is valid.
func (dao *Dao) IsValidTerm(term time.Time) bool {
return true
}
// TOOD
func (dao *Dao) isGuard(c context.Context, UID int64, targetID int64) (isGuard bool, err error) {
ret, err := dao.xuser.GetByUIDTargetID(c, &v1.GetByUidTargetIdReq{
Uid: UID,
TargetId: targetID,
})
log.Info("dao.xuser.GetByUIDTargetID uid (%v) target (%v) res (%v)", UID, targetID, ret)
if err != nil {
log.Error("get guard uid (%v) target (%v) error(%v)", UID, targetID, err)
return
}
if nil == ret || nil == ret.Data || 0 == len(ret.Data) {
log.Info("not_guard uid (%v) target (%v) res (%v)", UID, targetID, ret)
return
}
isGuard = true
return
}
// GetTaskFinish .
func (dao *Dao) GetTaskFinish(c context.Context, term time.Time) (isOn bool, err error) {
conn := dao.mc.Get(c)
defer conn.Close()
key := dao.keyTaskFinish(term)
reply, err := conn.Get(key)
log.Info("GetTaskFinish key (%v) term (%v)", key, term)
if err != nil {
if err == memcache.ErrNotFound {
log.Info("GetTaskFinish_not_found key (%v) term (%v)", key, term)
err = nil
return
}
prom.BusinessErrCount.Incr("mc:GetTaskFinish")
log.Error("GetTaskFinish_fail key(%v) error(%v)", key, err)
return
}
res := &roomNotice.TaskFinish{}
err = conn.Scan(reply, &res)
if err != nil {
prom.BusinessErrCount.Incr("mc:GetTaskFinish")
log.Error("GetTaskFinish_fail_scan key(%v) error(%v)", key, err)
return
}
log.Info("GetTaskFinish_succ key (%v) term (%v) res(%+v)", key, term, res)
if res == nil {
return
}
if 1 == res.Finish {
isOn = true
}
return
}
// SetTaskFinish .
func (dao *Dao) SetTaskFinish(c context.Context, term time.Time, isFinish int64) (err error) {
conn := dao.mc.Get(c)
defer conn.Close()
key := dao.keyTaskFinish(term)
value := &roomNotice.TaskFinish{
Finish: isFinish,
}
log.Info("SetTaskFinish key (%v) term (%v) value (%+v)", key, term, value)
item := &memcache.Item{
Key: key,
Object: value,
Flags: memcache.FlagJSON,
Expiration: 0,
}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:SetTaskFinish")
log.Error("SetTaskFinish_fail key(%v) value (%+v) error(%v)", key, value, err)
return
}
log.Info("SetTaskFinish_succ key (%v) term (%v) value (%+v)", key, term, value)
return
}
func (dao *Dao) termToString(term time.Time) string {
return term.Format("20060102")
}
func (dao *Dao) keyTaskFinish(term time.Time) (key string) {
return fmt.Sprintf(TaskFinishKey, dao.termToString(term))
}

View File

@@ -0,0 +1,195 @@
package notice
import (
"context"
"go-common/app/service/live/xuserex/conf"
"testing"
"time"
"flag"
"github.com/smartystreets/goconvey/convey"
"os"
)
var (
d *Dao
UID = int64(10000)
targetID = int64(10000)
date = "20190101"
term = time.Now()
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "live.live.xuserex")
flag.Set("conf_token", "4e6ace268a9ee6d04fad131ad551f61e")
flag.Set("tree_id", "82470")
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/test.toml")
flag.Set("deploy.env", "uat")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestRoomNoticeNew(t *testing.T) {
convey.Convey("New", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
ctx.Convey("Then dao should not be nil.", func(ctx convey.C) {
ctx.So(d, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticekeyShouldNotice(t *testing.T) {
convey.Convey("keyShouldNotice", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyShouldNotice(UID, targetID, date)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeIsNotice(t *testing.T) {
convey.Convey("IsNotice", t, func(ctx convey.C) {
convey.Convey("When everything goes positive", func(ctx convey.C) {
c := context.TODO()
p1, err := d.IsNotice(c, UID, targetID)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticegetThreshold(t *testing.T) {
convey.Convey("getThreshold", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
threshold, err := d.getThreshold()
ctx.Convey("Then err should be nil.threshold should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(threshold, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticegetShouldNotice(t *testing.T) {
convey.Convey("getShouldNotice", t, func() {
var (
ctx = context.Background()
)
convey.Convey("When everything goes positive", func() {
shouldNotice, err := d.getShouldNotice(ctx, UID, targetID, term)
convey.Convey("Then err should be nil.shouldNotice should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(shouldNotice, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticehbaseRowKey(t *testing.T) {
convey.Convey("hbaseRowKey", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := hbaseRowKey(UID, targetID, date)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeRawMonthConsume(t *testing.T) {
convey.Convey("RawMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RawMonthConsume(c, UID, targetID, date)
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 TestRoomNoticeGetTermBegin(t *testing.T) {
convey.Convey("GetTermBegin", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.GetTermBegin()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeGetTermEnd(t *testing.T) {
convey.Convey("GetTermEnd", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.GetTermEnd()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeIsValidTerm(t *testing.T) {
convey.Convey("IsValidTerm", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.IsValidTerm(term)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeisGuard(t *testing.T) {
convey.Convey("isGuard", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
isGuard, err := d.isGuard(c, UID, targetID)
ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(isGuard, convey.ShouldNotBeNil)
})
})
})
}
func TestGetTaskFinish(t *testing.T) {
convey.Convey("GetTaskFinish", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
term := d.GetTermBegin()
isFinish, err := d.GetTaskFinish(c, term)
ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(isFinish, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,31 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["model.go"],
importpath = "go-common/app/service/live/xuserex/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/xuserex/model/roomNotice:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1 @@
package model

View File

@@ -0,0 +1,28 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["model.go"],
importpath = "go-common/app/service/live/xuserex/model/roomNotice",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
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,14 @@
package roomNotice
// MonthConsume .
type MonthConsume struct {
Uid int64
Ruid int64
Amount int64
Date int64
}
// TaskFinish .
type TaskFinish struct {
Finish int64
}

View File

@@ -0,0 +1,33 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["server.go"],
importpath = "go-common/app/service/live/xuserex/server/grpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/service:go_default_library",
"//library/net/rpc/warden: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,19 @@
package grpc
import (
v1pb "go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/app/service/live/xuserex/service"
"go-common/library/net/rpc/warden"
)
// New new grpc server
func New(svc *service.Service) (wsvr *warden.Server, err error) {
wsvr = warden.NewServer(nil)
v1pb.RegisterRoomNoticeServer(wsvr.Server(), svc.RoomNoticeV1Svc())
if wsvr, err = wsvr.Start(); err != nil {
return
}
return
}

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 = ["http.go"],
importpath = "go-common/app/service/live/xuserex/server/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/service:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify: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,53 @@
package http
import (
"net/http"
"go-common/app/service/live/xuserex/conf"
"go-common/app/service/live/xuserex/service"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
)
var (
srv *service.Service
vfy *verify.Verify
)
// Init init
func Init(c *conf.Config) {
srv = service.New(c)
vfy = verify.New(c.Verify)
engine := bm.DefaultServer(c.BM)
route(engine)
if err := engine.Start(); err != nil {
log.Error("bm Start error(%v)", err)
panic(err)
}
}
func route(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
g := e.Group("/x/xuserex")
{
g.GET("/start", vfy.Verify, howToStart)
}
}
func ping(c *bm.Context) {
if err := srv.Ping(c); err != nil {
log.Error("ping error(%v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}
func register(c *bm.Context) {
c.JSON(map[string]interface{}{}, nil)
}
// example for http request handler
func howToStart(c *bm.Context) {
c.String(0, "Golang 大法好 !!!")
}

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 = ["service.go"],
importpath = "go-common/app/service/live/xuserex/service",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/service/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/xuserex/service/v1:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,38 @@
package service
import (
"context"
"go-common/app/service/live/xuserex/service/v1"
"go-common/app/service/live/xuserex/conf"
)
// Service struct
type Service struct {
c *conf.Config
roomNotivev1svc *v1.RoomNoticeService
}
// New init
func New(c *conf.Config) (s *Service) {
// init vip.v1 service
s = &Service{
c: c,
roomNotivev1svc: v1.NewRoomNoticeService(conf.Conf),
}
return s
}
// RoomNoticeV1Svc return roomadmin v1 service
func (s *Service) RoomNoticeV1Svc() *v1.RoomNoticeService {
return s.roomNotivev1svc
}
// Ping Service
func (s *Service) Ping(ctx context.Context) (err error) {
return nil
}
// Close Service
func (s *Service) Close() {
}

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 = ["roomNotice.go"],
importpath = "go-common/app/service/live/xuserex/service/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/dao/notice:go_default_library",
"//library/ecode:go_default_library",
"//library/log: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,76 @@
package v1
import (
"context"
v1pb "go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/app/service/live/xuserex/conf"
"go-common/app/service/live/xuserex/dao/notice"
"go-common/library/ecode"
"go-common/library/log"
)
// RoomNoticeService struct
type RoomNoticeService struct {
conf *conf.Config
// optionally add other properties here, such as dao
dao *notice.Dao
}
//NewRoomNoticeService init
func NewRoomNoticeService(c *conf.Config) (s *RoomNoticeService) {
s = &RoomNoticeService{
conf: c,
dao: notice.New(c),
}
return s
}
// 房间提示 相关服务
// BuyGuard implementation
// 是否弹出大航海购买提示
func (s *RoomNoticeService) BuyGuard(ctx context.Context, req *v1pb.RoomNoticeBuyGuardReq) (resp *v1pb.RoomNoticeBuyGuardResp, err error) {
resp = &v1pb.RoomNoticeBuyGuardResp{}
UID := req.GetUid()
targetID := req.GetTargetId()
if UID <= 0 || targetID <= 0 {
err = ecode.NoLogin
return resp, err
}
resp, err = s.dao.IsNotice(ctx, UID, targetID)
return
}
// IsTaskFinish implementation
// habse 任务是否结束
func (s *RoomNoticeService) IsTaskFinish(ctx context.Context, req *v1pb.RoomNoticeIsTaskFinishReq) (resp *v1pb.RoomNoticeIsTaskFinishResp, err error) {
resp = &v1pb.RoomNoticeIsTaskFinishResp{}
ret, err := s.dao.GetTaskFinish(ctx, s.dao.GetTermBegin())
if err != nil {
log.Error("s.dao.GetTaskFinish(%v) error(%v)", s.dao.GetTermBegin(), err)
return
}
if ret {
resp.Result = 1
}
return
}
// SetTaskFinish implementation
// 手动设置base 任务结束
func (s *RoomNoticeService) SetTaskFinish(ctx context.Context, req *v1pb.RoomNoticeSetTaskFinishReq) (resp *v1pb.RoomNoticeSetTaskFinishResp, err error) {
resp = &v1pb.RoomNoticeSetTaskFinishResp{}
isFinish := req.GetResult()
log.Info("SetTaskFinish finish (%v) term (%v)", isFinish, s.dao.GetTermBegin())
err = s.dao.SetTaskFinish(ctx, s.dao.GetTermBegin(), isFinish)
if err != nil {
log.Error("SetTaskFinish(%v) term (%v) error(%v)", isFinish, s.dao.GetTermBegin(), err)
return
}
resp.Result = 1
return
}