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

25
app/service/main/up/BUILD Normal file
View File

@@ -0,0 +1,25 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/main/up/api/gorpc:all-srcs",
"//app/service/main/up/api/v1:all-srcs",
"//app/service/main/up/cmd:all-srcs",
"//app/service/main/up/conf:all-srcs",
"//app/service/main/up/dao:all-srcs",
"//app/service/main/up/model:all-srcs",
"//app/service/main/up/server/gorpc:all-srcs",
"//app/service/main/up/server/grpc:all-srcs",
"//app/service/main/up/server/http:all-srcs",
"//app/service/main/up/service:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,189 @@
#### 创作中心up主身份服务
# v1.11.11
> 1.批量增加查询active tid的接口
# v1.11.10
> 1.loadSpGroupsMids load append not flush
# v1.11.9
> 1.调整group相关接口
# v1.11.8
> 1.高能联盟 grpc服务
# v1.11.7
> 1.切gorpc to grpc服务
# v1.11.6
> 1.调整分组信息列表为map
# v1.11.5
> 1.添加特殊用户up主的grpc接口
# v1.11.4
> 1.添加up主活跃度的列表grpc接口
# v1.11.3
> 1.change account gorpc to grpc
# v1.11.2
> 1.增加查询active tid的接口
# v1.11.1
> 1.修改speical add为异步逻辑
# v1.11.0
> 1.up主列表相关 + 联合投稿staff
# v1.10.1
> 1.特殊用户组接口修改错误信息
# v1.10.0
> 1.up主列表相关
##### Version 1.9.0
> 1.修改up列表API-查询参数增加活跃度字段
##### Version 1.8.9
> 1.修改人物卡片查询API: up图片和视频按id倒序排序
##### Version 1.8.8
> 1.增加api接口
##### Version 1.8.7
> 1.播放器开关如果没有找到Up主配置现在默认为开
##### Version 1.8.6
> 1.增加API: 按 mid 列表查询人物卡片信息
##### Version 1.8.5
> 1.增加获取所有up主mid的服务
##### Version 1.8.4
> 1.增加人物卡片API
##### Version 1.8.3
> 1.fix error log
##### Version 1.8.2
> 1.修复更新成功触发删除缓存
##### Version 1.8.1
> 1.修复ut
##### Version 1.8.0
> 1.增加up主开关功能
##### Version 1.7.10
> 1.增加数据库中不存在时的缓存
##### Version 1.7.9
> 1.修改hbase为hbasev2
##### Version 1.7.8
> 1.更换remoteIP调用
##### Version 1.7.7
> 1.修复没权限返回数据错误的问题
> 2.去掉一处打印过多的日志
##### Version 1.7.6
> 1.修复服务器重启时时DataScheduler导致crash的问题
> 2.增加签约用户访问权限
##### Version 1.7.5
> 1.修复服务器重启时会crash的问题
##### Version 1.7.4
> 1.修复validate tag
##### Version 1.7.3
> 1.替换net/http/parse
##### Version 1.7.2
> 1.重新合入master基础库
##### Version 1.7.1
> 1.增加获取up主特殊用户组时的颜色标签
##### Version 1.7.0
> 1.优化databus消费使用队列分发策略并行分发且保证顺序消费
##### Version 1.6.4
> 1.add register
##### Version 1.6.3
> 1.修复proto编译问题
##### Version 1.6.2
> 1.增加用户统计数据接口
##### Version 1.6.1
> 1.调整逻辑重复Add变为Edit
##### Version 1.6.0
> 1.迁移admin上up special相关接口1.5.4继承过来)
> 2.增加权限点
##### Version 1.5.4
> 1.迁移admin上up special相关接口
##### Version 1.5.3
> 1.修复getToken导致高CPU占用的问题
##### Version 1.5.2
> 1.更新protobuf的目录结构
##### Version 1.5.1
> 1.增加RPC服务注册目录为/microservice/up-service/
> 2.增加Info与Special的RPC接口
##### Version 1.5.0
> 1.直播接入
##### Version 1.4.8
> 1.迁移到main目录
##### Version 1.4.7
> 1.fix up nil
##### Version 1.4.6
> 1.解耦异步db更新的频率和routine数量
> 2.确保异步处理databus消息的顺序一致性
##### Version 1.4.5
> 1.迁移videoup-service上的up/special接口到up-service
##### Version 1.4.4
> 1.不消费报警可配置
##### Version 1.4.3
> 1.五分钟不消费报警
##### Version 1.4.2
> 1.消费databus异步更新db
##### Version 1.4.1
> 1.去除statsd
##### Version 1.4.0
> 1.对外接口加个缓存
### Version 1.3.1
> 1.修改up-service接口uri
##### Version 1.3.0
> 1.支持移动端投稿身份校验
##### Version 1.2.1
> 1.fix databus consume msg type
##### Version 1.2.0
> 1.接入bm
##### Version 1.1.0
> 1.去除identity和ecode
##### Version 1.0.0
> 1.稿件up主接入

View File

@@ -0,0 +1,17 @@
# Owner
shencen
wangzhe01
# Author
haoguanwei
wangzhe01
shencen
hejianbing
limengqing
liyixin
yanjinbin
# Reviewer
haoguanwei
shencen
wangzhe01

View File

@@ -0,0 +1,21 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- haoguanwei
- hejianbing
- shencen
- wangzhe01
labels:
- main
- service
- service/main/up
options:
no_parent_owners: true
reviewers:
- haoguanwei
- hejianbing
- limengqing
- liyixin
- shencen
- wangzhe01
- yanjinbin

View File

@@ -0,0 +1,10 @@
#### up-service
##### 项目简介
> 1.up身份服务
##### 编译环境
> 请只用golang v1.8.x以上版本编译执行。
##### 依赖包
> 1.公共包go-common

View File

@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["up_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = ["//app/service/main/up/model:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["up.go"],
importpath = "go-common/app/service/main/up/api/gorpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/model:go_default_library",
"//library/net/rpc: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,78 @@
package client
import (
"context"
"go-common/app/service/main/up/model"
"go-common/library/net/rpc"
)
const (
_Special = "RPC.Special"
_Info = "RPC.Info"
_UpStatBase = "RPC.UpStatBase"
_SetUpSwitch = "RPC.SetUpSwitch"
_UpSwitch = "RPC.UpSwitch"
)
const (
_appid = "archive.service.up"
)
var (
// _noRes = &struct{}{}
)
// Service rpc client
type Service struct {
client *rpc.Client2
}
// RPC rpc
type RPC interface {
// DEPRECATED: Please use gRPC service of func UpGroupMids instead, but must get datas in many times by one time of max 1000.
Special(c context.Context, arg *model.ArgSpecial) (res []*model.UpSpecial, err error)
// DEPRECATED: Please use gRPC service of func UpAttr instead.
Info(c context.Context, arg *model.ArgInfo) (res *model.UpInfo, err error)
}
// New create
func New(c *rpc.ClientConfig) (s *Service) {
s = &Service{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
// Special special
// DEPRECATED: Please use gRPC service of func UpGroupMids instead, but must get datas in many times by one time of max 1000.
func (s *Service) Special(c context.Context, arg *model.ArgSpecial) (res []*model.UpSpecial, err error) {
err = s.client.Call(c, _Special, arg, &res)
return
}
// Info info
// DEPRECATED: Please use gRPC service of func UpAttr instead.
func (s *Service) Info(c context.Context, arg *model.ArgInfo) (res *model.UpInfo, err error) {
err = s.client.Call(c, _Info, arg, &res)
return
}
// UpStatBase base statis
// DEPRECATED: Please use gRPC service func UpBaseStats instead.
func (s *Service) UpStatBase(c context.Context, arg *model.ArgMidWithDate) (res *model.UpBaseStat, err error) {
err = s.client.Call(c, _UpStatBase, arg, &res)
return
}
// SetUpSwitch set up switch
// DEPRECATED: Please use gRPC service func SetUpSwitch instead.
func (s *Service) SetUpSwitch(c context.Context, arg *model.ArgUpSwitch) (res *model.PBSetUpSwitchRes, err error) {
err = s.client.Call(c, _SetUpSwitch, arg, &res)
return
}
// UpSwitch get up switch
// DEPRECATED: Please use gRPC service func UpSwitch instead.
func (s *Service) UpSwitch(c context.Context, arg *model.ArgUpSwitch) (res *model.PBUpSwitch, err error) {
err = s.client.Call(c, _UpSwitch, arg, &res)
return
}

View File

@@ -0,0 +1,48 @@
package client
import (
"context"
"testing"
"time"
"go-common/app/service/main/up/model"
)
func TestRpcClient(t *testing.T) {
s := New(nil)
time.Sleep(1 * time.Second)
testInfo(t, s)
testSpecial(t, s)
testUpStatBase(t, s)
testUpSwitch(t, s)
}
func testInfo(t *testing.T, s *Service) {
arg := model.ArgInfo{
Mid: 2089809,
From: 1,
}
t.Log(s.Info(context.TODO(), &arg))
}
func testSpecial(t *testing.T, s *Service) {
arg := model.ArgSpecial{
GroupID: 1,
}
t.Log(s.Special(context.TODO(), &arg))
}
func testUpStatBase(t *testing.T, s *Service) {
arg := model.ArgMidWithDate{
Mid: 12345,
}
t.Log(s.UpStatBase(context.TODO(), &arg))
}
func testUpSwitch(t *testing.T, s *Service) {
arg := model.ArgUpSwitch{
Mid: 1,
From: 0,
}
t.Log(s.UpSwitch(context.TODO(), &arg))
}

View File

@@ -0,0 +1,83 @@
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 = [
"api.proto",
"archive.proto",
"reply.proto",
"request.proto",
"sign_up.proto",
"up.proto",
],
tags = ["automanaged"],
deps = [
"//app/service/main/archive/api:api_proto",
"@go_googleapis//google/api:annotations_proto",
"@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/main/up/api/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = [
"//app/service/main/archive/api:api_go_proto",
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
],
)
go_library(
name = "go_default_library",
srcs = [
"api.pb.bm.go",
"client.go",
"mock.go",
],
embed = [":v1_go_proto"],
importpath = "go-common/app/service/main/up/api/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/tool/protoc-gen-bm/jsonpb:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/google.golang.org/genproto/googleapis/api/annotations: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,98 @@
// Package v1 Code generated by go-common/app/tool/protoc-gen-bm. DO NOT EDIT.
package v1
import (
"bytes"
"context"
"encoding/json"
"go-common/app/tool/protoc-gen-bm/jsonpb"
bm "go-common/library/net/http/blademaster"
)
// BMUpServer interface as same as gGRPC server define
type BMUpServer interface {
UpArcs(context.Context, *UpArcsReq) (*UpArcsReply, error)
UpsArcs(context.Context, *UpsArcsReq) (*UpsArcsReply, error)
UpCount(context.Context, *UpCountReq) (*UpCountReply, error)
UpsCount(context.Context, *UpsCountReq) (*UpsCountReply, error)
}
// _BMServerUpserver
type _BMServerUp struct {
BMUpServer
}
func (b *_BMServerUp) bmUpUpArcsHandler(c *bm.Context) {
req := new(UpArcsReq)
if err := c.Bind(req); err != nil {
return
}
reply, err := b.UpArcs(c.Context, req)
if err != nil {
c.JSON(nil, err)
return
}
body := &bytes.Buffer{}
marshaler := jsonpb.Marshaler{EmitDefaults: true, OrigName: true}
err = marshaler.Marshal(body, reply)
c.JSON(json.RawMessage(body.Bytes()), err)
}
func (b *_BMServerUp) bmUpUpsArcsHandler(c *bm.Context) {
req := new(UpsArcsReq)
if err := c.Bind(req); err != nil {
return
}
reply, err := b.UpsArcs(c.Context, req)
if err != nil {
c.JSON(nil, err)
return
}
body := &bytes.Buffer{}
marshaler := jsonpb.Marshaler{EmitDefaults: true, OrigName: true}
err = marshaler.Marshal(body, reply)
c.JSON(json.RawMessage(body.Bytes()), err)
}
func (b *_BMServerUp) bmUpUpCountHandler(c *bm.Context) {
req := new(UpCountReq)
if err := c.Bind(req); err != nil {
return
}
reply, err := b.UpCount(c.Context, req)
if err != nil {
c.JSON(nil, err)
return
}
body := &bytes.Buffer{}
marshaler := jsonpb.Marshaler{EmitDefaults: true, OrigName: true}
err = marshaler.Marshal(body, reply)
c.JSON(json.RawMessage(body.Bytes()), err)
}
func (b *_BMServerUp) bmUpUpsCountHandler(c *bm.Context) {
req := new(UpsCountReq)
if err := c.Bind(req); err != nil {
return
}
reply, err := b.UpsCount(c.Context, req)
if err != nil {
c.JSON(nil, err)
return
}
body := &bytes.Buffer{}
marshaler := jsonpb.Marshaler{EmitDefaults: true, OrigName: true}
err = marshaler.Marshal(body, reply)
c.JSON(json.RawMessage(body.Bytes()), err)
}
// RegisterUpBMServer register bm server
func RegisterUpBMServer(e *bm.Engine, s BMUpServer) {
bs := &_BMServerUp{s}
e.GET("/x/internal/uper/archive/up/passed", bs.bmUpUpArcsHandler)
e.GET("/x/internal/uper/archive/ups/passed", bs.bmUpUpsArcsHandler)
e.GET("/x/internal/uper/archive/up/count", bs.bmUpUpCountHandler)
e.GET("/x/internal/uper/archive/ups/count", bs.bmUpUpsCountHandler)
}

View File

@@ -0,0 +1,821 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: app/service/main/up/api/v1/api.proto
/*
Package v1 is a generated protocol buffer package.
It is generated from these files:
app/service/main/up/api/v1/api.proto
app/service/main/up/api/v1/archive.proto
app/service/main/up/api/v1/reply.proto
app/service/main/up/api/v1/request.proto
app/service/main/up/api/v1/sign_up.proto
app/service/main/up/api/v1/up.proto
It has these top-level messages:
AidPubTime
NoReply
UpArcsReply
UpsArcsReply
UpCountReply
UpsCountReply
UpAidPubTimeReply
UpsAidPubTimeReply
UpActivityListReply
UpGroupsReply
UpSpecialReply
UpsSpecialReply
UpGroupMidsReply
UpAttrReply
UpBaseStatReply
UpSwitchReply
HighAllyUpsReply
NoArgReq
UpArcsReq
UpsArcsReq
UpCountReq
UpsCountReq
UpCacheReq
UpListByLastIDReq
UpSpecialReq
UpsSpecialReq
UpGroupMidsReq
UpAttrReq
UpStatReq
UpSwitchReq
HighAllyUpsReq
SignUp
UpActivity
UpGroup
UpSpecial
*/
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "google.golang.org/genproto/googleapis/api/annotations"
import _ "github.com/gogo/protobuf/gogoproto"
import context "golang.org/x/net/context"
import grpc "google.golang.org/grpc"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for Up service
type UpClient interface {
// UpArcs 单个up主的稿件列表接口-带分页
UpArcs(ctx context.Context, in *UpArcsReq, opts ...grpc.CallOption) (*UpArcsReply, error)
// UpsArcs 多个up主的稿件列表接口-带分页
UpsArcs(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsArcsReply, error)
// UpCount 单个up主的稿件计数接口
UpCount(ctx context.Context, in *UpCountReq, opts ...grpc.CallOption) (*UpCountReply, error)
// UpsCount 多个up主的稿件计数接口
UpsCount(ctx context.Context, in *UpsCountReq, opts ...grpc.CallOption) (*UpsCountReply, error)
// UpsAidPubTime archives 多个up主的按分布时间排序的aid接口
UpsAidPubTime(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsAidPubTimeReply, error)
// AddUpPassedCacheByStaff staff变更 新增或者变更up主稿件信息列表和计数接口
AddUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error)
// AddUpPassedCache archive变更 新增或者变更up主稿件信息列表和计数接口
AddUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error)
// DelUpPassedCacheByStaff staff解除 删除的up主稿件信息列表和计数接口
DelUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error)
// DelUpPassedCache archive失效 删除的up主稿件信息列表和计数接口
DelUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error)
// UpInfoActivitys 获取up主活跃度列表信息的接口
UpInfoActivitys(ctx context.Context, in *UpListByLastIDReq, opts ...grpc.CallOption) (*UpActivityListReply, error)
// UpSpecial 获取up主的特殊属性信息的接口
UpSpecial(ctx context.Context, in *UpSpecialReq, opts ...grpc.CallOption) (*UpSpecialReply, error)
// UpsSpecial 获取多个up主的特殊属性信息的接口
UpsSpecial(ctx context.Context, in *UpsSpecialReq, opts ...grpc.CallOption) (*UpsSpecialReply, error)
// UpGroups 获取所有特殊用户组信息的接口
UpGroups(ctx context.Context, in *NoArgReq, opts ...grpc.CallOption) (*UpGroupsReply, error)
// UpGroupMids 获取某个分组下的所有用户的接口
UpGroupMids(ctx context.Context, in *UpGroupMidsReq, opts ...grpc.CallOption) (*UpGroupMidsReply, error)
// UpAttr 获取up主身份属性的接口
UpAttr(ctx context.Context, in *UpAttrReq, opts ...grpc.CallOption) (*UpAttrReply, error)
// UpBaseStats 获取up主基础计数的接口
UpBaseStats(ctx context.Context, in *UpStatReq, opts ...grpc.CallOption) (*UpBaseStatReply, error)
// SetUpSwitch 设置up主关注弹窗开关的接口
SetUpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*NoReply, error)
// UpSwitch 获取up主关注弹窗开关的接口
UpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*UpSwitchReply, error)
// GetHighAllyUps 获取高能联盟up主列表
GetHighAllyUps(ctx context.Context, in *HighAllyUpsReq, opts ...grpc.CallOption) (*HighAllyUpsReply, error)
}
type upClient struct {
cc *grpc.ClientConn
}
func NewUpClient(cc *grpc.ClientConn) UpClient {
return &upClient{cc}
}
func (c *upClient) UpArcs(ctx context.Context, in *UpArcsReq, opts ...grpc.CallOption) (*UpArcsReply, error) {
out := new(UpArcsReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpArcs", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpsArcs(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsArcsReply, error) {
out := new(UpsArcsReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpsArcs", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpCount(ctx context.Context, in *UpCountReq, opts ...grpc.CallOption) (*UpCountReply, error) {
out := new(UpCountReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpCount", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpsCount(ctx context.Context, in *UpsCountReq, opts ...grpc.CallOption) (*UpsCountReply, error) {
out := new(UpsCountReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpsCount", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpsAidPubTime(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsAidPubTimeReply, error) {
out := new(UpsAidPubTimeReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpsAidPubTime", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) AddUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
out := new(NoReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/AddUpPassedCacheByStaff", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) AddUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
out := new(NoReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/AddUpPassedCache", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) DelUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
out := new(NoReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/DelUpPassedCacheByStaff", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) DelUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
out := new(NoReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/DelUpPassedCache", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpInfoActivitys(ctx context.Context, in *UpListByLastIDReq, opts ...grpc.CallOption) (*UpActivityListReply, error) {
out := new(UpActivityListReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpInfoActivitys", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpSpecial(ctx context.Context, in *UpSpecialReq, opts ...grpc.CallOption) (*UpSpecialReply, error) {
out := new(UpSpecialReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpSpecial", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpsSpecial(ctx context.Context, in *UpsSpecialReq, opts ...grpc.CallOption) (*UpsSpecialReply, error) {
out := new(UpsSpecialReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpsSpecial", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpGroups(ctx context.Context, in *NoArgReq, opts ...grpc.CallOption) (*UpGroupsReply, error) {
out := new(UpGroupsReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpGroups", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpGroupMids(ctx context.Context, in *UpGroupMidsReq, opts ...grpc.CallOption) (*UpGroupMidsReply, error) {
out := new(UpGroupMidsReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpGroupMids", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpAttr(ctx context.Context, in *UpAttrReq, opts ...grpc.CallOption) (*UpAttrReply, error) {
out := new(UpAttrReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpAttr", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpBaseStats(ctx context.Context, in *UpStatReq, opts ...grpc.CallOption) (*UpBaseStatReply, error) {
out := new(UpBaseStatReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpBaseStats", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) SetUpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*NoReply, error) {
out := new(NoReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/SetUpSwitch", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) UpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*UpSwitchReply, error) {
out := new(UpSwitchReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/UpSwitch", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *upClient) GetHighAllyUps(ctx context.Context, in *HighAllyUpsReq, opts ...grpc.CallOption) (*HighAllyUpsReply, error) {
out := new(HighAllyUpsReply)
err := grpc.Invoke(ctx, "/archive.service.up.v1.Up/GetHighAllyUps", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Up service
type UpServer interface {
// UpArcs 单个up主的稿件列表接口-带分页
UpArcs(context.Context, *UpArcsReq) (*UpArcsReply, error)
// UpsArcs 多个up主的稿件列表接口-带分页
UpsArcs(context.Context, *UpsArcsReq) (*UpsArcsReply, error)
// UpCount 单个up主的稿件计数接口
UpCount(context.Context, *UpCountReq) (*UpCountReply, error)
// UpsCount 多个up主的稿件计数接口
UpsCount(context.Context, *UpsCountReq) (*UpsCountReply, error)
// UpsAidPubTime archives 多个up主的按分布时间排序的aid接口
UpsAidPubTime(context.Context, *UpsArcsReq) (*UpsAidPubTimeReply, error)
// AddUpPassedCacheByStaff staff变更 新增或者变更up主稿件信息列表和计数接口
AddUpPassedCacheByStaff(context.Context, *UpCacheReq) (*NoReply, error)
// AddUpPassedCache archive变更 新增或者变更up主稿件信息列表和计数接口
AddUpPassedCache(context.Context, *UpCacheReq) (*NoReply, error)
// DelUpPassedCacheByStaff staff解除 删除的up主稿件信息列表和计数接口
DelUpPassedCacheByStaff(context.Context, *UpCacheReq) (*NoReply, error)
// DelUpPassedCache archive失效 删除的up主稿件信息列表和计数接口
DelUpPassedCache(context.Context, *UpCacheReq) (*NoReply, error)
// UpInfoActivitys 获取up主活跃度列表信息的接口
UpInfoActivitys(context.Context, *UpListByLastIDReq) (*UpActivityListReply, error)
// UpSpecial 获取up主的特殊属性信息的接口
UpSpecial(context.Context, *UpSpecialReq) (*UpSpecialReply, error)
// UpsSpecial 获取多个up主的特殊属性信息的接口
UpsSpecial(context.Context, *UpsSpecialReq) (*UpsSpecialReply, error)
// UpGroups 获取所有特殊用户组信息的接口
UpGroups(context.Context, *NoArgReq) (*UpGroupsReply, error)
// UpGroupMids 获取某个分组下的所有用户的接口
UpGroupMids(context.Context, *UpGroupMidsReq) (*UpGroupMidsReply, error)
// UpAttr 获取up主身份属性的接口
UpAttr(context.Context, *UpAttrReq) (*UpAttrReply, error)
// UpBaseStats 获取up主基础计数的接口
UpBaseStats(context.Context, *UpStatReq) (*UpBaseStatReply, error)
// SetUpSwitch 设置up主关注弹窗开关的接口
SetUpSwitch(context.Context, *UpSwitchReq) (*NoReply, error)
// UpSwitch 获取up主关注弹窗开关的接口
UpSwitch(context.Context, *UpSwitchReq) (*UpSwitchReply, error)
// GetHighAllyUps 获取高能联盟up主列表
GetHighAllyUps(context.Context, *HighAllyUpsReq) (*HighAllyUpsReply, error)
}
func RegisterUpServer(s *grpc.Server, srv UpServer) {
s.RegisterService(&_Up_serviceDesc, srv)
}
func _Up_UpArcs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpArcsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpArcs(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpArcs",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpArcs(ctx, req.(*UpArcsReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpsArcs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpsArcsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpsArcs(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpsArcs",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpsArcs(ctx, req.(*UpsArcsReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpCount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpCountReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpCount(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpCount",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpCount(ctx, req.(*UpCountReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpsCount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpsCountReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpsCount(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpsCount",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpsCount(ctx, req.(*UpsCountReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpsAidPubTime_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpsArcsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpsAidPubTime(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpsAidPubTime",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpsAidPubTime(ctx, req.(*UpsArcsReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_AddUpPassedCacheByStaff_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpCacheReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).AddUpPassedCacheByStaff(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/AddUpPassedCacheByStaff",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).AddUpPassedCacheByStaff(ctx, req.(*UpCacheReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_AddUpPassedCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpCacheReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).AddUpPassedCache(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/AddUpPassedCache",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).AddUpPassedCache(ctx, req.(*UpCacheReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_DelUpPassedCacheByStaff_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpCacheReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).DelUpPassedCacheByStaff(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/DelUpPassedCacheByStaff",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).DelUpPassedCacheByStaff(ctx, req.(*UpCacheReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_DelUpPassedCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpCacheReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).DelUpPassedCache(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/DelUpPassedCache",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).DelUpPassedCache(ctx, req.(*UpCacheReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpInfoActivitys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpListByLastIDReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpInfoActivitys(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpInfoActivitys",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpInfoActivitys(ctx, req.(*UpListByLastIDReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpSpecial_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpSpecialReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpSpecial(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpSpecial",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpSpecial(ctx, req.(*UpSpecialReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpsSpecial_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpsSpecialReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpsSpecial(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpsSpecial",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpsSpecial(ctx, req.(*UpsSpecialReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpGroups_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(NoArgReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpGroups(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpGroups",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpGroups(ctx, req.(*NoArgReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpGroupMids_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpGroupMidsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpGroupMids(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpGroupMids",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpGroupMids(ctx, req.(*UpGroupMidsReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpAttr_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpAttrReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpAttr(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpAttr",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpAttr(ctx, req.(*UpAttrReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpBaseStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpStatReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpBaseStats(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpBaseStats",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpBaseStats(ctx, req.(*UpStatReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_SetUpSwitch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpSwitchReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).SetUpSwitch(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/SetUpSwitch",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).SetUpSwitch(ctx, req.(*UpSwitchReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_UpSwitch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpSwitchReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).UpSwitch(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/UpSwitch",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).UpSwitch(ctx, req.(*UpSwitchReq))
}
return interceptor(ctx, in, info, handler)
}
func _Up_GetHighAllyUps_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HighAllyUpsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UpServer).GetHighAllyUps(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/archive.service.up.v1.Up/GetHighAllyUps",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UpServer).GetHighAllyUps(ctx, req.(*HighAllyUpsReq))
}
return interceptor(ctx, in, info, handler)
}
var _Up_serviceDesc = grpc.ServiceDesc{
ServiceName: "archive.service.up.v1.Up",
HandlerType: (*UpServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "UpArcs",
Handler: _Up_UpArcs_Handler,
},
{
MethodName: "UpsArcs",
Handler: _Up_UpsArcs_Handler,
},
{
MethodName: "UpCount",
Handler: _Up_UpCount_Handler,
},
{
MethodName: "UpsCount",
Handler: _Up_UpsCount_Handler,
},
{
MethodName: "UpsAidPubTime",
Handler: _Up_UpsAidPubTime_Handler,
},
{
MethodName: "AddUpPassedCacheByStaff",
Handler: _Up_AddUpPassedCacheByStaff_Handler,
},
{
MethodName: "AddUpPassedCache",
Handler: _Up_AddUpPassedCache_Handler,
},
{
MethodName: "DelUpPassedCacheByStaff",
Handler: _Up_DelUpPassedCacheByStaff_Handler,
},
{
MethodName: "DelUpPassedCache",
Handler: _Up_DelUpPassedCache_Handler,
},
{
MethodName: "UpInfoActivitys",
Handler: _Up_UpInfoActivitys_Handler,
},
{
MethodName: "UpSpecial",
Handler: _Up_UpSpecial_Handler,
},
{
MethodName: "UpsSpecial",
Handler: _Up_UpsSpecial_Handler,
},
{
MethodName: "UpGroups",
Handler: _Up_UpGroups_Handler,
},
{
MethodName: "UpGroupMids",
Handler: _Up_UpGroupMids_Handler,
},
{
MethodName: "UpAttr",
Handler: _Up_UpAttr_Handler,
},
{
MethodName: "UpBaseStats",
Handler: _Up_UpBaseStats_Handler,
},
{
MethodName: "SetUpSwitch",
Handler: _Up_SetUpSwitch_Handler,
},
{
MethodName: "UpSwitch",
Handler: _Up_UpSwitch_Handler,
},
{
MethodName: "GetHighAllyUps",
Handler: _Up_GetHighAllyUps_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "app/service/main/up/api/v1/api.proto",
}
func init() { proto.RegisterFile("app/service/main/up/api/v1/api.proto", fileDescriptorApi) }
var fileDescriptorApi = []byte{
// 613 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xdf, 0x6a, 0x14, 0x3d,
0x18, 0x87, 0xd9, 0x1e, 0xf4, 0xfb, 0x4c, 0xb1, 0x96, 0x80, 0x14, 0x16, 0x59, 0xed, 0xfe, 0xa9,
0x6d, 0xc5, 0x19, 0x56, 0xaf, 0x60, 0xb7, 0x85, 0x5a, 0xa8, 0xa5, 0xba, 0x0d, 0x42, 0x69, 0xc1,
0xec, 0x6c, 0x76, 0x36, 0x30, 0x3b, 0x79, 0x9b, 0x64, 0x46, 0x47, 0x44, 0xc4, 0x5b, 0xf0, 0xa6,
0x3c, 0x12, 0xc1, 0x1b, 0x90, 0xc5, 0x0b, 0x91, 0x64, 0x66, 0x4b, 0x2d, 0x4e, 0x66, 0x85, 0x7a,
0xd4, 0xce, 0xe4, 0xc9, 0xf3, 0x4b, 0xde, 0x77, 0x92, 0x45, 0x6d, 0x0a, 0xe0, 0x2b, 0x26, 0x53,
0x1e, 0x30, 0x7f, 0x4a, 0x79, 0xec, 0x27, 0xe0, 0x53, 0xe0, 0x7e, 0xda, 0x35, 0x7f, 0x3c, 0x90,
0x42, 0x0b, 0x7c, 0x97, 0xca, 0x60, 0xc2, 0x53, 0xe6, 0x15, 0xa4, 0x97, 0x80, 0x97, 0x76, 0xeb,
0x5b, 0x8e, 0xc9, 0x92, 0x5d, 0x24, 0x4c, 0xe9, 0x5c, 0x50, 0xdf, 0x74, 0x92, 0x10, 0x65, 0x05,
0x77, 0x2f, 0x14, 0x22, 0x8c, 0x98, 0x1d, 0xa2, 0x71, 0x2c, 0x34, 0xd5, 0x5c, 0xc4, 0xaa, 0x18,
0x7d, 0x1c, 0x72, 0x3d, 0x49, 0x86, 0x5e, 0x20, 0xa6, 0x7e, 0x28, 0x42, 0xe1, 0xdb, 0xd7, 0xc3,
0x64, 0x6c, 0x9f, 0xec, 0x83, 0xfd, 0x2f, 0xc7, 0x9f, 0x7c, 0x5d, 0x45, 0x4b, 0x04, 0xf0, 0x3b,
0xb4, 0x4c, 0xa0, 0x27, 0x03, 0x85, 0x1f, 0x78, 0x7f, 0xdc, 0x87, 0x97, 0x0f, 0xbf, 0x64, 0x17,
0xf5, 0x66, 0x05, 0x01, 0x51, 0xd6, 0xdc, 0xf9, 0xf4, 0xfd, 0xe7, 0xe7, 0xa5, 0x36, 0x6e, 0xfa,
0x6f, 0x7d, 0x1e, 0x6b, 0x26, 0x63, 0x1a, 0xf9, 0x09, 0x30, 0xe9, 0x17, 0x73, 0xcd, 0xde, 0x80,
0x2a, 0xc5, 0x46, 0xf8, 0x03, 0xfa, 0x8f, 0x80, 0xb2, 0xe1, 0x1b, 0xa5, 0x6a, 0x35, 0x4f, 0x6f,
0x55, 0x21, 0x26, 0xfe, 0x91, 0x8d, 0xef, 0xe0, 0x96, 0x23, 0x5e, 0xcd, 0xf3, 0xdf, 0x9b, 0xfc,
0x5d, 0x91, 0xc4, 0xda, 0x91, 0x6f, 0xc7, 0xdd, 0xf9, 0x05, 0x62, 0xf2, 0xb7, 0x6d, 0x7e, 0x0b,
0x6f, 0xb8, 0xb6, 0x1f, 0xd8, 0xc8, 0x8f, 0x35, 0xf4, 0x3f, 0x01, 0x95, 0xe7, 0x97, 0x97, 0x56,
0x5d, 0x2e, 0xa0, 0x5d, 0xc9, 0x2c, 0xda, 0x00, 0x55, 0x2c, 0xe1, 0x1c, 0xdd, 0x36, 0xd5, 0xe3,
0xa3, 0xe3, 0x64, 0x78, 0xc2, 0xa7, 0x6c, 0x91, 0x36, 0x6c, 0x3b, 0x90, 0x4b, 0x91, 0x5d, 0x0a,
0x3e, 0x43, 0xeb, 0xbd, 0xd1, 0x88, 0xc0, 0xb1, 0x2d, 0xf7, 0x2e, 0x0d, 0x26, 0xac, 0x9f, 0x0d,
0x34, 0x1d, 0x8f, 0x5d, 0xf5, 0x36, 0x98, 0x09, 0x6a, 0x94, 0x20, 0x47, 0x22, 0xb7, 0x13, 0xb4,
0x76, 0xdd, 0x7e, 0x13, 0xda, 0x33, 0xb4, 0xbe, 0xc7, 0xa2, 0x7f, 0xb8, 0xe8, 0xeb, 0xf6, 0x9b,
0xd0, 0x86, 0xe8, 0x0e, 0x81, 0x83, 0x78, 0x2c, 0x7a, 0x81, 0xe6, 0x29, 0xd7, 0x99, 0xc2, 0x5b,
0xa5, 0xd6, 0x43, 0xae, 0x74, 0x3f, 0x3b, 0xa4, 0x4a, 0x1f, 0xec, 0x19, 0xf9, 0x4e, 0xf9, 0xb1,
0x2e, 0x6c, 0x66, 0x46, 0x1e, 0xf4, 0x0a, 0xdd, 0x22, 0x30, 0x00, 0x16, 0x70, 0x1a, 0xe1, 0xf2,
0x13, 0x51, 0x10, 0xc6, 0xde, 0xa9, 0x86, 0x8c, 0xf8, 0x14, 0x21, 0x02, 0x6a, 0x6e, 0x76, 0x7c,
0xea, 0x57, 0xd4, 0x9b, 0x0b, 0x50, 0xc6, 0xfd, 0xc2, 0x1c, 0xb4, 0x7d, 0x29, 0x12, 0x50, 0xf8,
0x7e, 0x69, 0x25, 0x7b, 0x32, 0x74, 0x9f, 0xb2, 0xdc, 0x90, 0x2b, 0xcf, 0xd1, 0x4a, 0xf1, 0xe2,
0x39, 0x1f, 0x29, 0xdc, 0x71, 0x4f, 0x32, 0x8c, 0x71, 0x3f, 0x5c, 0x04, 0x33, 0xfa, 0x23, 0x7b,
0x2b, 0x6b, 0x2d, 0x5d, 0xb7, 0xb2, 0xd6, 0xb2, 0xe2, 0x56, 0xb6, 0x44, 0xde, 0xb6, 0x15, 0x02,
0x7d, 0xaa, 0xd8, 0x40, 0x53, 0xed, 0xba, 0xea, 0xcd, 0xb8, 0xbb, 0xb4, 0x73, 0xcb, 0xbc, 0xb4,
0x2b, 0x03, 0xa6, 0x09, 0x0c, 0xde, 0x70, 0x1d, 0x4c, 0x1c, 0xd7, 0x58, 0x0e, 0x2c, 0xf2, 0x2d,
0x9f, 0x98, 0x6e, 0xfd, 0x85, 0xaf, 0x5d, 0xc9, 0x18, 0xeb, 0x6b, 0xb4, 0xba, 0xcf, 0xf4, 0x33,
0x1e, 0x4e, 0x7a, 0x51, 0x94, 0x11, 0x28, 0xef, 0xd9, 0x15, 0xc6, 0xd5, 0xb3, 0xdf, 0x30, 0x88,
0xb2, 0xfe, 0xda, 0x97, 0x59, 0xa3, 0xf6, 0x6d, 0xd6, 0xa8, 0xfd, 0x98, 0x35, 0x6a, 0xa7, 0x4b,
0x69, 0x77, 0xb8, 0x6c, 0x7f, 0x69, 0x9f, 0xfe, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xc9, 0x84, 0x1b,
0x65, 0x47, 0x08, 0x00, 0x00,
}

View File

@@ -0,0 +1,68 @@
syntax = "proto3";
package archive.service.up.v1;
import "app/service/main/up/api/v1/request.proto";
import "app/service/main/up/api/v1/reply.proto";
import "google/api/annotations.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// Up up主相关的稿件接口
service Up {
// UpArcs 单个up主的稿件列表接口-带分页
rpc UpArcs(UpArcsReq) returns (UpArcsReply) {
option (google.api.http) = {
get: "/x/internal/uper/archive/up/passed"
};
}
// UpsArcs 多个up主的稿件列表接口-带分页
rpc UpsArcs(UpsArcsReq) returns (UpsArcsReply) {
option (google.api.http) = {
get: "/x/internal/uper/archive/ups/passed"
};
}
// UpCount 单个up主的稿件计数接口
rpc UpCount(UpCountReq) returns (UpCountReply) {
option (google.api.http) = {
get: "/x/internal/uper/archive/up/count"
};
}
// UpsCount 多个up主的稿件计数接口
rpc UpsCount(UpsCountReq) returns (UpsCountReply) {
option (google.api.http) = {
get: "/x/internal/uper/archive/ups/count"
};
}
// UpsAidPubTime archives 多个up主的按分布时间排序的aid接口
rpc UpsAidPubTime(UpsArcsReq) returns (UpsAidPubTimeReply);
// AddUpPassedCacheByStaff staff变更 新增或者变更up主稿件信息列表和计数接口
rpc AddUpPassedCacheByStaff(UpCacheReq) returns (NoReply);
// AddUpPassedCache archive变更 新增或者变更up主稿件信息列表和计数接口
rpc AddUpPassedCache(UpCacheReq) returns (NoReply);
// DelUpPassedCacheByStaff staff解除 删除的up主稿件信息列表和计数接口
rpc DelUpPassedCacheByStaff(UpCacheReq) returns (NoReply);
// DelUpPassedCache archive失效 删除的up主稿件信息列表和计数接口
rpc DelUpPassedCache(UpCacheReq) returns (NoReply);
// UpInfoActivitys 获取up主活跃度列表信息的接口
rpc UpInfoActivitys(UpListByLastIDReq) returns (UpActivityListReply);
// UpSpecial 获取up主的特殊属性信息的接口
rpc UpSpecial(UpSpecialReq) returns (UpSpecialReply);
// UpsSpecial 获取多个up主的特殊属性信息的接口
rpc UpsSpecial(UpsSpecialReq) returns (UpsSpecialReply);
// UpGroups 获取所有特殊用户组信息的接口
rpc UpGroups(NoArgReq) returns (UpGroupsReply);
// UpGroupMids 获取某个分组下的所有用户的接口
rpc UpGroupMids(UpGroupMidsReq) returns (UpGroupMidsReply);
// UpAttr 获取up主身份属性的接口
rpc UpAttr(UpAttrReq) returns (UpAttrReply);
// UpBaseStats 获取up主基础计数的接口
rpc UpBaseStats(UpStatReq) returns (UpBaseStatReply);
// SetUpSwitch 设置up主关注弹窗开关的接口
rpc SetUpSwitch(UpSwitchReq) returns (NoReply);
// UpSwitch 获取up主关注弹窗开关的接口
rpc UpSwitch(UpSwitchReq) returns (UpSwitchReply);
// GetHighAllyUps 获取高能联盟up主列表
rpc GetHighAllyUps(HighAllyUpsReq) returns (HighAllyUpsReply);
}

View File

@@ -0,0 +1,487 @@
{
"swagger": "2.0",
"info": {
"title": "app/service/main/up/api/v1/api.proto",
"version": "version not set"
},
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/x/internal/uper/archive/up/count": {
"get": {
"summary": "UpCount 单个up主的稿件计数接口",
"operationId": "UpCount",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UpCountReply"
}
}
},
"parameters": [
{
"name": "mid",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
}
],
"tags": [
"Up"
]
}
},
"/x/internal/uper/archive/up/passed": {
"get": {
"summary": "UpArcs 单个up主的稿件列表接口-带分页",
"operationId": "UpArcs",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UpArcsReply"
}
}
},
"parameters": [
{
"name": "mid",
"description": "mid 用户id 必传.",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
},
{
"name": "pn",
"description": "pn 第几页 非必传.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "ps",
"description": "ps 分页大小 非必传.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Up"
]
}
},
"/x/internal/uper/archive/ups/count": {
"get": {
"summary": "UpsCount 多个up主的稿件计数接口",
"operationId": "UpsCount",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UpsCountReply"
}
}
},
"parameters": [
{
"name": "mids",
"description": "mids 多个用户id 必传 最大100个.",
"in": "query",
"required": false,
"type": "array",
"items": {
"type": "string",
"format": "int64"
}
}
],
"tags": [
"Up"
]
}
},
"/x/internal/uper/archive/ups/passed": {
"get": {
"summary": "UpsArcs 多个up主的稿件列表接口-带分页",
"operationId": "UpsArcs",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UpsArcsReply"
}
}
},
"parameters": [
{
"name": "mids",
"description": "mids 多个用户id 必传 最大100个.",
"in": "query",
"required": false,
"type": "array",
"items": {
"type": "string",
"format": "int64"
}
},
{
"name": "pn",
"description": "pn 第几页 非必传.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "ps",
"description": "ps 分页大小 非必传.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Up"
]
}
}
},
"definitions": {
"v1AidPubTime": {
"type": "object",
"properties": {
"Aid": {
"type": "string",
"format": "int64",
"title": "Aid 稿件aid"
},
"PubDate": {
"type": "string",
"format": "int64",
"title": "PubDate 发布时间"
},
"Copyright": {
"type": "integer",
"format": "int32",
"title": "Copyright 版权来源"
}
},
"title": "AidPubTime 发布时间的稿件aid的信息"
},
"v1Arc": {
"type": "object",
"properties": {
"Aid": {
"type": "string",
"format": "int64"
},
"Videos": {
"type": "string",
"format": "int64"
},
"TypeID": {
"type": "integer",
"format": "int32"
},
"TypeName": {
"type": "string"
},
"Copyright": {
"type": "integer",
"format": "int32"
},
"Pic": {
"type": "string"
},
"Title": {
"type": "string"
},
"PubDate": {
"type": "string",
"format": "int64"
},
"Ctime": {
"type": "string",
"format": "int64"
},
"Desc": {
"type": "string"
},
"State": {
"type": "integer",
"format": "int32"
},
"Access": {
"type": "integer",
"format": "int32"
},
"Attribute": {
"type": "integer",
"format": "int32"
},
"Tag": {
"type": "string"
},
"Tags": {
"type": "array",
"items": {
"type": "string"
}
},
"Duration": {
"type": "string",
"format": "int64"
},
"MissionID": {
"type": "string",
"format": "int64"
},
"OrderID": {
"type": "string",
"format": "int64"
},
"RedirectURL": {
"type": "string"
},
"Forward": {
"type": "string",
"format": "int64"
},
"Rights": {
"$ref": "#/definitions/v1Rights"
},
"Author": {
"$ref": "#/definitions/v1Author"
},
"Stat": {
"$ref": "#/definitions/v1Stat"
},
"ReportResult": {
"type": "string"
},
"Dynamic": {
"type": "string"
},
"FirstCid": {
"type": "string",
"format": "int64"
},
"Dimension": {
"$ref": "#/definitions/v1Dimension"
}
}
},
"v1Author": {
"type": "object",
"properties": {
"Mid": {
"type": "string",
"format": "int64"
},
"Name": {
"type": "string"
},
"Face": {
"type": "string"
}
}
},
"v1Dimension": {
"type": "object",
"properties": {
"Width": {
"type": "string",
"format": "int64"
},
"Height": {
"type": "string",
"format": "int64"
},
"Rotate": {
"type": "string",
"format": "int64"
}
}
},
"v1NoReply": {
"type": "object",
"title": "NoReply 没有返回值"
},
"v1Rights": {
"type": "object",
"properties": {
"Bp": {
"type": "integer",
"format": "int32"
},
"Elec": {
"type": "integer",
"format": "int32"
},
"Download": {
"type": "integer",
"format": "int32"
},
"Movie": {
"type": "integer",
"format": "int32"
},
"Pay": {
"type": "integer",
"format": "int32"
},
"HD5": {
"type": "integer",
"format": "int32"
},
"NoReprint": {
"type": "integer",
"format": "int32"
},
"Autoplay": {
"type": "integer",
"format": "int32"
},
"UGCPay": {
"type": "integer",
"format": "int32"
}
}
},
"v1Stat": {
"type": "object",
"properties": {
"Aid": {
"type": "string",
"format": "int64"
},
"View": {
"type": "integer",
"format": "int32"
},
"Danmaku": {
"type": "integer",
"format": "int32"
},
"Reply": {
"type": "integer",
"format": "int32"
},
"Fav": {
"type": "integer",
"format": "int32"
},
"Coin": {
"type": "integer",
"format": "int32"
},
"Share": {
"type": "integer",
"format": "int32"
},
"NowRank": {
"type": "integer",
"format": "int32"
},
"HisRank": {
"type": "integer",
"format": "int32"
},
"Like": {
"type": "integer",
"format": "int32"
},
"DisLike": {
"type": "integer",
"format": "int32"
}
}
},
"v1UpAidPubTimeReply": {
"type": "object",
"properties": {
"archives": {
"type": "array",
"items": {
"$ref": "#/definitions/v1AidPubTime"
}
}
},
"title": "UpAidPubTimeReply 按发布时间的单个up的稿件aid的返回值"
},
"v1UpArcsReply": {
"type": "object",
"properties": {
"archives": {
"type": "array",
"items": {
"$ref": "#/definitions/v1Arc"
}
}
},
"title": "UpArcsReply 单个up主的稿件信息列表返回值"
},
"v1UpCountReply": {
"type": "object",
"properties": {
"count": {
"type": "string",
"format": "int64"
}
},
"title": "UpCountReply 单个up主的稿件计数返回值"
},
"v1UpsAidPubTimeReply": {
"type": "object",
"properties": {
"archives": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/v1UpAidPubTimeReply"
}
}
},
"title": "UpsAidPubTimeReply 按发布时间的多个up的稿件aid的返回值"
},
"v1UpsArcsReply": {
"type": "object",
"properties": {
"archives": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/v1UpArcsReply"
}
}
},
"title": "UpsArcsReply 多个up主的稿件信息列表返回值"
},
"v1UpsCountReply": {
"type": "object",
"properties": {
"count": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "int64"
}
}
},
"title": "UpsCountReply 多个up主的稿件计数返回值"
}
}
}

View File

@@ -0,0 +1,361 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: app/service/main/up/api/v1/archive.proto
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import go_common_library_time "go-common/library/time"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// AidPubTime 发布时间的稿件aid的信息
type AidPubTime struct {
// aid 稿件aid
Aid int64 `protobuf:"varint,1,opt,name=aid,proto3" json:"aid"`
// pub_date 发布时间
PubDate go_common_library_time.Time `protobuf:"varint,2,opt,name=pub_date,json=pubDate,proto3,casttype=go-common/library/time.Time" json:"pubdate"`
// copyright 版权来源
Copyright int32 `protobuf:"varint,3,opt,name=copyright,proto3" json:"copyright"`
}
func (m *AidPubTime) Reset() { *m = AidPubTime{} }
func (m *AidPubTime) String() string { return proto.CompactTextString(m) }
func (*AidPubTime) ProtoMessage() {}
func (*AidPubTime) Descriptor() ([]byte, []int) { return fileDescriptorArchive, []int{0} }
func (m *AidPubTime) GetAid() int64 {
if m != nil {
return m.Aid
}
return 0
}
func (m *AidPubTime) GetPubDate() go_common_library_time.Time {
if m != nil {
return m.PubDate
}
return 0
}
func (m *AidPubTime) GetCopyright() int32 {
if m != nil {
return m.Copyright
}
return 0
}
func init() {
proto.RegisterType((*AidPubTime)(nil), "archive.service.up.v1.AidPubTime")
}
func (m *AidPubTime) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *AidPubTime) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Aid != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintArchive(dAtA, i, uint64(m.Aid))
}
if m.PubDate != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintArchive(dAtA, i, uint64(m.PubDate))
}
if m.Copyright != 0 {
dAtA[i] = 0x18
i++
i = encodeVarintArchive(dAtA, i, uint64(m.Copyright))
}
return i, nil
}
func encodeVarintArchive(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *AidPubTime) Size() (n int) {
var l int
_ = l
if m.Aid != 0 {
n += 1 + sovArchive(uint64(m.Aid))
}
if m.PubDate != 0 {
n += 1 + sovArchive(uint64(m.PubDate))
}
if m.Copyright != 0 {
n += 1 + sovArchive(uint64(m.Copyright))
}
return n
}
func sovArchive(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozArchive(x uint64) (n int) {
return sovArchive(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *AidPubTime) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowArchive
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: AidPubTime: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: AidPubTime: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Aid", wireType)
}
m.Aid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowArchive
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Aid |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field PubDate", wireType)
}
m.PubDate = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowArchive
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.PubDate |= (go_common_library_time.Time(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Copyright", wireType)
}
m.Copyright = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowArchive
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Copyright |= (int32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipArchive(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthArchive
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipArchive(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowArchive
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowArchive
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowArchive
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthArchive
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowArchive
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipArchive(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthArchive = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowArchive = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("app/service/main/up/api/v1/archive.proto", fileDescriptorArchive) }
var fileDescriptorArchive = []byte{
// 255 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x8e, 0x41, 0x4a, 0xc4, 0x30,
0x14, 0x86, 0xc9, 0x14, 0x1d, 0x0d, 0x08, 0x52, 0x10, 0xaa, 0x42, 0x3b, 0xb8, 0x2a, 0xca, 0xf4,
0x51, 0x3c, 0x81, 0x45, 0xf7, 0x52, 0x5c, 0xb9, 0x91, 0xa4, 0x8d, 0xed, 0x03, 0x33, 0x09, 0x31,
0x29, 0xcc, 0x59, 0xbc, 0x90, 0x4b, 0x4f, 0x50, 0xa4, 0xcb, 0x1e, 0xc1, 0x95, 0x24, 0x3a, 0xcc,
0x26, 0xfc, 0xdf, 0x9f, 0x8f, 0x9f, 0x47, 0x73, 0xa6, 0x35, 0xbc, 0x0b, 0x33, 0x60, 0x23, 0x40,
0x32, 0xdc, 0x80, 0xd3, 0xc0, 0x34, 0xc2, 0x50, 0x02, 0x33, 0x4d, 0x8f, 0x83, 0x28, 0xb4, 0x51,
0x56, 0xc5, 0x67, 0x3b, 0xfc, 0xb7, 0x0b, 0xa7, 0x8b, 0xa1, 0xbc, 0x58, 0x77, 0x68, 0x7b, 0xc7,
0x8b, 0x46, 0x49, 0xe8, 0x54, 0xa7, 0x20, 0xd8, 0xdc, 0xbd, 0x06, 0x0a, 0x10, 0xd2, 0xdf, 0xca,
0xd5, 0x07, 0xa1, 0xf4, 0x0e, 0xdb, 0x47, 0xc7, 0x9f, 0x50, 0x8a, 0xf8, 0x9c, 0x46, 0x0c, 0xdb,
0x84, 0xac, 0x48, 0x1e, 0x55, 0xcb, 0x79, 0xcc, 0x3c, 0xd6, 0xfe, 0x89, 0x1f, 0xe8, 0x91, 0x76,
0xfc, 0xa5, 0x65, 0x56, 0x24, 0x8b, 0xf0, 0x7f, 0x3d, 0x8f, 0xd9, 0x52, 0x3b, 0xee, 0xab, 0x9f,
0x31, 0xbb, 0xec, 0xd4, 0xba, 0x51, 0x52, 0xaa, 0x0d, 0xbc, 0x21, 0x37, 0xcc, 0x6c, 0xc1, 0xa2,
0x14, 0x85, 0x1f, 0xae, 0xbd, 0x77, 0xcf, 0xac, 0x88, 0x6f, 0xe8, 0x71, 0xa3, 0xf4, 0xd6, 0x60,
0xd7, 0xdb, 0x24, 0x5a, 0x91, 0xfc, 0xa0, 0x3a, 0x99, 0xc7, 0x6c, 0x5f, 0xd6, 0xfb, 0x58, 0x9d,
0x7e, 0x4e, 0x29, 0xf9, 0x9a, 0x52, 0xf2, 0x3d, 0xa5, 0xe4, 0x79, 0x31, 0x94, 0xfc, 0x30, 0x9c,
0x7d, 0xfb, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x8d, 0xf9, 0xfe, 0x1f, 0x28, 0x01, 0x00, 0x00,
}

View File

@@ -0,0 +1,19 @@
syntax = "proto3";
package archive.service.up.v1;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// AidPubTime 发布时间的稿件aid的信息
message AidPubTime {
// aid 稿件aid
int64 aid = 1 [(gogoproto.jsontag) = "aid"];
// pub_date 发布时间
int64 pub_date = 2 [
(gogoproto.jsontag) = "pubdate",
(gogoproto.casttype) = "go-common/library/time.Time"
];
// copyright 版权来源
int32 copyright = 3 [(gogoproto.jsontag) = "copyright"];
}

View File

@@ -0,0 +1,22 @@
package v1
import (
"context"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
// AppID unique app id for service discovery
const AppID = "archive.service.up"
// NewClient new member grpc client
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (UpClient, error) {
client := warden.NewClient(cfg, opts...)
conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
if err != nil {
return nil, err
}
return NewUpClient(conn), nil
}

View File

@@ -0,0 +1,647 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: api.pb.go
// Package v1 is a generated GoMock package.
package v1
import (
gomock "github.com/golang/mock/gomock"
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
reflect "reflect"
)
// MockUpClient is a mock of UpClient interface
type MockUpClient struct {
ctrl *gomock.Controller
recorder *MockUpClientMockRecorder
}
// MockUpClientMockRecorder is the mock recorder for MockUpClient
type MockUpClientMockRecorder struct {
mock *MockUpClient
}
// NewMockUpClient creates a new mock instance
func NewMockUpClient(ctrl *gomock.Controller) *MockUpClient {
mock := &MockUpClient{ctrl: ctrl}
mock.recorder = &MockUpClientMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockUpClient) EXPECT() *MockUpClientMockRecorder {
return m.recorder
}
// UpArcs mocks base method
func (m *MockUpClient) UpArcs(ctx context.Context, in *UpArcsReq, opts ...grpc.CallOption) (*UpArcsReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpArcs", varargs...)
ret0, _ := ret[0].(*UpArcsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpArcs indicates an expected call of UpArcs
func (mr *MockUpClientMockRecorder) UpArcs(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpArcs", reflect.TypeOf((*MockUpClient)(nil).UpArcs), varargs...)
}
// UpsArcs mocks base method
func (m *MockUpClient) UpsArcs(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsArcsReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpsArcs", varargs...)
ret0, _ := ret[0].(*UpsArcsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsArcs indicates an expected call of UpsArcs
func (mr *MockUpClientMockRecorder) UpsArcs(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsArcs", reflect.TypeOf((*MockUpClient)(nil).UpsArcs), varargs...)
}
// UpCount mocks base method
func (m *MockUpClient) UpCount(ctx context.Context, in *UpCountReq, opts ...grpc.CallOption) (*UpCountReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpCount", varargs...)
ret0, _ := ret[0].(*UpCountReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpCount indicates an expected call of UpCount
func (mr *MockUpClientMockRecorder) UpCount(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpCount", reflect.TypeOf((*MockUpClient)(nil).UpCount), varargs...)
}
// UpsCount mocks base method
func (m *MockUpClient) UpsCount(ctx context.Context, in *UpsCountReq, opts ...grpc.CallOption) (*UpsCountReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpsCount", varargs...)
ret0, _ := ret[0].(*UpsCountReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsCount indicates an expected call of UpsCount
func (mr *MockUpClientMockRecorder) UpsCount(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsCount", reflect.TypeOf((*MockUpClient)(nil).UpsCount), varargs...)
}
// UpsAidPubTime mocks base method
func (m *MockUpClient) UpsAidPubTime(ctx context.Context, in *UpsArcsReq, opts ...grpc.CallOption) (*UpsAidPubTimeReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpsAidPubTime", varargs...)
ret0, _ := ret[0].(*UpsAidPubTimeReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsAidPubTime indicates an expected call of UpsAidPubTime
func (mr *MockUpClientMockRecorder) UpsAidPubTime(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsAidPubTime", reflect.TypeOf((*MockUpClient)(nil).UpsAidPubTime), varargs...)
}
// AddUpPassedCacheByStaff mocks base method
func (m *MockUpClient) AddUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "AddUpPassedCacheByStaff", varargs...)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AddUpPassedCacheByStaff indicates an expected call of AddUpPassedCacheByStaff
func (mr *MockUpClientMockRecorder) AddUpPassedCacheByStaff(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUpPassedCacheByStaff", reflect.TypeOf((*MockUpClient)(nil).AddUpPassedCacheByStaff), varargs...)
}
// AddUpPassedCache mocks base method
func (m *MockUpClient) AddUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "AddUpPassedCache", varargs...)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AddUpPassedCache indicates an expected call of AddUpPassedCache
func (mr *MockUpClientMockRecorder) AddUpPassedCache(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUpPassedCache", reflect.TypeOf((*MockUpClient)(nil).AddUpPassedCache), varargs...)
}
// DelUpPassedCacheByStaff mocks base method
func (m *MockUpClient) DelUpPassedCacheByStaff(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "DelUpPassedCacheByStaff", varargs...)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DelUpPassedCacheByStaff indicates an expected call of DelUpPassedCacheByStaff
func (mr *MockUpClientMockRecorder) DelUpPassedCacheByStaff(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelUpPassedCacheByStaff", reflect.TypeOf((*MockUpClient)(nil).DelUpPassedCacheByStaff), varargs...)
}
// DelUpPassedCache mocks base method
func (m *MockUpClient) DelUpPassedCache(ctx context.Context, in *UpCacheReq, opts ...grpc.CallOption) (*NoReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "DelUpPassedCache", varargs...)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DelUpPassedCache indicates an expected call of DelUpPassedCache
func (mr *MockUpClientMockRecorder) DelUpPassedCache(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelUpPassedCache", reflect.TypeOf((*MockUpClient)(nil).DelUpPassedCache), varargs...)
}
// UpInfoActivitys mocks base method
func (m *MockUpClient) UpInfoActivitys(ctx context.Context, in *UpListByLastIDReq, opts ...grpc.CallOption) (*UpActivityListReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpInfoActivitys", varargs...)
ret0, _ := ret[0].(*UpActivityListReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpInfoActivitys indicates an expected call of UpInfoActivitys
func (mr *MockUpClientMockRecorder) UpInfoActivitys(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpInfoActivitys", reflect.TypeOf((*MockUpClient)(nil).UpInfoActivitys), varargs...)
}
// UpSpecial mocks base method
func (m *MockUpClient) UpSpecial(ctx context.Context, in *UpSpecialReq, opts ...grpc.CallOption) (*UpSpecialReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpSpecial", varargs...)
ret0, _ := ret[0].(*UpSpecialReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpSpecial indicates an expected call of UpSpecial
func (mr *MockUpClientMockRecorder) UpSpecial(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpSpecial", reflect.TypeOf((*MockUpClient)(nil).UpSpecial), varargs...)
}
// UpsSpecial mocks base method
func (m *MockUpClient) UpsSpecial(ctx context.Context, in *UpsSpecialReq, opts ...grpc.CallOption) (*UpsSpecialReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpsSpecial", varargs...)
ret0, _ := ret[0].(*UpsSpecialReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsSpecial indicates an expected call of UpsSpecial
func (mr *MockUpClientMockRecorder) UpsSpecial(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsSpecial", reflect.TypeOf((*MockUpClient)(nil).UpsSpecial), varargs...)
}
// UpGroups mocks base method
func (m *MockUpClient) UpGroups(ctx context.Context, in *NoArgReq, opts ...grpc.CallOption) (*UpGroupsReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpGroups", varargs...)
ret0, _ := ret[0].(*UpGroupsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpGroups indicates an expected call of UpGroups
func (mr *MockUpClientMockRecorder) UpGroups(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpGroups", reflect.TypeOf((*MockUpClient)(nil).UpGroups), varargs...)
}
// UpGroupMids mocks base method
func (m *MockUpClient) UpGroupMids(ctx context.Context, in *UpGroupMidsReq, opts ...grpc.CallOption) (*UpGroupMidsReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpGroupMids", varargs...)
ret0, _ := ret[0].(*UpGroupMidsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpGroupMids indicates an expected call of UpGroupMids
func (mr *MockUpClientMockRecorder) UpGroupMids(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpGroupMids", reflect.TypeOf((*MockUpClient)(nil).UpGroupMids), varargs...)
}
// UpAttr mocks base method
func (m *MockUpClient) UpAttr(ctx context.Context, in *UpAttrReq, opts ...grpc.CallOption) (*UpAttrReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpAttr", varargs...)
ret0, _ := ret[0].(*UpAttrReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpAttr indicates an expected call of UpAttr
func (mr *MockUpClientMockRecorder) UpAttr(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpAttr", reflect.TypeOf((*MockUpClient)(nil).UpAttr), varargs...)
}
// UpBaseStats mocks base method
func (m *MockUpClient) UpBaseStats(ctx context.Context, in *UpStatReq, opts ...grpc.CallOption) (*UpBaseStatReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpBaseStats", varargs...)
ret0, _ := ret[0].(*UpBaseStatReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpBaseStats indicates an expected call of UpBaseStats
func (mr *MockUpClientMockRecorder) UpBaseStats(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpBaseStats", reflect.TypeOf((*MockUpClient)(nil).UpBaseStats), varargs...)
}
// SetUpSwitch mocks base method
func (m *MockUpClient) SetUpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*NoReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetUpSwitch", varargs...)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// SetUpSwitch indicates an expected call of SetUpSwitch
func (mr *MockUpClientMockRecorder) SetUpSwitch(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUpSwitch", reflect.TypeOf((*MockUpClient)(nil).SetUpSwitch), varargs...)
}
// UpSwitch mocks base method
func (m *MockUpClient) UpSwitch(ctx context.Context, in *UpSwitchReq, opts ...grpc.CallOption) (*UpSwitchReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpSwitch", varargs...)
ret0, _ := ret[0].(*UpSwitchReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpSwitch indicates an expected call of UpSwitch
func (mr *MockUpClientMockRecorder) UpSwitch(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpSwitch", reflect.TypeOf((*MockUpClient)(nil).UpSwitch), varargs...)
}
// GetHighAllyUps mocks base method
func (m *MockUpClient) GetHighAllyUps(ctx context.Context, in *HighAllyUpsReq, opts ...grpc.CallOption) (*HighAllyUpsReply, error) {
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetHighAllyUps", varargs...)
ret0, _ := ret[0].(*HighAllyUpsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetHighAllyUps indicates an expected call of GetHighAllyUps
func (mr *MockUpClientMockRecorder) GetHighAllyUps(ctx, in interface{}, opts ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHighAllyUps", reflect.TypeOf((*MockUpClient)(nil).GetHighAllyUps), varargs...)
}
// MockUpServer is a mock of UpServer interface
type MockUpServer struct {
ctrl *gomock.Controller
recorder *MockUpServerMockRecorder
}
// MockUpServerMockRecorder is the mock recorder for MockUpServer
type MockUpServerMockRecorder struct {
mock *MockUpServer
}
// NewMockUpServer creates a new mock instance
func NewMockUpServer(ctrl *gomock.Controller) *MockUpServer {
mock := &MockUpServer{ctrl: ctrl}
mock.recorder = &MockUpServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockUpServer) EXPECT() *MockUpServerMockRecorder {
return m.recorder
}
// UpArcs mocks base method
func (m *MockUpServer) UpArcs(arg0 context.Context, arg1 *UpArcsReq) (*UpArcsReply, error) {
ret := m.ctrl.Call(m, "UpArcs", arg0, arg1)
ret0, _ := ret[0].(*UpArcsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpArcs indicates an expected call of UpArcs
func (mr *MockUpServerMockRecorder) UpArcs(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpArcs", reflect.TypeOf((*MockUpServer)(nil).UpArcs), arg0, arg1)
}
// UpsArcs mocks base method
func (m *MockUpServer) UpsArcs(arg0 context.Context, arg1 *UpsArcsReq) (*UpsArcsReply, error) {
ret := m.ctrl.Call(m, "UpsArcs", arg0, arg1)
ret0, _ := ret[0].(*UpsArcsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsArcs indicates an expected call of UpsArcs
func (mr *MockUpServerMockRecorder) UpsArcs(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsArcs", reflect.TypeOf((*MockUpServer)(nil).UpsArcs), arg0, arg1)
}
// UpCount mocks base method
func (m *MockUpServer) UpCount(arg0 context.Context, arg1 *UpCountReq) (*UpCountReply, error) {
ret := m.ctrl.Call(m, "UpCount", arg0, arg1)
ret0, _ := ret[0].(*UpCountReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpCount indicates an expected call of UpCount
func (mr *MockUpServerMockRecorder) UpCount(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpCount", reflect.TypeOf((*MockUpServer)(nil).UpCount), arg0, arg1)
}
// UpsCount mocks base method
func (m *MockUpServer) UpsCount(arg0 context.Context, arg1 *UpsCountReq) (*UpsCountReply, error) {
ret := m.ctrl.Call(m, "UpsCount", arg0, arg1)
ret0, _ := ret[0].(*UpsCountReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsCount indicates an expected call of UpsCount
func (mr *MockUpServerMockRecorder) UpsCount(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsCount", reflect.TypeOf((*MockUpServer)(nil).UpsCount), arg0, arg1)
}
// UpsAidPubTime mocks base method
func (m *MockUpServer) UpsAidPubTime(arg0 context.Context, arg1 *UpsArcsReq) (*UpsAidPubTimeReply, error) {
ret := m.ctrl.Call(m, "UpsAidPubTime", arg0, arg1)
ret0, _ := ret[0].(*UpsAidPubTimeReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsAidPubTime indicates an expected call of UpsAidPubTime
func (mr *MockUpServerMockRecorder) UpsAidPubTime(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsAidPubTime", reflect.TypeOf((*MockUpServer)(nil).UpsAidPubTime), arg0, arg1)
}
// AddUpPassedCacheByStaff mocks base method
func (m *MockUpServer) AddUpPassedCacheByStaff(arg0 context.Context, arg1 *UpCacheReq) (*NoReply, error) {
ret := m.ctrl.Call(m, "AddUpPassedCacheByStaff", arg0, arg1)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AddUpPassedCacheByStaff indicates an expected call of AddUpPassedCacheByStaff
func (mr *MockUpServerMockRecorder) AddUpPassedCacheByStaff(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUpPassedCacheByStaff", reflect.TypeOf((*MockUpServer)(nil).AddUpPassedCacheByStaff), arg0, arg1)
}
// AddUpPassedCache mocks base method
func (m *MockUpServer) AddUpPassedCache(arg0 context.Context, arg1 *UpCacheReq) (*NoReply, error) {
ret := m.ctrl.Call(m, "AddUpPassedCache", arg0, arg1)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AddUpPassedCache indicates an expected call of AddUpPassedCache
func (mr *MockUpServerMockRecorder) AddUpPassedCache(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUpPassedCache", reflect.TypeOf((*MockUpServer)(nil).AddUpPassedCache), arg0, arg1)
}
// DelUpPassedCacheByStaff mocks base method
func (m *MockUpServer) DelUpPassedCacheByStaff(arg0 context.Context, arg1 *UpCacheReq) (*NoReply, error) {
ret := m.ctrl.Call(m, "DelUpPassedCacheByStaff", arg0, arg1)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DelUpPassedCacheByStaff indicates an expected call of DelUpPassedCacheByStaff
func (mr *MockUpServerMockRecorder) DelUpPassedCacheByStaff(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelUpPassedCacheByStaff", reflect.TypeOf((*MockUpServer)(nil).DelUpPassedCacheByStaff), arg0, arg1)
}
// DelUpPassedCache mocks base method
func (m *MockUpServer) DelUpPassedCache(arg0 context.Context, arg1 *UpCacheReq) (*NoReply, error) {
ret := m.ctrl.Call(m, "DelUpPassedCache", arg0, arg1)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DelUpPassedCache indicates an expected call of DelUpPassedCache
func (mr *MockUpServerMockRecorder) DelUpPassedCache(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelUpPassedCache", reflect.TypeOf((*MockUpServer)(nil).DelUpPassedCache), arg0, arg1)
}
// UpInfoActivitys mocks base method
func (m *MockUpServer) UpInfoActivitys(arg0 context.Context, arg1 *UpListByLastIDReq) (*UpActivityListReply, error) {
ret := m.ctrl.Call(m, "UpInfoActivitys", arg0, arg1)
ret0, _ := ret[0].(*UpActivityListReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpInfoActivitys indicates an expected call of UpInfoActivitys
func (mr *MockUpServerMockRecorder) UpInfoActivitys(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpInfoActivitys", reflect.TypeOf((*MockUpServer)(nil).UpInfoActivitys), arg0, arg1)
}
// UpSpecial mocks base method
func (m *MockUpServer) UpSpecial(arg0 context.Context, arg1 *UpSpecialReq) (*UpSpecialReply, error) {
ret := m.ctrl.Call(m, "UpSpecial", arg0, arg1)
ret0, _ := ret[0].(*UpSpecialReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpSpecial indicates an expected call of UpSpecial
func (mr *MockUpServerMockRecorder) UpSpecial(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpSpecial", reflect.TypeOf((*MockUpServer)(nil).UpSpecial), arg0, arg1)
}
// UpsSpecial mocks base method
func (m *MockUpServer) UpsSpecial(arg0 context.Context, arg1 *UpsSpecialReq) (*UpsSpecialReply, error) {
ret := m.ctrl.Call(m, "UpsSpecial", arg0, arg1)
ret0, _ := ret[0].(*UpsSpecialReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpsSpecial indicates an expected call of UpsSpecial
func (mr *MockUpServerMockRecorder) UpsSpecial(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsSpecial", reflect.TypeOf((*MockUpServer)(nil).UpsSpecial), arg0, arg1)
}
// UpGroups mocks base method
func (m *MockUpServer) UpGroups(arg0 context.Context, arg1 *NoArgReq) (*UpGroupsReply, error) {
ret := m.ctrl.Call(m, "UpGroups", arg0, arg1)
ret0, _ := ret[0].(*UpGroupsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpGroups indicates an expected call of UpGroups
func (mr *MockUpServerMockRecorder) UpGroups(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpGroups", reflect.TypeOf((*MockUpServer)(nil).UpGroups), arg0, arg1)
}
// UpGroupMids mocks base method
func (m *MockUpServer) UpGroupMids(arg0 context.Context, arg1 *UpGroupMidsReq) (*UpGroupMidsReply, error) {
ret := m.ctrl.Call(m, "UpGroupMids", arg0, arg1)
ret0, _ := ret[0].(*UpGroupMidsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpGroupMids indicates an expected call of UpGroupMids
func (mr *MockUpServerMockRecorder) UpGroupMids(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpGroupMids", reflect.TypeOf((*MockUpServer)(nil).UpGroupMids), arg0, arg1)
}
// UpAttr mocks base method
func (m *MockUpServer) UpAttr(arg0 context.Context, arg1 *UpAttrReq) (*UpAttrReply, error) {
ret := m.ctrl.Call(m, "UpAttr", arg0, arg1)
ret0, _ := ret[0].(*UpAttrReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpAttr indicates an expected call of UpAttr
func (mr *MockUpServerMockRecorder) UpAttr(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpAttr", reflect.TypeOf((*MockUpServer)(nil).UpAttr), arg0, arg1)
}
// UpBaseStats mocks base method
func (m *MockUpServer) UpBaseStats(arg0 context.Context, arg1 *UpStatReq) (*UpBaseStatReply, error) {
ret := m.ctrl.Call(m, "UpBaseStats", arg0, arg1)
ret0, _ := ret[0].(*UpBaseStatReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpBaseStats indicates an expected call of UpBaseStats
func (mr *MockUpServerMockRecorder) UpBaseStats(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpBaseStats", reflect.TypeOf((*MockUpServer)(nil).UpBaseStats), arg0, arg1)
}
// SetUpSwitch mocks base method
func (m *MockUpServer) SetUpSwitch(arg0 context.Context, arg1 *UpSwitchReq) (*NoReply, error) {
ret := m.ctrl.Call(m, "SetUpSwitch", arg0, arg1)
ret0, _ := ret[0].(*NoReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// SetUpSwitch indicates an expected call of SetUpSwitch
func (mr *MockUpServerMockRecorder) SetUpSwitch(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUpSwitch", reflect.TypeOf((*MockUpServer)(nil).SetUpSwitch), arg0, arg1)
}
// UpSwitch mocks base method
func (m *MockUpServer) UpSwitch(arg0 context.Context, arg1 *UpSwitchReq) (*UpSwitchReply, error) {
ret := m.ctrl.Call(m, "UpSwitch", arg0, arg1)
ret0, _ := ret[0].(*UpSwitchReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// UpSwitch indicates an expected call of UpSwitch
func (mr *MockUpServerMockRecorder) UpSwitch(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpSwitch", reflect.TypeOf((*MockUpServer)(nil).UpSwitch), arg0, arg1)
}
// GetHighAllyUps mocks base method
func (m *MockUpServer) GetHighAllyUps(arg0 context.Context, arg1 *HighAllyUpsReq) (*HighAllyUpsReply, error) {
ret := m.ctrl.Call(m, "GetHighAllyUps", arg0, arg1)
ret0, _ := ret[0].(*HighAllyUpsReply)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetHighAllyUps indicates an expected call of GetHighAllyUps
func (mr *MockUpServerMockRecorder) GetHighAllyUps(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHighAllyUps", reflect.TypeOf((*MockUpServer)(nil).GetHighAllyUps), arg0, arg1)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,117 @@
syntax = "proto3";
package archive.service.up.v1;
import "app/service/main/archive/api/api.proto";
import "app/service/main/up/api/v1/archive.proto";
import "app/service/main/up/api/v1/up.proto";
import "app/service/main/up/api/v1/sign_up.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// NoReply 没有返回值
message NoReply {}
// UpArcsReply 单个up主的稿件信息列表返回值
message UpArcsReply {
// archives 稿件信息列表
repeated archive.service.v1.Arc archives = 1;
}
// UpsArcsReply 多个up主的稿件信息列表返回值
message UpsArcsReply {
// archives 稿件信息列表
map<int64, UpArcsReply> archives = 1;
}
// UpCountReply 单个up主的稿件计数返回值
message UpCountReply {
// count 稿件数量
int64 count = 1;
}
// UpsCountReply 多个up主的稿件计数返回值
message UpsCountReply {
// count 稿件数量
map<int64, int64> count = 1;
}
// UpAidPubTimeReply 按发布时间的单个up的稿件aid的返回值
message UpAidPubTimeReply {
// archives 稿件信息列表
repeated AidPubTime archives = 1;
}
// UpsAidPubTimeReply 按发布时间的多个up的稿件aid的返回值
message UpsAidPubTimeReply {
// archives 稿件信息列表
map<int64, UpAidPubTimeReply> archives = 1;
}
// UpActivityListReply up主活跃度列表信息
message UpActivityListReply {
// up_activity 活跃度up主信息列表
repeated UpActivity up_activitys = 1;
// last_id 数据最后返回的id
int64 last_id = 2 [(gogoproto.customname) = "LastID"];
}
// UpGroupsReply up主特殊用户组列表
message UpGroupsReply {
// up_groups up主的特殊用户组信息
map<int64, UpGroup> up_groups = 1;
}
// UpSpecialReply up主特殊属性信息
message UpSpecialReply {
// up_special up主的特殊属性
UpSpecial up_special = 1;
}
// UpsSpecialReply 多个up主特殊属性信息
message UpsSpecialReply {
// up_specials 多个up主的特殊属性
map<int64, UpSpecial> up_specials = 1;
}
// UpGroupMidsReply 获取某个分组下的所有用户的返回值
message UpGroupMidsReply {
// mids 分组下用户ID
repeated int64 mids = 1 [(gogoproto.jsontag) = "mids"];
int32 total = 2 [(gogoproto.jsontag) = "total", (gogoproto.casttype) = "int"];
}
// UpAttrReply 获取up主身份的返回值
message UpAttrReply {
// is_author 是否有身份 0:无身份 1:有身份
int32 is_author = 1
[(gogoproto.jsontag) = "is_author", (gogoproto.casttype) = "uint8"];
}
// UpBaseStatReply 获取up主基础计数的返回值
message UpBaseStatReply {
// view 播放数
int64 view = 1 [(gogoproto.jsontag) = "view"];
// reply 评论数
int64 reply = 2 [(gogoproto.jsontag) = "reply"];
// dm 弹幕数
int64 dm = 3 [(gogoproto.jsontag) = "dm"];
// fans 粉丝数
int64 fans = 4 [(gogoproto.jsontag) = "fans"];
// fav 收藏数
int64 fav = 5 [(gogoproto.jsontag) = "fav"];
// like 点赞数
int64 like = 6 [(gogoproto.jsontag) = "like"];
}
// UpSwitchReq 获取up主关注弹窗开关的返回值
message UpSwitchReply {
// state 开关状态 0-关闭 1-打开
int32 state = 1
[(gogoproto.jsontag) = "state", (gogoproto.casttype) = "uint8"];
}
// HighAllyUpsReply 高能联盟up主map返回值
message HighAllyUpsReply {
map<int64, SignUp> lists = 1;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,152 @@
syntax = "proto3";
package archive.service.up.v1;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// NoArgReq 没有请求参数
message NoArgReq {}
// UpArcsReq 单个up主的稿件列表信息请求参数
message UpArcsReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
// pn 第几页 非必传
int32 pn = 2 [(gogoproto.moretags) = "form:\"pn\" default:\"1\""];
// ps 分页大小 非必传
int32 ps = 3 [(gogoproto.moretags) = "form:\"ps\" default:\"20\""];
}
// UpsArcsReq 多个up主的稿件列表信息请求参数
message UpsArcsReq {
// mids 多个用户id 必传 最大100个
repeated int64 mids = 1
[(gogoproto.moretags) =
"form:\"mids,split\" validate:\"min=1,max=100,required\""];
// pn 第几页 非必传
int32 pn = 2 [(gogoproto.moretags) = "form:\"pn\" default:\"1\""];
// ps 分页大小 非必传
int32 ps = 3 [(gogoproto.moretags) = "form:\"ps\" default:\"20\""];
}
// UpCountReq 单个up主的稿件计数的请求参数
message UpCountReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
}
// UpsCountReq 多个up主的稿件计数的请求参数
message UpsCountReq {
// mids 多个用户id 必传 最大100个
repeated int64 mids = 1
[(gogoproto.moretags) =
"form:\"mids,split\" validate:\"min=1,max=100,required\""];
}
// UpCacheReq up主的cache更新的请求参数
message UpCacheReq {
// mid 用户id 必传
int64 mid = 1 [(gogoproto.moretags) = "form:\"mid\" validate:\"required\""];
// aid 稿件id 必传
int64 aid = 2 [(gogoproto.moretags) = "form:\"aid\" validate:\"required\""];
}
// UpListByLastIDReq 获取up主活跃度信息通过最后id获取
message UpListByLastIDReq {
// LastID 获取的数据最后id
int64 last_id = 1 [
(gogoproto.customname) = "LastID",
(gogoproto.moretags) = "form:\"last_id\" validate:\"min=0\""
];
// 获取数量 最大1000个
int32 ps = 2 [
(gogoproto.casttype) = "int",
(gogoproto.moretags) =
"form:\"ps\" validate:\"min=1,max=1000\" default:\"100\""
];
}
// UpSpecialReq up主特殊用户属性请求参数
message UpSpecialReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
}
// UpsSpecialReq 多个up主特殊用户属性请求参数
message UpsSpecialReq {
// mids 多个用户id 必传 最大100个
repeated int64 mids = 1
[(gogoproto.moretags) =
"form:\"mids,split\" validate:\"min=1,max=100,required\""];
}
// UpGroupMidsReq 获取某个分组下的所有用户的请求参数
message UpGroupMidsReq {
// GroupID 分组ID
int64 group_id = 1 [
(gogoproto.customname) = "GroupID",
(gogoproto.moretags) = "form:\"group_id\" validate:\"min=1,required\""
];
// pn 第几页 非必传
int32 pn = 2 [
(gogoproto.casttype) = "int",
(gogoproto.moretags) =
"form:\"pn\" validate:\"min=1,max=100\" default:\"1\""
];
// ps 分页大小 非必传
int32 ps = 3 [
(gogoproto.casttype) = "int",
(gogoproto.moretags) =
"form:\"ps\" validate:\"min=1,max=10000\" default:\"1000\""
];
}
// UpAttrReq 获取up主身份属性的请求参数
message UpAttrReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
// from 0 - 稿件作者(至少有一个通过稿件); 1 - 移动投稿作者(至少有一个稿件);
// 2 - live(直播up主); 3 - live(直播白名单)
int32 from = 2 [
(gogoproto.moretags) = "form:\"from\" validate:\"min=0,max=1\"",
(gogoproto.casttype) = "uint8"
];
}
// UpStatReq 获取up计数的请求参数
message UpStatReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
// date 获取计数时间范围
int64 date = 2 [
(gogoproto.moretags) = "form:\"date\"",
(gogoproto.casttype) = "go-common/library/time.Time"
];
}
// UpSwitchReq 获取up主关注弹窗开关的请求参数
message UpSwitchReq {
// mid 用户id 必传
int64 mid = 1
[(gogoproto.moretags) = "form:\"mid\" validate:\"min=1,required\""];
// from 业务来源 0-播放器关注开关 1-up主荣誉周报是否退订
int32 from = 2
[(gogoproto.moretags) = "form:\"from\"", (gogoproto.casttype) = "uint8"];
// state 开关状态 0-关闭 1-打开
int32 state = 3 [
(gogoproto.moretags) = "form:\"state\" validate:\"min=0,max=1\"",
(gogoproto.casttype) = "uint8"
];
}
// HighAllyUpReq 高能联盟up主请求参数
message HighAllyUpsReq {
// mids 用户id数组 必传
repeated int64 mids = 1 [(gogoproto.moretags) = "form:\"mids\" validate:\"required\""];
}

View File

@@ -0,0 +1,399 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: app/service/main/up/api/v1/sign_up.proto
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import go_common_library_time "go-common/library/time"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// SignUp 签约up
type SignUp struct {
// Mid 签约up主ID
Mid int64 `protobuf:"varint,1,opt,name=Mid,proto3" json:"mid"`
// State 签约状态
State int32 `protobuf:"varint,2,opt,name=State,proto3" json:"state"`
// BeginDate 经纪签约开始时间
BeginDate go_common_library_time.Time `protobuf:"varint,3,opt,name=BeginDate,proto3,casttype=go-common/library/time.Time" json:"begin_date"`
// EndDate 经纪签约结束时间
EndDate go_common_library_time.Time `protobuf:"varint,4,opt,name=EndDate,proto3,casttype=go-common/library/time.Time" json:"end_date"`
}
func (m *SignUp) Reset() { *m = SignUp{} }
func (m *SignUp) String() string { return proto.CompactTextString(m) }
func (*SignUp) ProtoMessage() {}
func (*SignUp) Descriptor() ([]byte, []int) { return fileDescriptorSignUp, []int{0} }
func (m *SignUp) GetMid() int64 {
if m != nil {
return m.Mid
}
return 0
}
func (m *SignUp) GetState() int32 {
if m != nil {
return m.State
}
return 0
}
func (m *SignUp) GetBeginDate() go_common_library_time.Time {
if m != nil {
return m.BeginDate
}
return 0
}
func (m *SignUp) GetEndDate() go_common_library_time.Time {
if m != nil {
return m.EndDate
}
return 0
}
func init() {
proto.RegisterType((*SignUp)(nil), "archive.service.up.v1.SignUp")
}
func (m *SignUp) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *SignUp) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Mid != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintSignUp(dAtA, i, uint64(m.Mid))
}
if m.State != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintSignUp(dAtA, i, uint64(m.State))
}
if m.BeginDate != 0 {
dAtA[i] = 0x18
i++
i = encodeVarintSignUp(dAtA, i, uint64(m.BeginDate))
}
if m.EndDate != 0 {
dAtA[i] = 0x20
i++
i = encodeVarintSignUp(dAtA, i, uint64(m.EndDate))
}
return i, nil
}
func encodeVarintSignUp(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *SignUp) Size() (n int) {
var l int
_ = l
if m.Mid != 0 {
n += 1 + sovSignUp(uint64(m.Mid))
}
if m.State != 0 {
n += 1 + sovSignUp(uint64(m.State))
}
if m.BeginDate != 0 {
n += 1 + sovSignUp(uint64(m.BeginDate))
}
if m.EndDate != 0 {
n += 1 + sovSignUp(uint64(m.EndDate))
}
return n
}
func sovSignUp(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozSignUp(x uint64) (n int) {
return sovSignUp(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *SignUp) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSignUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: SignUp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: SignUp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Mid", wireType)
}
m.Mid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSignUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Mid |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field State", wireType)
}
m.State = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSignUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.State |= (int32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field BeginDate", wireType)
}
m.BeginDate = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSignUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.BeginDate |= (go_common_library_time.Time(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 4:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field EndDate", wireType)
}
m.EndDate = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSignUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.EndDate |= (go_common_library_time.Time(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipSignUp(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthSignUp
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipSignUp(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSignUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSignUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSignUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthSignUp
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSignUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipSignUp(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthSignUp = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowSignUp = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("app/service/main/up/api/v1/sign_up.proto", fileDescriptorSignUp) }
var fileDescriptorSignUp = []byte{
// 280 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x8f, 0xbf, 0x4a, 0xf4, 0x40,
0x14, 0xc5, 0x99, 0xcd, 0xb7, 0xbb, 0xdf, 0x4e, 0x25, 0x01, 0x61, 0x55, 0xc8, 0x2c, 0x56, 0x01,
0xc9, 0x0c, 0xc1, 0x37, 0x08, 0x6e, 0x25, 0x36, 0x59, 0x6d, 0x6c, 0x96, 0x49, 0x32, 0xce, 0x5e,
0x70, 0xfe, 0x90, 0x4c, 0x02, 0xbe, 0xa1, 0xa5, 0xa5, 0x55, 0x90, 0x94, 0x79, 0x04, 0x2b, 0xc9,
0xac, 0x62, 0x6b, 0x77, 0xcf, 0x8f, 0x73, 0x7e, 0x70, 0x71, 0xcc, 0xad, 0x65, 0x8d, 0xa8, 0x3b,
0x28, 0x05, 0x53, 0x1c, 0x34, 0x6b, 0x2d, 0xe3, 0x16, 0x58, 0x97, 0xb2, 0x06, 0xa4, 0xde, 0xb7,
0x96, 0xda, 0xda, 0x38, 0x13, 0x9e, 0xf2, 0xba, 0x3c, 0x40, 0x27, 0xe8, 0x77, 0x9b, 0xb6, 0x96,
0x76, 0xe9, 0x79, 0x22, 0xc1, 0x1d, 0xda, 0x82, 0x96, 0x46, 0x31, 0x69, 0xa4, 0x61, 0xbe, 0x5d,
0xb4, 0x4f, 0x3e, 0xf9, 0xe0, 0xaf, 0xa3, 0xe5, 0xf2, 0x1d, 0xe1, 0xc5, 0x0e, 0xa4, 0x7e, 0xb0,
0xe1, 0x19, 0x0e, 0xee, 0xa0, 0x5a, 0xa3, 0x0d, 0x8a, 0x83, 0x6c, 0x39, 0xf6, 0x24, 0x50, 0x50,
0xe5, 0x13, 0x0b, 0x09, 0x9e, 0xef, 0x1c, 0x77, 0x62, 0x3d, 0xdb, 0xa0, 0x78, 0x9e, 0xad, 0xc6,
0x9e, 0xcc, 0x9b, 0x09, 0xe4, 0x47, 0x1e, 0xde, 0xe2, 0x55, 0x26, 0x24, 0xe8, 0x9b, 0xa9, 0x14,
0x78, 0x43, 0x32, 0xf6, 0x04, 0x17, 0x13, 0xdc, 0x57, 0xdc, 0x89, 0xcf, 0x9e, 0x5c, 0x48, 0x93,
0x94, 0x46, 0x29, 0xa3, 0xd9, 0x33, 0x14, 0x35, 0xaf, 0x5f, 0x98, 0x03, 0x25, 0xe8, 0x3d, 0x28,
0x91, 0xff, 0xee, 0xc3, 0x2d, 0x5e, 0x6e, 0x75, 0xe5, 0x55, 0xff, 0xbc, 0xea, 0x6a, 0xec, 0xc9,
0x7f, 0xa1, 0xab, 0x3f, 0x89, 0x7e, 0xb6, 0xd9, 0xc9, 0xeb, 0x10, 0xa1, 0xb7, 0x21, 0x42, 0x1f,
0x43, 0x84, 0x1e, 0x67, 0x5d, 0x5a, 0x2c, 0xfc, 0xcf, 0xd7, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff,
0xae, 0xdc, 0x75, 0xf6, 0x65, 0x01, 0x00, 0x00,
}

View File

@@ -0,0 +1,18 @@
syntax = "proto3";
package archive.service.up.v1;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// SignUp 签约up
message SignUp {
// Mid 签约up主ID
int64 Mid = 1 [(gogoproto.jsontag) = "mid"];
// State 签约状态
int32 State = 2 [(gogoproto.jsontag) = "state"];
// BeginDate 经纪签约开始时间
int64 BeginDate = 3 [(gogoproto.jsontag) = "begin_date", (gogoproto.casttype) = "go-common/library/time.Time"];
// EndDate 经纪签约结束时间
int64 EndDate = 4 [(gogoproto.jsontag) = "end_date", (gogoproto.casttype) = "go-common/library/time.Time"];
}

View File

@@ -0,0 +1,920 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: app/service/main/up/api/v1/up.proto
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// UpActivity up主活跃度信息
type UpActivity struct {
// mid up主id
Mid int64 `protobuf:"varint,1,opt,name=mid,proto3" json:"mid"`
// activity 活跃度
Activity int8 `protobuf:"varint,2,opt,name=activity,proto3,casttype=int8" json:"activity"`
}
func (m *UpActivity) Reset() { *m = UpActivity{} }
func (m *UpActivity) String() string { return proto.CompactTextString(m) }
func (*UpActivity) ProtoMessage() {}
func (*UpActivity) Descriptor() ([]byte, []int) { return fileDescriptorUp, []int{0} }
func (m *UpActivity) GetMid() int64 {
if m != nil {
return m.Mid
}
return 0
}
func (m *UpActivity) GetActivity() int8 {
if m != nil {
return m.Activity
}
return 0
}
// UpGroup up主的特殊用户组信息
type UpGroup struct {
// id 分组ID
ID int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id"`
// name 分组名
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name"`
// tag 标签名称
Tag string `protobuf:"bytes,3,opt,name=tag,proto3" json:"tag"`
// tag 标签简称
ShortTag string `protobuf:"bytes,4,opt,name=short_tag,json=shortTag,proto3" json:"short_tag"`
// font_color 字体色
FontColor string `protobuf:"bytes,5,opt,name=font_color,json=fontColor,proto3" json:"font_color"`
// bg_color 背景色
BgColor string `protobuf:"bytes,6,opt,name=bg_color,json=bgColor,proto3" json:"bg_color"`
// note 备注
Note string `protobuf:"bytes,7,opt,name=note,proto3" json:"note"`
}
func (m *UpGroup) Reset() { *m = UpGroup{} }
func (m *UpGroup) String() string { return proto.CompactTextString(m) }
func (*UpGroup) ProtoMessage() {}
func (*UpGroup) Descriptor() ([]byte, []int) { return fileDescriptorUp, []int{1} }
func (m *UpGroup) GetID() int64 {
if m != nil {
return m.ID
}
return 0
}
func (m *UpGroup) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *UpGroup) GetTag() string {
if m != nil {
return m.Tag
}
return ""
}
func (m *UpGroup) GetShortTag() string {
if m != nil {
return m.ShortTag
}
return ""
}
func (m *UpGroup) GetFontColor() string {
if m != nil {
return m.FontColor
}
return ""
}
func (m *UpGroup) GetBgColor() string {
if m != nil {
return m.BgColor
}
return ""
}
func (m *UpGroup) GetNote() string {
if m != nil {
return m.Note
}
return ""
}
// UpSpecial up主的特殊属性
type UpSpecial struct {
// group_ids 特殊属性数组
GroupIDs []int64 `protobuf:"varint,1,rep,packed,name=group_ids,json=groupIds" json:"group_ids"`
}
func (m *UpSpecial) Reset() { *m = UpSpecial{} }
func (m *UpSpecial) String() string { return proto.CompactTextString(m) }
func (*UpSpecial) ProtoMessage() {}
func (*UpSpecial) Descriptor() ([]byte, []int) { return fileDescriptorUp, []int{2} }
func (m *UpSpecial) GetGroupIDs() []int64 {
if m != nil {
return m.GroupIDs
}
return nil
}
func init() {
proto.RegisterType((*UpActivity)(nil), "archive.service.up.v1.UpActivity")
proto.RegisterType((*UpGroup)(nil), "archive.service.up.v1.UpGroup")
proto.RegisterType((*UpSpecial)(nil), "archive.service.up.v1.UpSpecial")
}
func (m *UpActivity) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *UpActivity) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Mid != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintUp(dAtA, i, uint64(m.Mid))
}
if m.Activity != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintUp(dAtA, i, uint64(m.Activity))
}
return i, nil
}
func (m *UpGroup) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *UpGroup) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.ID != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintUp(dAtA, i, uint64(m.ID))
}
if len(m.Name) > 0 {
dAtA[i] = 0x12
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.Name)))
i += copy(dAtA[i:], m.Name)
}
if len(m.Tag) > 0 {
dAtA[i] = 0x1a
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.Tag)))
i += copy(dAtA[i:], m.Tag)
}
if len(m.ShortTag) > 0 {
dAtA[i] = 0x22
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.ShortTag)))
i += copy(dAtA[i:], m.ShortTag)
}
if len(m.FontColor) > 0 {
dAtA[i] = 0x2a
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.FontColor)))
i += copy(dAtA[i:], m.FontColor)
}
if len(m.BgColor) > 0 {
dAtA[i] = 0x32
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.BgColor)))
i += copy(dAtA[i:], m.BgColor)
}
if len(m.Note) > 0 {
dAtA[i] = 0x3a
i++
i = encodeVarintUp(dAtA, i, uint64(len(m.Note)))
i += copy(dAtA[i:], m.Note)
}
return i, nil
}
func (m *UpSpecial) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *UpSpecial) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if len(m.GroupIDs) > 0 {
dAtA2 := make([]byte, len(m.GroupIDs)*10)
var j1 int
for _, num1 := range m.GroupIDs {
num := uint64(num1)
for num >= 1<<7 {
dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80)
num >>= 7
j1++
}
dAtA2[j1] = uint8(num)
j1++
}
dAtA[i] = 0xa
i++
i = encodeVarintUp(dAtA, i, uint64(j1))
i += copy(dAtA[i:], dAtA2[:j1])
}
return i, nil
}
func encodeVarintUp(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *UpActivity) Size() (n int) {
var l int
_ = l
if m.Mid != 0 {
n += 1 + sovUp(uint64(m.Mid))
}
if m.Activity != 0 {
n += 1 + sovUp(uint64(m.Activity))
}
return n
}
func (m *UpGroup) Size() (n int) {
var l int
_ = l
if m.ID != 0 {
n += 1 + sovUp(uint64(m.ID))
}
l = len(m.Name)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
l = len(m.Tag)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
l = len(m.ShortTag)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
l = len(m.FontColor)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
l = len(m.BgColor)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
l = len(m.Note)
if l > 0 {
n += 1 + l + sovUp(uint64(l))
}
return n
}
func (m *UpSpecial) Size() (n int) {
var l int
_ = l
if len(m.GroupIDs) > 0 {
l = 0
for _, e := range m.GroupIDs {
l += sovUp(uint64(e))
}
n += 1 + sovUp(uint64(l)) + l
}
return n
}
func sovUp(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozUp(x uint64) (n int) {
return sovUp(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *UpActivity) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: UpActivity: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: UpActivity: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Mid", wireType)
}
m.Mid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Mid |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Activity", wireType)
}
m.Activity = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Activity |= (int8(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipUp(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthUp
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *UpGroup) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: UpGroup: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: UpGroup: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType)
}
m.ID = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.ID |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Tag", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Tag = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ShortTag", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ShortTag = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field FontColor", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.FontColor = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BgColor", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.BgColor = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 7:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Note", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Note = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipUp(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthUp
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *UpSpecial) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: UpSpecial: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: UpSpecial: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType == 0 {
var v int64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
m.GroupIDs = append(m.GroupIDs, v)
} else if wireType == 2 {
var packedLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
packedLen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if packedLen < 0 {
return ErrInvalidLengthUp
}
postIndex := iNdEx + packedLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
for iNdEx < postIndex {
var v int64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowUp
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
m.GroupIDs = append(m.GroupIDs, v)
}
} else {
return fmt.Errorf("proto: wrong wireType = %d for field GroupIDs", wireType)
}
default:
iNdEx = preIndex
skippy, err := skipUp(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthUp
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipUp(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthUp
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowUp
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipUp(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthUp = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowUp = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("app/service/main/up/api/v1/up.proto", fileDescriptorUp) }
var fileDescriptorUp = []byte{
// 397 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0x4f, 0x8b, 0xd4, 0x30,
0x18, 0xc6, 0x69, 0x3b, 0xbb, 0x6d, 0xc3, 0x2a, 0x12, 0x14, 0xba, 0xb2, 0x4c, 0x86, 0xf1, 0xe0,
0x20, 0x6c, 0xe3, 0x20, 0x88, 0x57, 0xbb, 0x0b, 0x32, 0xd7, 0xe8, 0x1c, 0xf4, 0x32, 0xa4, 0x7f,
0x36, 0x13, 0xd8, 0x36, 0xa1, 0x4d, 0x0b, 0x5e, 0xfd, 0x74, 0x1e, 0xfd, 0x04, 0x41, 0x7a, 0xec,
0x47, 0xf0, 0x24, 0x79, 0x77, 0xac, 0x7b, 0x79, 0x79, 0x9e, 0xa7, 0x3f, 0x5e, 0x9e, 0xbe, 0x41,
0xaf, 0xb8, 0xd6, 0xb4, 0xab, 0xda, 0x41, 0x16, 0x15, 0xad, 0xb9, 0x6c, 0x68, 0xaf, 0x29, 0xd7,
0x92, 0x0e, 0x5b, 0xda, 0xeb, 0x54, 0xb7, 0xca, 0x28, 0xfc, 0x82, 0xb7, 0xc5, 0x51, 0x0e, 0x55,
0x7a, 0x02, 0xd3, 0x5e, 0xa7, 0xc3, 0xf6, 0xe5, 0xb5, 0x90, 0xe6, 0xd8, 0xe7, 0x69, 0xa1, 0x6a,
0x2a, 0x94, 0x50, 0x14, 0xe8, 0xbc, 0xbf, 0x03, 0x07, 0x06, 0xd4, 0xc3, 0x96, 0xf5, 0x57, 0x84,
0xf6, 0xfa, 0x63, 0x61, 0xe4, 0x20, 0xcd, 0x77, 0x7c, 0x89, 0x82, 0x5a, 0x96, 0x89, 0xb7, 0xf2,
0x36, 0x41, 0x16, 0x4e, 0x96, 0x38, 0xcb, 0xdc, 0xc0, 0x6f, 0x51, 0xc4, 0x4f, 0x58, 0xe2, 0xaf,
0xbc, 0xcd, 0x59, 0xf6, 0x7c, 0xb2, 0x64, 0xce, 0xfe, 0x58, 0xb2, 0x90, 0x8d, 0xf9, 0xc0, 0xe6,
0x64, 0xfd, 0xc3, 0x47, 0xe1, 0x5e, 0x7f, 0x6a, 0x55, 0xaf, 0xf1, 0x15, 0xf2, 0xe7, 0xbd, 0x17,
0xa3, 0x25, 0xfe, 0xee, 0x76, 0xb2, 0xc4, 0x97, 0x25, 0xf3, 0x65, 0x89, 0xaf, 0xd0, 0xa2, 0xe1,
0x75, 0x05, 0x7b, 0xe3, 0x2c, 0x9a, 0x2c, 0x01, 0xcf, 0x60, 0xba, 0x52, 0x86, 0x8b, 0x24, 0x80,
0x8f, 0x50, 0xca, 0x70, 0xc1, 0xdc, 0xc0, 0x6f, 0x50, 0xdc, 0x1d, 0x55, 0x6b, 0x0e, 0x0e, 0x58,
0x00, 0xf0, 0x64, 0xb2, 0xe4, 0x7f, 0xc8, 0x22, 0x90, 0x5f, 0xb8, 0xc0, 0xd7, 0x08, 0xdd, 0xa9,
0xc6, 0x1c, 0x0a, 0x75, 0xaf, 0xda, 0xe4, 0x0c, 0xe0, 0xa7, 0x93, 0x25, 0x8f, 0x52, 0x16, 0x3b,
0x7d, 0xe3, 0x24, 0x7e, 0x8d, 0xa2, 0x5c, 0x9c, 0xe0, 0x73, 0x80, 0x2f, 0xdc, 0xff, 0xfe, 0xcb,
0x58, 0x98, 0x8b, 0x07, 0xd0, 0x95, 0x57, 0xa6, 0x4a, 0xc2, 0x47, 0xe5, 0x95, 0x71, 0xe5, 0x95,
0xa9, 0xd6, 0x37, 0x28, 0xde, 0xeb, 0xcf, 0xba, 0x2a, 0x24, 0xbf, 0xc7, 0xef, 0x51, 0x2c, 0xdc,
0x39, 0x0e, 0xb2, 0xec, 0x12, 0x6f, 0x15, 0x6c, 0x82, 0xec, 0x72, 0xb4, 0x24, 0x82, 0x1b, 0xed,
0x6e, 0x3b, 0x57, 0x7d, 0x06, 0x58, 0x04, 0x72, 0x57, 0x76, 0xd9, 0xb3, 0x9f, 0xe3, 0xd2, 0xfb,
0x35, 0x2e, 0xbd, 0xdf, 0xe3, 0xd2, 0xfb, 0xe6, 0x0f, 0xdb, 0xfc, 0x1c, 0x5e, 0xef, 0xdd, 0xdf,
0x00, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x8e, 0x29, 0xd2, 0x2a, 0x02, 0x00, 0x00,
}

View File

@@ -0,0 +1,40 @@
syntax = "proto3";
package archive.service.up.v1;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "v1";
// UpActivity up主活跃度信息
message UpActivity {
// mid up主id
int64 mid = 1 [(gogoproto.jsontag) = "mid"];
// activity 活跃度
int32 activity = 2
[(gogoproto.jsontag) = "activity", (gogoproto.casttype) = "int8"];
}
// UpGroup up主的特殊用户组信息
message UpGroup {
// id 分组ID
int64 id = 1 [(gogoproto.jsontag) = "id", (gogoproto.customname) = "ID"];
// name 分组名
string name = 2 [(gogoproto.jsontag) = "name"];
// tag 标签名称
string tag = 3 [(gogoproto.jsontag) = "tag"];
// tag 标签简称
string short_tag = 4 [(gogoproto.jsontag) = "short_tag"];
// font_color 字体色
string font_color = 5 [(gogoproto.jsontag) = "font_color"];
// bg_color 背景色
string bg_color = 6 [(gogoproto.jsontag) = "bg_color"];
// note 备注
string note = 7 [(gogoproto.jsontag) = "note"];
}
// UpSpecial up主的特殊属性
message UpSpecial {
// group_ids 特殊属性数组
repeated int64 group_ids = 1
[(gogoproto.jsontag) = "group_ids", (gogoproto.customname) = "GroupIDs"];
}

View File

@@ -0,0 +1,47 @@
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 = ["up-service.toml"],
importpath = "go-common/app/service/main/up/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/server/gorpc:go_default_library",
"//app/service/main/up/server/grpc:go_default_library",
"//app/service/main/up/server/http:go_default_library",
"//app/service/main/up/service:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/trace:go_default_library",
"//library/queue/databus/report: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,62 @@
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/server/gorpc"
"go-common/app/service/main/up/server/grpc"
"go-common/app/service/main/up/server/http"
"go-common/app/service/main/up/service"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
"go-common/library/queue/databus/report"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
log.Error("conf.Init() error(%v)", err)
panic(err)
}
// init log
log.Init(conf.Conf.Xlog)
trace.Init(conf.Conf.Tracer)
defer trace.Close()
defer log.Close()
log.SetFormat("[%D %T] [%L] [%S] %M")
log.Info("up-servicestart")
svr := service.New(conf.Conf)
ecode.Init(conf.Conf.Ecode)
// service init
http.Init(conf.Conf, svr)
rpcSvr := gorpc.New(conf.Conf, svr)
grpcSvr := grpc.New(conf.Conf.GRPCServer, svr)
report.InitManager(conf.Conf.ManagerReport)
// init signal
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("up-service get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
rpcSvr.Close()
grpcSvr.Shutdown(context.TODO())
time.Sleep(time.Second * 2)
svr.Close()
log.Info("up-service exit")
return
case syscall.SIGHUP:
// TODO reload
default:
return
}
}
}

View File

@@ -0,0 +1,326 @@
# This is a TOML document. Boom.
consume = false
istest = true
[app]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
[host]
api = "http://uat-api.bilibili.co"
live = "http://uat-api.vc.bilibili.co"
search = "http://uat-bili-search.bilibili.co"
manager = "http://uat-manager.bilibili.co"
[xlog]
stdout = true
[statsd]
project = "up-service"
addr = "172.18.20.15:8200"
chanSize = 10240
[httpClient]
[httpClient.normal]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
dial = "500ms"
timeout = "1s"
keepAlive = "60s"
timer = 10
[httpClient.normal.breaker]
window = "10s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[httpClient.slow]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
dial = "1s"
timeout = "10s"
keepAlive = "60s"
timer = 10
[httpClient.slow.breaker]
window = "10s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[bm]
[bm.inner]
addr = "0.0.0.0:7441"
maxListen = 1000
timeout = "1s"
[bm.local]
addr = "0.0.0.0:7442"
maxListen = 100
timeout = "1s"
[db]
[db.creative]
name = "[creative]tcp@172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_creative?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 5
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "5s"
[db.creative.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.archive]
name = "[archive]tcp@172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_archive?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 5
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "5s"
[db.archive.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.arcResult]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/archive_result?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 1
idleTimeout = "4h"
queryTimeout = "150ms"
execTimeout = "100ms"
tranTimeout = "200ms"
[db.arcResult.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.manager]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_manager?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.manager.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.upcrm]
name = "172.16.33.205:3306"
dsn = "upcrm:DdL6c5JaWCYKMAQ10PURbfeImow9HXlx@tcp(172.16.33.205:3306)/bilibili_upcrm?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.upcrm.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[accountRPC]
timeout = "30s"
[articleRPC]
timeout = "30s"
[ArchiveRPC]
timeout = "30s"
[GRPCClient]
[GRPCClient.Archive]
timeout = "30s"
[GRPCClient.Account]
timeout = "30s"
[identify]
whiteAccessKey = ""
whiteMid = 0
csrf = false
[identify.app]
key = "53e2fa226f5ad348"
secret = "3cf6bd1b0ff671021da5f424fea4b04a"
[identify.memcache]
name = "go-business/identify"
proto = "tcp"
addr = "172.18.33.60:11214"
active = 10
idle = 5
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "80s"
[identify.host]
auth = "http://uat-passport.bilibili.com"
secret = "http://uat-open.bilibili.com"
[identify.httpClient]
key = "53e2fa226f5ad348"
secret = "3cf6bd1b0ff671021da5f424fea4b04a"
dial = "500ms"
timeout = "800ms"
keepAlive = "60s"
[identify.httpClient.breaker]
window = "10s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[identify.httpClient.url]
"http://uat-passport.bilibili.co/intranet/auth/tokenInfo" = {timeout = "100ms"}
"http://uat-passport.bilibili.co/intranet/auth/cookieInfo" = {timeout = "100ms"}
"http://uat-open.bilibili.co/api/getsecret" = {timeout = "500ms"}
[upSub]
key = "4c76cbb7a985ac90"
secret = "43bb22ce34a6b13e7814f09cb8116522"
addr = "172.16.33.158:6205"
group = "Creative-MainArchive-S"
topic = "Creative-T"
action = "sub"
offset = "old"
buffer = 128
name = "up-service/sub"
proto = "tcp"
idle = 10
active = 100
dialTimeout = "5s"
readTimeout = "6s"
writeTimeout = "5s"
idleTimeout = "10s"
upChanSize = 1024
consumeLimit = 10 #消费速率控制
routineLimit = 10 #消费协程控制
SpecialAddDBLimit = 100 # 100每秒
[monitor]
moni="http://moni.bilibili.co/dashboard/db/databus?orgId=1"
host = "http://bap.bilibili.co"
username="fengpengfei"
appToken = "jLgSvndTeranxGMN"
appSecret = "CcCdlEBYqxqrgAieJuFVZUsgPmweLRms"
intervalAlarm = "5m"
[memcache]
upExpire = "1800s"
upSpecialExpire = "300s"
[memcache.up]
name = "up-service"
proto = "tcp"
addr = "172.18.33.60:11216"
active = 10
idle = 5
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "80s"
[redis]
[redis.up]
name = "up-service/up"
proto = "tcp"
addr = "172.18.33.60:6893"
idle = 1
active = 5
dialTimeout = "100ms"
readTimeout = "200ms"
writeTimeout = "200ms"
idleTimeout = "80s"
upExpire = "480h"
[rpcServer2]
discoverOff = false
token = "123456"
[[rpcServer2.servers]]
proto = "tcp"
addr = "0.0.0.0:6079"
weight = 10
group = "test"
[rpcServer2.zookeeper]
root = "/microservice/up-service/"
addrs = ["172.18.33.50:2199","172.18.33.51:2199","172.18.33.52:2199"]
timeout = "1s"
[logCli]
family = "up-service"
taskID = "000293"
proto = "unixgram"
addr = "/var/run/lancer/collector.sock"
chan = 10240
[auth]
managerHost = "http://uat-manager.bilibili.co"
dashboardHost = "http://dashboard-mng.bilibili.co"
dashboardCaller = "manager-go"
[auth.DsHTTPClient]
key = "manager-go"
secret = "949bbb2dd3178252638c2407578bc7ad"
dial = "1s"
timeout = "1s"
keepAlive = "60s"
[auth.DsHTTPClient.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[auth.MaHTTPClient]
key = "f6433799dbd88751"
secret = "36f8ddb1806207fe07013ab6a77a3935"
dial = "1s"
timeout = "1s"
keepAlive = "60s"
[auth.MaHTTPClient.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[auth.session]
sessionIDLength = 32
cookieLifeTime = 1800
cookieName = "mng-go"
domain = ".bilibili.co"
[auth.session.Memcache]
name = "go-business/auth"
proto = "unix"
addr = "/tmp/uat-manager-auth-mc.sock"
active = 10
idle = 5
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "80s"
[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"

View File

@@ -0,0 +1,45 @@
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/main/up/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/conf:go_default_library",
"//library/database/hbase.v2:go_default_library",
"//library/database/sql: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/permit:go_default_library",
"//library/net/rpc:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/net/trace:go_default_library",
"//library/queue/databus:go_default_library",
"//library/time: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,216 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/sql"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/permit"
"go-common/library/net/rpc"
"go-common/library/net/rpc/warden"
"go-common/library/net/trace"
"go-common/library/queue/databus"
"go-common/library/time"
"go-common/library/database/hbase.v2"
"github.com/BurntSushi/toml"
)
// Conf info.
var (
ConfPath string
Conf = &Config{}
client *conf.Client
)
// Config struct.
type Config struct {
// bm
BM *HTTPServers
// db
DB *DB
// base
// elk
Xlog *log.Config
// httpClinet
HTTPClient *HTTPClient
// tracer
Tracer *trace.Config
// Ecode
Ecode *ecode.Config
// host
Host *Host
// ArchStatus
ArchStatus map[string]string
// Redis
Redis *Redis
// Databus
Env string
Consume bool
IsTest bool
UpSub *upSub
ChanSize int64
Monitor *Monitor
// rpc client2
ArticleRPC *rpc.ClientConfig
// identify
App *blademaster.App
Memcache *MC
//API HOST
API string
Live string
// rpc server
RPCServer *rpc.ServerConfig
GRPCServer *warden.ServerConfig
// auth
Auth *permit.Config
// hbase
HBase *HBaseConfig
// Manager
ManagerReport *databus.Config
// GRPCClient
GRPCClient *GRPC
}
// HBaseConfig combine with hbase.Config add ReadTimeout, WriteTimeout
type HBaseConfig struct {
hbase.Config
// extra config
ReadTimeout time.Duration
ReadsTimeout time.Duration
WriteTimeout time.Duration
WritesTimeout time.Duration
}
//UpSub upsub config
type upSub struct {
*databus.Config
UpChanSize int
ConsumeLimit int
RoutineLimit int
SpecialAddDBLimit int
}
// GRPC .
type GRPC struct {
Archive *warden.ClientConfig
Account *warden.ClientConfig
}
//HTTPServers for http server.
type HTTPServers struct {
Inner *blademaster.ServerConfig
}
// DB conf.
type DB struct {
// Creative db
Creative *sql.Config
Manager *sql.Config
UpCRM *sql.Config
ArcResult *sql.Config
Archive *sql.Config
}
// Redis redis config
type Redis struct {
Up *struct {
*redis.Config
UpExpire time.Duration
}
}
// HTTPClient conf.
type HTTPClient struct {
Normal *blademaster.ClientConfig
Slow *blademaster.ClientConfig
}
// Host conf.
type Host struct {
API string
Live string
Search string
Manager string
}
// Monitor conf.
type Monitor struct {
Host string
Moni string
UserName string
AppSecret string
AppToken string
IntervalAlarm time.Duration
}
//App for key secret.
type App struct {
Key string
Secret string
}
//MC memcache
type MC struct {
UpExpire time.Duration
UpSpecialExpire time.Duration
Up *memcache.Config
}
func init() {
flag.StringVar(&ConfPath, "conf", "", "default config path")
}
// Init conf.
func Init() (err 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 (
tomlStr string
ok bool
tmpConf *Config
)
if tomlStr, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(tomlStr, &tmpConf); err != nil {
return errors.New("could not decode toml config")
}
*Conf = *tmpConf
return
}

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 = ["utils_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//vendor/github.com/smartystreets/goconvey/convey:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["utils.go"],
importpath = "go-common/app/service/main/up/dao",
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/main/up/dao/archive:all-srcs",
"//app/service/main/up/dao/card:all-srcs",
"//app/service/main/up/dao/data:all-srcs",
"//app/service/main/up/dao/global:all-srcs",
"//app/service/main/up/dao/manager:all-srcs",
"//app/service/main/up/dao/monitor:all-srcs",
"//app/service/main/up/dao/up:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,64 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"archive_test.go",
"dao_test.go",
"upper_rds_test.go",
"upper_staff_test.go",
"upper_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"dao.go",
"upper.go",
"upper_rds.go",
"upper_staff.go",
],
importpath = "go-common/app/service/main/up/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/stat/prom:go_default_library",
"//library/time:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/pkg/errors: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,45 @@
package archive
import (
"context"
"fmt"
"go-common/app/service/main/up/model"
"go-common/library/database/sql"
"go-common/library/time"
"go-common/library/xstr"
)
const (
_arcsAidsSQL = "SELECT aid,pubtime,copyright FROM archive WHERE aid IN (%s) AND state>=0 ORDER BY pubtime DESC"
)
// ArcsAids get archives by aids.
func (d *Dao) ArcsAids(c context.Context, ids []int64) (aids []int64, ptimes []time.Time, copyrights []int8, aptm map[int64]*model.AidPubTime, err error) {
d.infoProm.Incr("ArcAids")
rows, err := d.resultDB.Query(c, fmt.Sprintf(_arcsAidsSQL, xstr.JoinInts(ids)))
if err != nil {
return
}
defer rows.Close()
aptm = make(map[int64]*model.AidPubTime, len(ids))
for rows.Next() {
var (
aid int64
ptime time.Time
copyright int8
)
if err = rows.Scan(&aid, &ptime, &copyright); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
return
}
aptm[aid] = &model.AidPubTime{Aid: aid, PubDate: ptime, Copyright: copyright}
aids = append(aids, aid)
ptimes = append(ptimes, ptime)
copyrights = append(copyrights, copyright)
}
return
}

View File

@@ -0,0 +1,27 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveArcsAids(t *testing.T) {
convey.Convey("ArcsAids", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{10110188}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
aids, ptimes, copyrights, aptm, err := d.ArcsAids(c, ids)
ctx.Convey("Then err should be nil.aids,ptimes,copyrights,aptm should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(aptm, convey.ShouldNotBeNil)
ctx.So(copyrights, convey.ShouldNotBeNil)
ctx.So(ptimes, convey.ShouldNotBeNil)
ctx.So(aids, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,38 @@
package archive
import (
"time"
"go-common/app/service/main/up/conf"
"go-common/library/cache/redis"
"go-common/library/database/sql"
"go-common/library/stat/prom"
)
// Dao is archive dao.
type Dao struct {
c *conf.Config
resultDB *sql.DB
archiveDB *sql.DB
// redis
upRds *redis.Pool
upExpire int32
errProm *prom.Prom
infoProm *prom.Prom
}
// New new a Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// db
resultDB: sql.NewMySQL(c.DB.ArcResult),
archiveDB: sql.NewMySQL(c.DB.Archive),
// redis
upRds: redis.NewPool(c.Redis.Up.Config),
upExpire: int32(time.Duration(c.Redis.Up.UpExpire) / time.Second),
errProm: prom.BusinessErrCount,
infoProm: prom.BusinessInfoCount,
}
return
}

View File

@@ -0,0 +1,39 @@
package archive
import (
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.up-service")
flag.Set("conf_token", "5f1660060bb011e8865c66d44b23cda7")
flag.Set("tree_id", "15572")
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,107 @@
package archive
import (
"context"
"fmt"
"go-common/library/log"
"go-common/library/time"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_upCntSQL = "SELECT COUNT(*) FROM archive WHERE mid=? AND (state>=0 or state=-6)"
_upsCntSQL = "SELECT mid,COUNT(*) FROM archive WHERE mid IN(%s) AND (state>=0 or state=-6) GROUP BY mid"
_upPasSQL = "SELECT aid,pubtime,copyright FROM archive WHERE mid=? AND state>=0 ORDER BY pubtime DESC"
_upsPasSQL = "SELECT aid,mid,pubtime,copyright FROM archive WHERE mid IN (%s) AND state>=0 ORDER BY pubtime DESC"
)
// UppersCount get mids count
func (d *Dao) UppersCount(c context.Context, mids []int64) (uc map[int64]int64, err error) {
rows, err := d.resultDB.Query(c, fmt.Sprintf(_upsCntSQL, xstr.JoinInts(mids)))
if err != nil {
err = errors.WithStack(err)
return
}
uc = make(map[int64]int64, len(mids))
defer rows.Close()
for rows.Next() {
var (
mid int64
cnt int64
)
if err = rows.Scan(&mid, &cnt); err != nil {
err = errors.WithStack(err)
return
}
uc[mid] = cnt
}
return
}
// UpperCount get the count of archives by mid of Up.
func (d *Dao) UpperCount(c context.Context, mid int64) (count int64, err error) {
d.infoProm.Incr("UpperCount")
row := d.resultDB.QueryRow(c, _upCntSQL, mid)
if err = row.Scan(&count); err != nil {
log.Error("row.Scan error(%v)", err)
}
return
}
// UpperPassed get upper passed archives.
func (d *Dao) UpperPassed(c context.Context, mid int64) (aids []int64, ptimes []time.Time, copyrights []int8, err error) {
d.infoProm.Incr("UpperPassed")
rows, err := d.resultDB.Query(c, _upPasSQL, mid)
if err != nil {
log.Error("getUpPasStmt.Query(%d) error(%v)", mid, err)
return
}
defer rows.Close()
for rows.Next() {
var (
aid int64
ptime time.Time
copyright int8
)
if err = rows.Scan(&aid, &ptime, &copyright); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
ptimes = append(ptimes, ptime)
copyrights = append(copyrights, copyright)
}
return
}
// UppersPassed get uppers passed archives.
func (d *Dao) UppersPassed(c context.Context, mids []int64) (aidm map[int64][]int64, ptimes map[int64][]time.Time, copyrights map[int64][]int8, err error) {
d.infoProm.Incr("UppersPassed")
rows, err := d.resultDB.Query(c, fmt.Sprintf(_upsPasSQL, xstr.JoinInts(mids)))
if err != nil {
log.Error("UpsPassed error(%v)", err)
return
}
defer rows.Close()
aidm = make(map[int64][]int64, len(mids))
ptimes = make(map[int64][]time.Time, len(mids))
copyrights = make(map[int64][]int8, len(mids))
for rows.Next() {
var (
aid, mid int64
ptime time.Time
copyright int8
)
if err = rows.Scan(&aid, &mid, &ptime, &copyright); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aidm[mid] = append(aidm[mid], aid)
ptimes[mid] = append(ptimes[mid], ptime)
copyrights[mid] = append(copyrights[mid], copyright)
}
return
}

View File

@@ -0,0 +1,316 @@
package archive
import (
"context"
"strconv"
"go-common/app/service/main/up/model"
"go-common/library/cache/redis"
"go-common/library/log"
"go-common/library/time"
)
const (
_prefixUpCnt = "uc_"
_prefixUpPas = "up_"
)
func upCntKey(mid int64) string {
return _prefixUpCnt + strconv.FormatInt(mid, 10)
}
func upPasKey(mid int64) string {
return _prefixUpPas + strconv.FormatInt(mid, 10)
}
// AddUpperCountCache the count of up's archives
func (d *Dao) AddUpperCountCache(c context.Context, mid int64, count int64) (err error) {
var (
key = upCntKey(mid)
conn = d.upRds.Get(c)
expireTime = d.upExpire
)
defer conn.Close()
if count == 0 {
expireTime = 600
}
if _, err = conn.Do("SETEX", key, expireTime, count); err != nil {
log.Error("conn.Do(SETEX, %s, %d, %d)", key, expireTime, count)
return
}
return
}
// UpperCountCache get up count from cache.
func (d *Dao) UpperCountCache(c context.Context, mid int64) (count int64, err error) {
var (
key = upCntKey(mid)
conn = d.upRds.Get(c)
)
defer conn.Close()
if count, err = redis.Int64(conn.Do("GET", key)); err != nil {
if err == redis.ErrNil {
count = -1
err = nil
} else {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(GET, %s) error(%v)", key, err)
}
}
return
}
// UppersCountCache return uppers count cache
func (d *Dao) UppersCountCache(c context.Context, mids []int64) (cached map[int64]int64, missed []int64, err error) {
conn := d.upRds.Get(c)
defer conn.Close()
cached = make(map[int64]int64)
for _, mid := range mids {
key := upCntKey(mid)
if err = conn.Send("GET", key); err != nil {
missed = mids
continue
}
}
if err = conn.Flush(); err != nil {
missed = mids
return
}
for _, mid := range mids {
var cnt int64
if cnt, err = redis.Int64(conn.Receive()); err != nil {
if err == redis.ErrNil {
missed = append(missed, mid)
err = nil
continue
}
}
cached[mid] = int64(cnt)
}
return
}
// UpperPassedCache get upper passed archives from cache.
func (d *Dao) UpperPassedCache(c context.Context, mid int64, start, end int) (aids []int64, err error) {
var (
key = upPasKey(mid)
conn = d.upRds.Get(c)
)
defer conn.Close()
if aids, err = redis.Int64s(conn.Do("ZREVRANGE", key, start, end)); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(ZRANGE, %s, 0, -1) error(%v)", key, err)
}
return
}
// UppersPassedCacheWithScore get uppers passed archive from cache with score
func (d *Dao) UppersPassedCacheWithScore(c context.Context, mids []int64, start, end int) (aidm map[int64][]*model.AidPubTime, err error) {
conn := d.upRds.Get(c)
defer conn.Close()
aidm = make(map[int64][]*model.AidPubTime, len(mids))
for _, mid := range mids {
key := upPasKey(mid)
if err = conn.Send("ZREVRANGE", key, start, end, "WITHSCORES"); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Send(ZREVRANGE, %s) error(%v)", key, err)
return
}
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
return
}
for _, mid := range mids {
aidScores, err := redis.Int64s(conn.Receive())
if err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(GET, %d) error(%v)", mid, err)
continue
}
for i := 0; i < len(aidScores); i += 2 {
var (
score int64
ptime int64
copyright int8
)
score = aidScores[i+1]
if score > 1000000000 {
ptime = score >> 2
copyright = int8(score & 3)
aidm[mid] = append(aidm[mid], &model.AidPubTime{Aid: aidScores[i], PubDate: time.Time(ptime), Copyright: copyright})
} else {
aidm[mid] = append(aidm[mid], &model.AidPubTime{Aid: aidScores[i], PubDate: time.Time(score)})
}
}
}
return
}
// UppersPassedCache get uppers passed archives from cache.
func (d *Dao) UppersPassedCache(c context.Context, mids []int64, start, end int) (aidm map[int64][]int64, err error) {
conn := d.upRds.Get(c)
defer conn.Close()
aidm = make(map[int64][]int64, len(mids))
for _, mid := range mids {
key := upPasKey(mid)
if err = conn.Send("ZREVRANGE", key, start, end); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Send(ZREVRANGE, %s) error(%v)", key, err)
return
}
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
return
}
for _, mid := range mids {
aids, err := redis.Int64s(conn.Receive())
if err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(GET, %d) error(%v)", mid, err)
continue
}
aidm[mid] = aids
}
return
}
// ExpireUpperPassedCache expire up passed cache.
func (d *Dao) ExpireUpperPassedCache(c context.Context, mid int64) (ok bool, err error) {
var (
key = upPasKey(mid)
conn = d.upRds.Get(c)
)
defer conn.Close()
if ok, err = redis.Bool(conn.Do("EXPIRE", key, d.upExpire)); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(EXPIRE, %s, %d) error(%v)", key, d.upExpire, err)
}
return
}
// ExpireUppersCountCache expire ups count cache
func (d *Dao) ExpireUppersCountCache(c context.Context, mids []int64) (cachedUp, missed []int64, err error) {
var conn = d.upRds.Get(c)
defer conn.Close()
defer func() {
if err != nil {
d.errProm.Incr("upper_redis")
}
}()
for _, mid := range mids {
var key = upCntKey(mid)
if err = conn.Send("GET", key); err != nil {
log.Error("conn.Send(GET, %s) error(%v)", key, err)
return
}
}
for _, mid := range mids {
var key = upCntKey(mid)
if err = conn.Send("EXPIRE", key, d.upExpire); err != nil {
log.Error("conn.Send(GET, %s) error(%v)", key, err)
return
}
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
return
}
cachedUp = make([]int64, 0)
missed = make([]int64, 0)
for _, mid := range mids {
var cnt int
if cnt, err = redis.Int(conn.Receive()); err != nil {
if err == redis.ErrNil {
err = nil
missed = append(missed, mid)
} else {
log.Error("conn.Receive error(%v)", err)
return
}
} else if cnt > 0 {
cachedUp = append(cachedUp, mid)
}
}
for _, mid := range mids {
if _, err = redis.Bool(conn.Receive()); err != nil {
log.Error("conn.Receive mid(%d) error(%v)", mid, err)
return
}
}
return
}
// ExpireUppersPassedCache expire uppers passed cache.
func (d *Dao) ExpireUppersPassedCache(c context.Context, mids []int64) (res map[int64]bool, err error) {
conn := d.upRds.Get(c)
defer conn.Close()
res = make(map[int64]bool, len(mids))
for _, mid := range mids {
key := upPasKey(mid)
if err = conn.Send("EXPIRE", key, d.upExpire); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Send(%s) error(%v)", key, err)
return
}
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
return
}
var ok bool
for _, mid := range mids {
if ok, err = redis.Bool(conn.Receive()); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Receive() error(%v)", err)
return
}
res[mid] = ok
}
return
}
// AddUpperPassedCache add up paassed cache.
func (d *Dao) AddUpperPassedCache(c context.Context, mid int64, aids []int64, ptimes []time.Time, copyrights []int8) (err error) {
var (
key = upPasKey(mid)
conn = d.upRds.Get(c)
)
defer conn.Close()
for k, aid := range aids {
score := int64(ptimes[k]<<2) | int64(copyrights[k])
if err = conn.Send("ZADD", key, score, aid); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Send(ZADD, %s, %d, %d) error(%v)", key, aid, ptimes[k], err)
return
}
}
if err = conn.Flush(); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Flush error(%v)", err)
return
}
for i := 0; i < len(aids); i++ {
if _, err = conn.Receive(); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Receive error(%v)", err)
return
}
}
return
}
// DelUpperPassedCache delete up passed cache.
func (d *Dao) DelUpperPassedCache(c context.Context, mid, aid int64) (err error) {
var (
key = upPasKey(mid)
conn = d.upRds.Get(c)
)
defer conn.Close()
if _, err = conn.Do("ZREM", key, aid); err != nil {
d.errProm.Incr("upper_redis")
log.Error("conn.Do(ZERM, %s, %d) error(%v)", key, aid, err)
}
return
}

View File

@@ -0,0 +1,197 @@
package archive
import (
"context"
"testing"
"go-common/library/time"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveupCntKey(t *testing.T) {
var (
mid = int64(1)
)
convey.Convey("upCntKey", t, func(ctx convey.C) {
p1 := upCntKey(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestArchiveupPasKey(t *testing.T) {
var (
mid = int64(1)
)
convey.Convey("upPasKey", t, func(ctx convey.C) {
p1 := upPasKey(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestArchiveAddUpperCountCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
count = int64(10)
)
convey.Convey("AddUpperCountCache", t, func(ctx convey.C) {
err := d.AddUpperCountCache(c, mid, count)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestArchiveUpperCountCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
)
convey.Convey("UpperCountCache", t, func(ctx convey.C) {
count, err := d.UpperCountCache(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(count, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUppersCountCache(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
)
convey.Convey("UppersCountCache", t, func(ctx convey.C) {
cached, missed, err := d.UppersCountCache(c, mids)
ctx.Convey("Then err should be nil.cached,missed should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(missed, convey.ShouldNotBeNil)
ctx.So(cached, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUpperPassedCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
start = int(0)
end = int(10)
)
convey.Convey("UpperPassedCache", t, func(ctx convey.C) {
_, err := d.UpperPassedCache(c, mid, start, end)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestArchiveUppersPassedCacheWithScore(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
start = int(0)
end = int(10)
)
convey.Convey("UppersPassedCacheWithScore", t, func(ctx convey.C) {
aidm, err := d.UppersPassedCacheWithScore(c, mids, start, end)
ctx.Convey("Then err should be nil.aidm should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(aidm, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUppersPassedCache(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
start = int(0)
end = int(10)
)
convey.Convey("UppersPassedCache", t, func(ctx convey.C) {
aidm, err := d.UppersPassedCache(c, mids, start, end)
ctx.Convey("Then err should be nil.aidm should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(aidm, convey.ShouldNotBeNil)
})
})
}
func TestArchiveExpireUpperPassedCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
)
convey.Convey("ExpireUpperPassedCache", t, func(ctx convey.C) {
ok, err := d.ExpireUpperPassedCache(c, mid)
ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(ok, convey.ShouldNotBeNil)
})
})
}
func TestArchiveExpireUppersCountCache(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
)
convey.Convey("ExpireUppersCountCache", t, func(ctx convey.C) {
cachedUp, missed, err := d.ExpireUppersCountCache(c, mids)
ctx.Convey("Then err should be nil.cachedUp,missed should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(missed, convey.ShouldNotBeNil)
ctx.So(cachedUp, convey.ShouldNotBeNil)
})
})
}
func TestArchiveExpireUppersPassedCache(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
)
convey.Convey("ExpireUppersPassedCache", t, func(ctx convey.C) {
res, err := d.ExpireUppersPassedCache(c, mids)
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 TestArchiveAddUpperPassedCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
aids = []int64{1}
ptimes = []time.Time{1531553274}
copyrights = []int8{1}
)
convey.Convey("AddUpperPassedCache", t, func(ctx convey.C) {
err := d.AddUpperPassedCache(c, mid, aids, ptimes, copyrights)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestArchiveDelUpperPassedCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
aid = int64(1)
)
convey.Convey("DelUpperPassedCache", t, func(ctx convey.C) {
err := d.DelUpperPassedCache(c, mid, aid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,85 @@
package archive
import (
"context"
"fmt"
"go-common/library/database/sql"
"go-common/library/xstr"
)
const (
_staffSQL = "SELECT aid FROM archive_staff WHERE staff_mid = ? AND state = 1"
_staffsSQL = "SELECT aid, staff_mid FROM archive_staff WHERE staff_mid IN (%s) AND state = 1"
_staffAidSQL = "SELECT staff_mid FROM archive_staff WHERE aid = ? AND state = 1"
)
// Staff get upper staff aids by mid.
func (d *Dao) Staff(c context.Context, mid int64) (aids []int64, err error) {
d.infoProm.Incr("Staff")
rows, err := d.archiveDB.Query(c, _staffSQL, mid)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
return
}
aids = append(aids, aid)
}
return
}
// Staffs get uppers staff aids by mids.
func (d *Dao) Staffs(c context.Context, mids []int64) (aidm map[int64][]int64, err error) {
d.infoProm.Incr("Staffs")
rows, err := d.archiveDB.Query(c, fmt.Sprintf(_staffsSQL, xstr.JoinInts(mids)))
if err != nil {
return
}
defer rows.Close()
aidm = make(map[int64][]int64, len(mids))
for rows.Next() {
var (
aid int64
staffMid int64
)
if err = rows.Scan(&aid, &staffMid); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
return
}
aidm[staffMid] = append(aidm[staffMid], aid)
}
return
}
// StaffAid get uppers staff mid-list by aid.
func (d *Dao) StaffAid(c context.Context, aid int64) (mids []int64, err error) {
d.infoProm.Incr("StaffAid")
rows, err := d.archiveDB.Query(c, _staffAidSQL, aid)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
var mid int64
if err = rows.Scan(&mid); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
return
}
mids = append(mids, mid)
}
return
}

View File

@@ -0,0 +1,56 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveStaff(t *testing.T) {
convey.Convey("Staff", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515258)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
aids, err := d.Staff(c, mid)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(len(aids), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
})
}
func TestArchiveStaffs(t *testing.T) {
convey.Convey("Staffs", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{27515258}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
aidm, err := d.Staffs(c, mids)
ctx.Convey("Then err should be nil.aidm should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(aidm, convey.ShouldNotBeNil)
})
})
})
}
func TestArchiveStaffAid(t *testing.T) {
convey.Convey("StaffAid", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(10110188)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
mids, err := d.StaffAid(c, aid)
ctx.Convey("Then err should be nil.mids should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mids, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,65 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveUppersCount(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1, 2}
)
convey.Convey("UppersCount", t, func(ctx convey.C) {
uc, err := d.UppersCount(c, mids)
ctx.Convey("Then err should be nil.uc should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(uc, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUpperCount(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
)
convey.Convey("UpperCount", t, func(ctx convey.C) {
count, err := d.UpperCount(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(count, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUpperPassed(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
)
convey.Convey("UpperPassed", t, func(ctx convey.C) {
_, _, _, err := d.UpperPassed(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestArchiveUppersPassed(t *testing.T) {
var (
c = context.TODO()
mids = []int64{1}
)
convey.Convey("UppersPassed", t, func(ctx convey.C) {
aidm, ptimes, copyrights, err := d.UppersPassed(c, mids)
ctx.Convey("Then err should be nil.aidm,ptimes,copyrights should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(copyrights, convey.ShouldNotBeNil)
ctx.So(ptimes, convey.ShouldNotBeNil)
ctx.So(aidm, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,65 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"card.go",
"dao.go",
"rpc.go",
"up_base.go",
],
importpath = "go-common/app/service/main/up/dao/card",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/sync/errgroup: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"],
)
go_test(
name = "go_default_test",
srcs = [
"card_test.go",
"dao_test.go",
"rpc_test.go",
"up_base_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,282 @@
package card
import (
"context"
"fmt"
"go-common/app/service/main/up/model"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_UpInfoBaseColumn = `mid, name_cn, name_en, name_alias, signature, content, nationality,
nation, gender, blood_type, constellation, height, weight, birth_place, birth_date, occupation,
tags, masterpieces, school, location, interests, platform, platform_account`
_countUpSQL = "SELECT count(distinct mid) FROM card_up"
_listUpMidSQL = "SELECT mid FROM card_up order BY mtime DESC"
_listUpInfoSQL = "SELECT " + _UpInfoBaseColumn + " FROM card_up limit ? offset ?"
_getUpInfoByMidSQL = "SELECT " + _UpInfoBaseColumn + " FROM card_up WHERE mid=?"
_listUpVideoIDSQL = "SELECT avid FROM card_up_video WHERE mid=? ORDER BY id DESC"
_listUpImageSQL = "SELECT url, height, width FROM card_up_image WHERE mid=? ORDER BY id DESC"
_listUpAccountSQL = "SELECT url, title, picture, abstract FROM card_up_account WHERE mid = ?"
_listUpInfoByMidsSQL = "SELECT " + _UpInfoBaseColumn + " FROM card_up WHERE mid IN (%s)"
_listUpVideoIDByMidsSQL = "SELECT mid, avid FROM card_up_video WHERE mid IN (%s) ORDER BY id DESC"
_listUpImageByMidsSQL = "SELECT mid, url, height, width FROM card_up_image WHERE mid IN (%s) ORDER BY id DESC"
_listUpAccountByMidsSQL = "SELECT mid, url, title, picture, abstract FROM card_up_account WHERE mid IN (%s)"
)
// CountUpCard count up num
func (d *Dao) CountUpCard(ctx context.Context) (total int, err error) {
row := d.db.QueryRow(ctx, _countUpSQL)
err = row.Scan(&total)
if err != nil {
log.Error("CountUpCard row.Scan error(%v)", err)
}
return
}
// ListUpInfo page list up mids
func (d *Dao) ListUpInfo(ctx context.Context, offset uint, size uint) (infos []*model.UpCardInfo, err error) {
rows, err := d.db.Query(ctx, _listUpInfoSQL, size, offset)
if err != nil {
log.Error("ListUpInfo d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
info := &model.UpCardInfo{}
err = rows.Scan(&info.MID,
&info.NameCN, &info.NameEN, &info.NameAlias,
&info.Signature,
&info.Content, &info.Nationality, &info.Nation,
&info.Gender, &info.BloodType, &info.Constellation,
&info.Height, &info.Weight, &info.BirthPlace,
&info.BirthDate, &info.Occupation, &info.Tags,
&info.Masterpieces, &info.School, &info.Location,
&info.Interests, &info.Platform, &info.PlatformAccount)
if err != nil {
log.Error("ListUpInfo rows.Scan error(%v)", err)
return
}
infos = append(infos, info)
}
return
}
// MidUpInfoMap get <mid, UpInfo> map by mids
func (d *Dao) MidUpInfoMap(ctx context.Context, mids []int64) (midUpInfoMap map[int64]*model.UpCardInfo, err error) {
midUpInfoMap = make(map[int64]*model.UpCardInfo)
rows, err := d.db.Query(ctx, fmt.Sprintf(_listUpInfoByMidsSQL, xstr.JoinInts(mids)))
if err != nil {
log.Error("MidUpInfoMap d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
info := &model.UpCardInfo{}
err = rows.Scan(&info.MID,
&info.NameCN, &info.NameEN, &info.NameAlias,
&info.Signature,
&info.Content, &info.Nationality, &info.Nation,
&info.Gender, &info.BloodType, &info.Constellation,
&info.Height, &info.Weight, &info.BirthPlace,
&info.BirthDate, &info.Occupation, &info.Tags,
&info.Masterpieces, &info.School, &info.Location,
&info.Interests, &info.Platform, &info.PlatformAccount)
if err != nil {
log.Error("MidUpInfoMap rows.Scan error(%v)", err)
return
}
midUpInfoMap[info.MID] = info
}
return
}
// MidAccountsMap get <mid, Accounts> map by mids
func (d *Dao) MidAccountsMap(ctx context.Context, mids []int64) (midAccountsMap map[int64][]*model.UpCardAccount, err error) {
midAccountsMap = make(map[int64][]*model.UpCardAccount)
rows, err := d.db.Query(ctx, fmt.Sprintf(_listUpAccountByMidsSQL, xstr.JoinInts(mids)))
if err != nil {
log.Error("MidAccountsMap d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var mid int64
account := new(model.UpCardAccount)
err = rows.Scan(&mid, &account.URL, &account.Title, &account.Picture, &account.Desc)
if err != nil {
log.Error("MidAccountsMap row.Scan error(%v)", err)
return
}
midAccountsMap[mid] = append(midAccountsMap[mid], account)
}
return
}
// MidImagesMap get <mid, Images> map by mids
func (d *Dao) MidImagesMap(ctx context.Context, mids []int64) (midImagesMap map[int64][]*model.UpCardImage, err error) {
midImagesMap = make(map[int64][]*model.UpCardImage)
rows, err := d.db.Query(ctx, fmt.Sprintf(_listUpImageByMidsSQL, xstr.JoinInts(mids)))
if err != nil {
log.Error("MidImagesMap d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var mid int64
image := new(model.UpCardImage)
err = rows.Scan(&mid, &image.URL, &image.Height, &image.Width)
if err != nil {
log.Error("MidImagesMap row.Scan error(%v)", err)
return
}
midImagesMap[mid] = append(midImagesMap[mid], image)
}
return
}
// MidAvidsMap get <mid, Avids> map by mids
func (d *Dao) MidAvidsMap(ctx context.Context, mids []int64) (midAvidsMap map[int64][]int64, err error) {
midAvidsMap = make(map[int64][]int64)
rows, err := d.db.Query(ctx, fmt.Sprintf(_listUpVideoIDByMidsSQL, xstr.JoinInts(mids)))
if err != nil {
log.Error("MidAvidsMap d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var mid int64
var avid int64
err = rows.Scan(&mid, &avid)
if err != nil {
log.Error("MidAvidsMap row.Scan error(%v)", err)
return
}
midAvidsMap[mid] = append(midAvidsMap[mid], avid)
}
return
}
// ListUpMID list up mids
func (d *Dao) ListUpMID(ctx context.Context) (mids []int64, err error) {
rows, err := d.db.Query(ctx, _listUpMidSQL)
if err != nil {
log.Error("ListCardBase d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var mid int64
err = rows.Scan(&mid)
if err != nil {
log.Error("ListCardBase row.Scan error(%v)", err)
return
}
mids = append(mids, mid)
}
return
}
// GetUpInfo get up info by mid
func (d *Dao) GetUpInfo(ctx context.Context, mid int64) (card *model.UpCardInfo, err error) {
row := d.db.QueryRow(ctx, _getUpInfoByMidSQL, mid)
card = &model.UpCardInfo{}
if err = row.Scan(&card.MID,
&card.NameCN, &card.NameEN, &card.NameAlias,
&card.Signature,
&card.Content, &card.Nationality, &card.Nation,
&card.Gender, &card.BloodType, &card.Constellation,
&card.Height, &card.Weight, &card.BirthPlace,
&card.BirthDate, &card.Occupation, &card.Tags,
&card.Masterpieces, &card.School, &card.Location,
&card.Interests, &card.Platform, &card.PlatformAccount); err != nil {
if err == sql.ErrNoRows {
card = nil
err = nil
} else {
log.Error("GetUpCard row.Scan error(%v)", err)
return
}
}
return
}
// ListUpAccount list up accounts by mid
func (d *Dao) ListUpAccount(ctx context.Context, mid int64) (accounts []*model.UpCardAccount, err error) {
rows, err := d.db.Query(ctx, _listUpAccountSQL, mid)
if err != nil {
log.Error("listUpAccount d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
account := new(model.UpCardAccount)
err = rows.Scan(&account.URL, &account.Title, &account.Picture, &account.Desc)
if err != nil {
log.Error("listUpAccount row.Scan error(%v)", err)
return
}
accounts = append(accounts, account)
}
return
}
// ListUpImage list up images by mid
func (d *Dao) ListUpImage(ctx context.Context, mid int64) (images []*model.UpCardImage, err error) {
rows, err := d.db.Query(ctx, _listUpImageSQL, mid)
if err != nil {
log.Error("listUpImage d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
image := new(model.UpCardImage)
err = rows.Scan(&image.URL, &image.Height, &image.Width)
if err != nil {
log.Error("listUpImage row.Scan error(%v)", err)
return
}
images = append(images, image)
}
return
}
// ListAVID list avids by mid
func (d *Dao) ListAVID(ctx context.Context, mid int64) (avids []int64, err error) {
rows, err := d.db.Query(ctx, _listUpVideoIDSQL, mid)
if err != nil {
log.Error("listUpVideo d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var avid int64
err = rows.Scan(&avid)
if err != nil {
log.Error("listUpVideo row.Scan error(%v)", err)
return
}
avids = append(avids, avid)
}
return
}

View File

@@ -0,0 +1,148 @@
package card
import (
"context"
"github.com/smartystreets/goconvey/convey"
"testing"
)
func TestCountUpCard(t *testing.T) {
var c = context.Background()
convey.Convey("CountUpCard", t, func(ctx convey.C) {
total, err := d.CountUpCard(c)
ctx.Convey("Then err should be nil.total should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
}
func TestPageListUpInfo(t *testing.T) {
var (
c = context.Background()
offset = uint(1)
size = uint(1)
)
convey.Convey("ListUpInfo", t, func(ctx convey.C) {
infos, err := d.ListUpInfo(c, offset, size)
ctx.Convey("Then err should be nil.infos should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(infos, convey.ShouldNotBeNil)
})
})
}
func TestListUpMID(t *testing.T) {
var c = context.Background()
convey.Convey("ListUpMID", t, func(ctx convey.C) {
mids, err := d.ListUpMID(c)
ctx.Convey("Then err should be nil.mids should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mids, convey.ShouldNotBeNil)
})
})
}
func TestGetUpInfo(t *testing.T) {
var (
c = context.Background()
mid = int64(1532165)
)
convey.Convey("GetUpInfo", t, func(ctx convey.C) {
upInfo, err := d.GetUpInfo(c, mid)
ctx.Convey("Then err should be nil.upInfo should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(upInfo, convey.ShouldNotBeNil)
})
})
}
func TestListUpAccount(t *testing.T) {
var (
c = context.Background()
mid = int64(1532165)
)
convey.Convey("ListUpAccount", t, func(ctx convey.C) {
accounts, err := d.ListUpAccount(c, mid)
ctx.Convey("Then err should be nil.accounts should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(accounts, convey.ShouldNotBeNil)
})
})
}
func TestListUpImage(t *testing.T) {
var (
c = context.Background()
mid = int64(1532165)
)
convey.Convey("ListUpImage", t, func(ctx convey.C) {
images, err := d.ListUpImage(c, mid)
ctx.Convey("Then err should be nil.images should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(images, convey.ShouldNotBeNil)
})
})
}
func TestListAVID(t *testing.T) {
var (
c = context.Background()
mid = int64(1532165)
)
convey.Convey("ListAVID", t, func(ctx convey.C) {
avids, err := d.ListAVID(c, mid)
ctx.Convey("Then err should be nil.avids should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(avids, convey.ShouldNotBeNil)
})
})
}
func TestMidUpInfoMap(t *testing.T) {
var (
c = context.Background()
mids = []int64{1532165}
)
convey.Convey("MidUpInfoMap", t, func(ctx convey.C) {
res, err := d.MidUpInfoMap(c, mids)
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 TestMidAccountsMap(t *testing.T) {
var (
c = context.Background()
mids = []int64{1532165}
)
convey.Convey("MidAccountsMap", t, func(ctx convey.C) {
res, err := d.MidAccountsMap(c, mids)
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 TestMidImagesMap(t *testing.T) {
var (
c = context.Background()
mids = []int64{1532165}
)
convey.Convey("MidImagesMap", t, func(ctx convey.C) {
res, err := d.MidImagesMap(c, mids)
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 TestMidAvidsMap(t *testing.T) {
var (
c = context.Background()
mids = []int64{1532165}
)
convey.Convey("MidAvidsMap", t, func(ctx convey.C) {
res, err := d.MidAvidsMap(c, mids)
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,36 @@
package card
import (
"context"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao/global"
"go-common/library/database/sql"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
db *sql.DB
}
// New fn
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: global.GetUpCrmDB(),
}
return d
}
// Close fn
func (d *Dao) Close() {
if d.db != nil {
d.db.Close()
}
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}

View File

@@ -0,0 +1,42 @@
package card
import (
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/dao/global"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
global.Init(conf.Conf)
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,97 @@
package card
import (
"context"
"fmt"
"sync"
arcgrpc "go-common/app/service/main/archive/api"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/dao/global"
"go-common/app/service/main/up/model"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/sync/errgroup"
)
const _avURL = "http://www.bilibili.com/video/av%d"
//ListVideoArchive list videos by avids
func (d *Dao) ListVideoArchive(ctx context.Context, avids []int64) (videos []*model.UpCardVideo, err error) {
archives, err := d.listArchives(ctx, avids)
if err != nil {
log.Error("d.listArchives error(%v) arg(%v)", err, avids)
err = ecode.CreativeArcServiceErr
return
}
for avid, data := range archives {
video := transfer(avid, data)
videos = append(videos, video)
}
return
}
//AvidVideoMap get <avid, video> map by avids
func (d *Dao) AvidVideoMap(ctx context.Context, avids []int64) (avidVideoMap map[int64]*model.UpCardVideo, err error) {
avidVideoMap = make(map[int64]*model.UpCardVideo)
archives, err := d.listArchives(ctx, avids)
if err != nil {
log.Error("d.listArchives error(%v) arg(%v)", err, avids)
err = ecode.CreativeArcServiceErr
return
}
for avid, data := range archives {
video := transfer(avid, data)
avidVideoMap[avid] = video
}
return
}
func (d *Dao) listArchives(ctx context.Context, avids []int64) (archives map[int64]*arcgrpc.Arc, err error) {
archives = make(map[int64]*arcgrpc.Arc)
var (
g errgroup.Group
m sync.Mutex
)
dao.Split(0, len(avids), 300, func(start int, end int) {
g.Go(func() (err error) {
var (
arg = &arcgrpc.ArcsRequest{
Aids: avids[start:end],
}
res *arcgrpc.ArcsReply
)
if res, err = global.GetArcClient().Arcs(ctx, arg); err != nil {
log.Error("d.acc.Archives3 arg(%v) error(%v)", arg, err)
err = nil
} else {
for k, v := range res.Arcs {
m.Lock()
archives[k] = v
m.Unlock()
}
}
return
})
})
if err = g.Wait(); err != nil {
log.Error("g.Wait() error(%v)", err)
}
return
}
func transfer(avid int64, archive *arcgrpc.Arc) (video *model.UpCardVideo) {
return &model.UpCardVideo{
URL: fmt.Sprintf(_avURL, avid),
Title: archive.Title,
Picture: archive.Pic,
Duration: archive.Duration,
CTime: archive.Ctime,
}
}

View File

@@ -0,0 +1,35 @@
package card
import (
"context"
"github.com/smartystreets/goconvey/convey"
"testing"
)
func TestListVideoArchive(t *testing.T) {
var (
c = context.TODO()
avids = []int64{31908629}
)
convey.Convey("Info", t, func(ctx convey.C) {
videos, err := d.ListVideoArchive(c, avids)
ctx.Convey("Then err should be nil.videos should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(videos, convey.ShouldNotBeNil)
})
})
}
func TestAvidVideoMap(t *testing.T) {
var (
c = context.TODO()
avids = []int64{31908629}
)
convey.Convey("Info", t, func(ctx convey.C) {
avidVideoMap, err := d.AvidVideoMap(c, avids)
ctx.Convey("Then err should be nil.midVideosMap should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(avidVideoMap, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,34 @@
package card
import (
"context"
"fmt"
"go-common/library/log"
)
const _listUpBaseSQL = "SELECT id, mid FROM up_base_info WHERE id > ? AND business_type = 1 %s LIMIT ?"
// ListUpBase list <id, mid> k-v pairs
func (d *Dao) ListUpBase(c context.Context, size int, lastID int64, where string) (idMids map[int64]int64, err error) {
idMids = make(map[int64]int64)
rows, err := d.db.Query(c, fmt.Sprintf(_listUpBaseSQL, where), lastID, size)
if err != nil {
log.Error("ListUpBase d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var mid int64
var id int64
err = rows.Scan(&id, &mid)
if err != nil {
log.Error("ListUpBase rows.Scan error(%v)", err)
return
}
idMids[id] = mid
}
return
}

View File

@@ -0,0 +1,26 @@
package card
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestCardListUpBase(t *testing.T) {
convey.Convey("ListUpBase", t, func(ctx convey.C) {
var (
c = context.Background()
size = int(3)
lastID = int64(1)
where = "AND activity = 1"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
idMids, err := d.ListUpBase(c, size, lastID, where)
ctx.Convey("Then err should be nil.idMids should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(idMids, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,60 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"field_test.go",
"hbase_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//library/database/hbase.v2:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
"//vendor/github.com/tsuna/gohbase/hrpc:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"field.go",
"hbase.go",
],
importpath = "go-common/app/service/main/up/dao/data",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/model/data:go_default_library",
"//library/database/hbase.v2: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,24 @@
package data
import (
"go-common/app/service/main/up/conf"
"go-common/library/database/hbase.v2"
"time"
)
//Dao hbase dao
type Dao struct {
c *conf.Config
hbase *hbase.Client
hbaseTimeOut time.Duration
}
//New create dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
hbase: hbase.NewClient(&c.HBase.Config),
hbaseTimeOut: time.Millisecond * 500,
}
return
}

View File

@@ -0,0 +1,40 @@
package data
import (
"flag"
"go-common/app/service/main/up/conf"
"os"
"testing"
"go-common/app/service/main/up/dao"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,94 @@
package data
var (
//HBaseVideoTablePrefix 播放流失分布
HBaseVideoTablePrefix = "video_play_churn_"
//HBaseArchiveTablePrefix 分类分端播放
HBaseArchiveTablePrefix = "video_play_category_"
//HBaseAreaTablePrefix 地区播放
HBaseAreaTablePrefix = "video_play_area_"
//HBaseUpStatTablePrefix up主概况
HBaseUpStatTablePrefix = "up_stats_"
//HBaseUpViewerBase 观众数据,性别年龄分布 + 设备分布
HBaseUpViewerBase = "up_viewer_base_"
//HBaseUpViewerArea 地区分布
HBaseUpViewerArea = "up_viewer_area_"
//HBaseUpViewerTrend 内容倾向
HBaseUpViewerTrend = "up_viewer_trend_"
//HBaseUpViewerActionHour 行为时间分布
HBaseUpViewerActionHour = "up_viewer_action_hour_"
//HBaseUpRelationFansDay 日维度 最近30天 只保留31天
HBaseUpRelationFansDay = "up_relation_fans_day"
// HBaseUpRelationFansHistory 日维度 各月份每日数据,日更,永久保存
HBaseUpRelationFansHistory = "up_relation_fans_history"
//HBaseUpRelationFansMonth 年维度 2017.8月以后的数据永久保存
HBaseUpRelationFansMonth = "up_relation_fans_month"
//HBaseUpPlayInc 我的概况 播放相关
HBaseUpPlayInc = "up_play_inc_"
//HBaseUpDmInc 弹幕相关
HBaseUpDmInc = "up_dm_inc_"
//HBaseUpReplyInc 评论相关
HBaseUpReplyInc = "up_reply_inc_"
//HBaseUpShareInc 分享相关
HBaseUpShareInc = "up_share_inc_"
//HBaseUpCoinInc 投币相关
HBaseUpCoinInc = "up_coin_inc_"
//HBaseUpFavInc 收藏相关
HBaseUpFavInc = "up_fav_inc_"
//HBaseUpElecInc 充电相关
HBaseUpElecInc = "up_elec_inc_"
//HBaseUpFansAnalysis 粉丝管理
HBaseUpFansAnalysis = "up_fans_analysis"
//HBaseUpPlaySourceAnalysis 播放来源
HBaseUpPlaySourceAnalysis = "up_play_analysis"
//HBaseUpArcPlayAnalysis 平均观看时长、播放用户数、留存率
HBaseUpArcPlayAnalysis = "up_archive_play_analysis"
//HBaseUpArcQuery 稿件索引表
HBaseUpArcQuery = "up_archive_query"
//HBasePlayArc 播放相关 archive for 30 days
HBasePlayArc = "up_play_trend"
//HBaseDmArc 弹幕相关
HBaseDmArc = "up_dm_trend"
//HBaseReplyArc 评论相关
HBaseReplyArc = "up_reply_trend"
//HBaseShareArc 分享相关
HBaseShareArc = "up_share_trend"
//HBaseCoinArc 投币相关
HBaseCoinArc = "up_coin_trend"
//HBaseFavArc 收藏相关
HBaseFavArc = "up_fav_trend"
//HBaseElecArc 充电相关
HBaseElecArc = "up_elec_trend"
//HBaseFamilyPlat family
HBaseFamilyPlat = []byte("v")
//HBaseColumnAid aid
HBaseColumnAid = []byte("avid")
//HBaseColumnWebPC pc
HBaseColumnWebPC = []byte("plat0")
//HBaseColumnWebH5 h5
HBaseColumnWebH5 = []byte("plat1")
//HBaseColumnOutsite out
HBaseColumnOutsite = []byte("plat2")
//HBaseColumnIOS ios
HBaseColumnIOS = []byte("plat3")
//HBaseColumnAndroid android
HBaseColumnAndroid = []byte("plat4")
//HBaseColumnElse else
HBaseColumnElse = []byte("else")
//HBaseColumnFans fans
HBaseColumnFans = []byte("fans")
//HBaseColumnGuest guest
HBaseColumnGuest = []byte("guest")
//HBaseColumnAll all
HBaseColumnAll = []byte("all")
//HBaseColumnCoin coin
HBaseColumnCoin = []byte("coin")
//HBaseColumnElec elec
HBaseColumnElec = []byte("elec")
//HBaseColumnFav fav
HBaseColumnFav = []byte("fav")
//HBaseColumnShare share
HBaseColumnShare = []byte("share")
)

View File

@@ -0,0 +1 @@
package data

View File

@@ -0,0 +1,62 @@
package data
import (
"bytes"
"context"
"crypto/md5"
"encoding/hex"
"go-common/app/service/main/up/model/data"
"go-common/library/ecode"
"go-common/library/log"
"strconv"
)
func hbaseMd5Key(aid int64) []byte {
hasher := md5.New()
hasher.Write([]byte(strconv.Itoa(int(aid))))
return []byte(hex.EncodeToString(hasher.Sum(nil)))
}
// BaseUpStat get base up stat.
func (d *Dao) BaseUpStat(c context.Context, mid int64, date string) (stat *data.UpBaseStat, err error) {
var (
ctx, cancel = context.WithTimeout(c, d.hbaseTimeOut)
tableName = HBaseUpStatTablePrefix + date // change table at 12:00am
)
defer cancel()
result, err := d.hbase.Get(ctx, []byte(tableName), hbaseMd5Key(mid))
if err != nil {
log.Error("BaseUpStat d.hbase.Get BackupTable(%s, %d) error(%v)", tableName, mid, err)
err = ecode.ServerErr
return
}
if result == nil {
log.Error("BaseUpStat d.hbase.Get BackupTable(%s, %d) result nil", tableName, mid)
return
}
stat = &data.UpBaseStat{}
for _, c := range result.Cells {
if c == nil {
continue
}
v, _ := strconv.ParseInt(string(c.Value[:]), 10, 64)
if !bytes.Equal(c.Family, []byte("u")) {
continue
}
switch {
case bytes.Equal(c.Qualifier, []byte("play")):
stat.View = v
case bytes.Equal(c.Qualifier, []byte("dm")):
stat.Dm = v
case bytes.Equal(c.Qualifier, []byte("reply")):
stat.Reply = v
case bytes.Equal(c.Qualifier, []byte("fans")):
stat.Fans = v
case bytes.Equal(c.Qualifier, []byte("fav")):
stat.Fav = v
case bytes.Equal(c.Qualifier, []byte("like")):
stat.Like = v
}
}
return
}

View File

@@ -0,0 +1,53 @@
package data
import (
"context"
"github.com/bouk/monkey"
"github.com/tsuna/gohbase/hrpc"
"go-common/library/database/hbase.v2"
"reflect"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDatahbaseMd5Key(t *testing.T) {
var (
aid = int64(0)
)
convey.Convey("hbaseMd5Key", t, func(ctx convey.C) {
p1 := hbaseMd5Key(aid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestDataBaseUpStat(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
date = ""
)
// Hbase never ok
convey.Convey("BaseUpStat", t, func(ctx convey.C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "Get", func(_ *hbase.Client, _ context.Context, _ []byte, _ []byte, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
cells := make([]*hrpc.Cell, 5)
for i := range cells {
cell := new(hrpc.Cell)
cell.Value = []byte("test")
cells[i] = cell
}
res := &hrpc.Result{
Cells: cells,
}
return res, nil
})
defer guard.Unpatch()
stat, err := d.BaseUpStat(c, mid, date)
ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(stat, convey.ShouldNotBeNil)
})
})
}

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 = ["resource_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["resource.go"],
importpath = "go-common/app/service/main/up/dao/global",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/account/api:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//library/database/sql:go_default_library",
"//library/sync/pipeline/fanout:go_default_library",
"//vendor/github.com/pkg/errors: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,59 @@
package global
import (
"runtime"
accgrpc "go-common/app/service/main/account/api"
arcgrpc "go-common/app/service/main/archive/api"
"go-common/app/service/main/up/conf"
"go-common/library/database/sql"
"go-common/library/sync/pipeline/fanout"
"github.com/pkg/errors"
)
var (
upCrmDB *sql.DB
worker *fanout.Fanout
arcCli arcgrpc.ArchiveClient
accCli accgrpc.AccountClient
)
// GetArcClient .
func GetArcClient() arcgrpc.ArchiveClient {
return arcCli
}
// GetAccClient .
func GetAccClient() accgrpc.AccountClient {
return accCli
}
// GetWorker .
func GetWorker() *fanout.Fanout {
return worker
}
// GetUpCrmDB .
func GetUpCrmDB() *sql.DB {
return upCrmDB
}
//Init init global
func Init(c *conf.Config) {
var err error
if arcCli, err = arcgrpc.NewClient(c.GRPCClient.Archive); err != nil {
panic(errors.WithMessage(err, "Failed to dial archive service"))
}
if accCli, err = accgrpc.NewClient(c.GRPCClient.Account); err != nil {
panic(errors.WithMessage(err, "Failed to dial account service"))
}
upCrmDB = sql.NewMySQL(c.DB.UpCRM)
worker = fanout.New("cache", fanout.Worker(runtime.NumCPU()), fanout.Buffer(1024))
}
// Close .
func Close() {
upCrmDB.Close()
worker.Close()
}

View File

@@ -0,0 +1,100 @@
package global
import (
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
"github.com/smartystreets/goconvey/convey"
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.up-service")
flag.Set("conf_token", "5f1660060bb011e8865c66d44b23cda7")
flag.Set("tree_id", "15572")
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
Init(conf.Conf)
os.Exit(m.Run())
}
func TestGlobalGetArcClient(t *testing.T) {
convey.Convey("GetArcClient", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := GetArcClient()
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalGetAccClient(t *testing.T) {
convey.Convey("GetAccClient", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := GetAccClient()
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalGetWorker(t *testing.T) {
convey.Convey("GetWorker", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := GetWorker()
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalGetUpCrmDB(t *testing.T) {
convey.Convey("GetUpCrmDB", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := GetUpCrmDB()
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestGlobalInit(t *testing.T) {
convey.Convey("Init", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
Init(conf.Conf)
convCtx.Convey("No return values", func(convCtx convey.C) {
})
})
})
}
func TestGlobalClose(t *testing.T) {
convey.Convey("Close", t, func(convCtx convey.C) {
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
Close()
convCtx.Convey("No return values", func(convCtx convey.C) {
})
})
})
}

View File

@@ -0,0 +1,75 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao.cache_test.go",
"dao_test.go",
"mc.cache_test.go",
"up_group_test.go",
"up_mc_test.go",
"up_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/api/v1:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.cache.go",
"dao.go",
"mc.cache.go",
"up.go",
"up_group.go",
"up_mc.go",
],
importpath = "go-common/app/service/main/up/dao/manager",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/api/v1:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/stat/prom:go_default_library",
"//library/sync/errgroup:go_default_library",
"//library/sync/pipeline/fanout: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,139 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package manager is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpsSpecial(c context.Context, mids []int64) (map[int64]*upgrpc.UpSpecial, error)
}
*/
package manager
import (
"context"
"sync"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/library/stat/prom"
"go-common/library/sync/errgroup"
)
var _ _cache
// UpSpecial get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpSpecial(c context.Context, id int64) (res *upgrpc.UpSpecial, err error) {
addCache := true
res, err = d.CacheUpSpecial(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && len(res.GroupIDs) > 0 && res.GroupIDs[0] == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("UpSpecial")
return
}
prom.CacheMiss.Incr("UpSpecial")
res, err = d.RawUpSpecial(c, id)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &upgrpc.UpSpecial{GroupIDs: []int64{-1}}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpSpecial(c, id, miss)
})
return
}
// UpsSpecial get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpsSpecial(c context.Context, keys []int64) (res map[int64]*upgrpc.UpSpecial, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheUpsSpecial(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("UpsSpecial", int64(len(keys)-len(miss)))
for k, v := range res {
if v != nil && len(v.GroupIDs) > 0 && v.GroupIDs[0] == -1 {
delete(res, k)
}
}
missLen := len(miss)
if missLen == 0 {
return
}
missData := make(map[int64]*upgrpc.UpSpecial, missLen)
prom.CacheMiss.Add("UpsSpecial", int64(missLen))
var mutex sync.Mutex
group, ctx := errgroup.WithContext(c)
if missLen > 1 {
group.GOMAXPROCS(1)
}
var run = func(ms []int64) {
group.Go(func() (err error) {
data, err := d.RawUpsSpecial(ctx, ms)
mutex.Lock()
for k, v := range data {
missData[k] = v
}
mutex.Unlock()
return
})
}
var (
i int
n = missLen / 100
)
for i = 0; i < n; i++ {
run(miss[i*n : (i+1)*n])
}
if len(miss[i*n:]) > 0 {
run(miss[i*n:])
}
err = group.Wait()
if res == nil {
res = make(map[int64]*upgrpc.UpSpecial, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
for _, key := range miss {
if res[key] == nil {
missData[key] = &upgrpc.UpSpecial{GroupIDs: []int64{-1}}
}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpsSpecial(c, missData)
})
return
}

View File

@@ -0,0 +1,40 @@
package manager
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUpSpecial(t *testing.T) {
convey.Convey("UpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(27515256)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.UpSpecial(c, id)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerUpsSpecial(t *testing.T) {
convey.Convey("UpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
keys = []int64{27515256}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.UpsSpecial(c, keys)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,146 @@
package manager
import (
"context"
gosql "database/sql"
"net/url"
"strings"
"time"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao/global"
"go-common/library/cache/memcache"
"go-common/library/database/sql"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/sync/pipeline/fanout"
"go-common/library/xstr"
)
const (
//URLUNames url for names
URLUNames = "/x/admin/manager/users/unames"
//URLUids url for uids
URLUids = "/x/admin/manager/users/uids"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
managerDB *sql.DB
HTTPClient *bm.Client
// cache tool
cache *fanout.Fanout
// mc
mc *memcache.Pool
// upSpecial expiration
upSpecialExpire int32
}
// New fn
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
managerDB: sql.NewMySQL(c.DB.Manager),
// http client
HTTPClient: bm.NewClient(c.HTTPClient.Normal),
mc: memcache.NewPool(c.Memcache.Up),
upSpecialExpire: int32(time.Duration(c.Memcache.UpSpecialExpire) / time.Second),
cache: global.GetWorker(),
}
return d
}
// Close fn
func (d *Dao) Close() {
if d.managerDB != nil {
d.managerDB.Close()
}
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return d.managerDB.Ping(c)
}
func prepareAndExec(c context.Context, db *sql.DB, sqlstr string, args ...interface{}) (res gosql.Result, err error) {
var stmt *sql.Stmt
stmt, err = db.Prepare(sqlstr)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, sqlstr)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, args...)
if err != nil {
log.Error("data base fail, err=%v", err)
return
}
return
}
func prepareAndQuery(c context.Context, db *sql.DB, sqlstr string, args ...interface{}) (rows *sql.Rows, err error) {
var stmt *sql.Stmt
stmt, err = db.Prepare(sqlstr)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, sqlstr)
return
}
defer stmt.Close()
rows, err = stmt.Query(c, args...)
if err != nil {
log.Error("data base fail, err=%v", err)
return
}
return
}
//GetUNamesByUids get uname by uid
func (d *Dao) GetUNamesByUids(c context.Context, uids []int64) (res map[int64]string, err error) {
var param = url.Values{}
var uidStr = xstr.JoinInts(uids)
param.Set("uids", uidStr)
var httpRes struct {
Code int `json:"code"`
Data map[int64]string `json:"data"`
Message string `json:"message"`
}
err = d.HTTPClient.Get(c, d.c.Host.Manager+URLUNames, "", param, &httpRes)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.c.Host.Manager+URLUNames+"?"+param.Encode(), err)
return
}
if httpRes.Code != 0 {
log.Error("url(%s) error(%v), code(%d), message(%s)", d.c.Host.Manager+URLUNames+"?"+param.Encode(), err, httpRes.Code, httpRes.Message)
}
res = httpRes.Data
return
}
//GetUIDByNames get uid by uname
func (d *Dao) GetUIDByNames(c context.Context, names []string) (res map[string]int64, err error) {
var param = url.Values{}
var namesStr = strings.Join(names, ",")
param.Set("unames", namesStr)
var httpRes struct {
Code int `json:"code"`
Data map[string]int64 `json:"data"`
Message string `json:"message"`
}
err = d.HTTPClient.Get(c, d.c.Host.Manager+URLUids, "", param, &httpRes)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.c.Host.Manager+URLUids+"?"+param.Encode(), err)
return
}
if httpRes.Code != 0 {
log.Error("url(%s) error(%v), code(%d), message(%s)", d.c.Host.Manager+URLUids+"?"+param.Encode(), err, httpRes.Code, httpRes.Message)
}
res = httpRes.Data
return
}

View File

@@ -0,0 +1,119 @@
package manager
import (
"context"
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/dao/global"
"go-common/library/net/http/blademaster"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
global.Init(conf.Conf)
d = New(conf.Conf)
d.HTTPClient = blademaster.NewClient(conf.Conf.HTTPClient.Normal)
m.Run()
os.Exit(0)
}
func TestManagerPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestManagerprepareAndExec(t *testing.T) {
var (
c = context.TODO()
db = d.managerDB
sqlstr = _selectByID
args = interface{}(0)
)
convey.Convey("prepareAndExec", t, func(ctx convey.C) {
res, err := prepareAndExec(c, db, sqlstr, args)
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 TestManagerprepareAndQuery(t *testing.T) {
var (
c = context.TODO()
db = d.managerDB
sqlstr = _selectByID
args = interface{}(0)
)
convey.Convey("prepareAndQuery", t, func(ctx convey.C) {
rows, err := prepareAndQuery(c, db, sqlstr, args)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
}
func TestManagerGetUNamesByUids(t *testing.T) {
var (
c = context.TODO()
uids = []int64{100}
)
convey.Convey("GetUNamesByUids", t, func(ctx convey.C) {
res, err := d.GetUNamesByUids(c, uids)
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 TestManagerGetUIDByNames(t *testing.T) {
var (
c = context.TODO()
names = []string{"wangzhe01"}
)
convey.Convey("GetUIDByNames", t, func(ctx convey.C) {
res, err := d.GetUIDByNames(c, names)
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,172 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package manager is a generated mc cache package.
It is generated from:
type _mc interface {
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpSpecial(c context.Context, mid int64, us *upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpSpecial(c context.Context, mid int64) (res *upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpSpecial(c context.Context, mid int64) (err error)
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpsSpecial(c context.Context, mu map[int64]*upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpsSpecial(c context.Context, mid []int64) (res map[int64]*upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpsSpecial(c context.Context, mids []int64) (err error)
}
*/
package manager
import (
"context"
"fmt"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// AddCacheUpSpecial Set data to mc
func (d *Dao) AddCacheUpSpecial(c context.Context, id int64, val *upgrpc.UpSpecial) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upSpecialExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpSpecial")
log.Errorv(c, log.KV("AddCacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUpSpecial get data from mc
func (d *Dao) CacheUpSpecial(c context.Context, id int64) (res *upgrpc.UpSpecial, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUpSpecial")
log.Errorv(c, log.KV("CacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &upgrpc.UpSpecial{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpSpecial")
log.Errorv(c, log.KV("CacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUpSpecial delete data from mc
func (d *Dao) DelCacheUpSpecial(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUpSpecial")
log.Errorv(c, log.KV("DelCacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUpsSpecial Set data to mc
func (d *Dao) AddCacheUpsSpecial(c context.Context, values map[int64]*upgrpc.UpSpecial) (err error) {
if len(values) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for id, val := range values {
key := upSpecialCacheKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upSpecialExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpsSpecial")
log.Errorv(c, log.KV("AddCacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}
// CacheUpsSpecial get data from mc
func (d *Dao) CacheUpsSpecial(c context.Context, ids []int64) (res map[int64]*upgrpc.UpSpecial, err error) {
l := len(ids)
if l == 0 {
return
}
keysMap := make(map[string]int64, l)
keys := make([]string, 0, l)
for _, id := range ids {
key := upSpecialCacheKey(id)
keysMap[key] = id
keys = append(keys, key)
}
conn := d.mc.Get(c)
defer conn.Close()
replies, err := conn.GetMulti(keys)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsSpecial")
log.Errorv(c, log.KV("CacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
return
}
for key, reply := range replies {
var v *upgrpc.UpSpecial
v = &upgrpc.UpSpecial{}
err = conn.Scan(reply, v)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsSpecial")
log.Errorv(c, log.KV("CacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
if res == nil {
res = make(map[int64]*upgrpc.UpSpecial, len(keys))
}
res[keysMap[key]] = v
}
return
}
// DelCacheUpsSpecial delete data from mc
func (d *Dao) DelCacheUpsSpecial(c context.Context, ids []int64) (err error) {
if len(ids) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for _, id := range ids {
key := upSpecialCacheKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
continue
}
prom.BusinessErrCount.Incr("mc:DelCacheUpsSpecial")
log.Errorv(c, log.KV("DelCacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}

View File

@@ -0,0 +1,102 @@
package manager
import (
"context"
upgrpc "go-common/app/service/main/up/api/v1"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerAddCacheUpSpecial(t *testing.T) {
convey.Convey("AddCacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
val = &upgrpc.UpSpecial{}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddCacheUpSpecial(c, id, val)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerCacheUpSpecial(t *testing.T) {
convey.Convey("CacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.CacheUpSpecial(c, id)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerDelCacheUpSpecial(t *testing.T) {
convey.Convey("DelCacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.DelCacheUpSpecial(c, id)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerAddCacheUpsSpecial(t *testing.T) {
convey.Convey("AddCacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
values map[int64]*upgrpc.UpSpecial
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddCacheUpsSpecial(c, values)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerCacheUpsSpecial(t *testing.T) {
convey.Convey("CacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
ids = []int64{27515256}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.CacheUpsSpecial(c, ids)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerDelCacheUpsSpecial(t *testing.T) {
convey.Convey("DelCacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
ids = []int64{}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.DelCacheUpsSpecial(c, ids)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,372 @@
package manager
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_upsWithGroupBase = "SELECT ups.id,mid,up_group.id as group_id ,up_group.short_tag as group_tag,up_group.name as group_name,ups.note,ups.ctime, ups.mtime, ups.uid FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upsWithGroupBaseWithColor = "SELECT ups.id,mid,up_group.id as group_id ,up_group.short_tag as group_tag,up_group.name as group_name,ups.note,ups.ctime, ups.mtime, ups.uid, up_group.colors FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upsWithGroup = _upsWithGroupBaseWithColor + "limit ? offset ? "
_upsWithGroupByMtime = _upsWithGroupBaseWithColor + "where ups.mtime >= ?"
_delByMid = "DELETE FROM ups where id = ?"
_insertMidType = "INSERT INTO ups (mid, type, note, ctime, mtime, uid) values "
_selectByMidTypeWithGroup = _upsWithGroupBase + "where mid = ? and type = ?"
_updateByID = "update ups set type=?, note=?, uid=?, mtime=? where id = ?"
//MysqlTimeFormat mysql time format
MysqlTimeFormat = "2006-01-02 15:04:05"
_selectByID = _upsWithGroupBase + "where ups.id = ?"
_selectCount = "SELECT COUNT(0) FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upSpecialSQL = "SELECT type FROM ups WHERE mid = ?"
_upsSpecialSQL = "SELECT mid, type FROM ups WHERE mid IN (%s)"
_upGroupsMidsSQL = "SELECT id, mid, type FROM ups WHERE id > ? AND type IN (%s) LIMIT ?"
)
// UpSpecials load all ups with group info
func (d *Dao) UpSpecials(c context.Context) (ups []*model.UpSpecial, err error) {
log.Info("start refresh ups table")
stmt, err := d.managerDB.Prepare(_upsWithGroup)
if err != nil {
log.Error("d.managerDB.Prepare error(%v)", err)
return
}
defer stmt.Close()
var offset = 0
var limit = 1000
var cnt = 0
var isFirst = true
for isFirst || cnt == limit {
isFirst = false
rows, err1 := stmt.Query(c, limit, offset)
if err1 != nil {
err = err1
log.Error("stmt.Query error(%v)", err1)
return
}
cnt = 0
for rows.Next() {
cnt++
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
ups = append(ups, up)
}
rows.Close()
if err != nil {
return
}
log.Info("reading data from table, read count=%d", cnt)
offset += cnt
}
log.Info("end refresh ups table, read count=%d", offset)
return
}
//RefreshUpSpecialIncremental refresh cache incrementally
func (d *Dao) RefreshUpSpecialIncremental(c context.Context, lastMTime time.Time) (ups []*model.UpSpecial, err error) {
var timeStr = lastMTime.Format(MysqlTimeFormat)
log.Info("start refresh ups table mtime>%s", timeStr)
stmt, err := d.managerDB.Prepare(_upsWithGroupByMtime)
if err != nil {
log.Error("d.managerDB.Prepare error(%v)", err)
return
}
defer stmt.Close()
var cnt = 0
rows, err1 := stmt.Query(c, timeStr)
if err1 != nil {
err = err1
log.Error("stmt.Query error(%v)", err1)
return
}
cnt = 0
for rows.Next() {
cnt++
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
if err != nil {
log.Error("scan row err, %v", err)
break
}
ups = append(ups, up)
}
rows.Close()
if err != nil {
return
}
log.Info("reading data from table, read count=%d", cnt)
return
}
//DelSpecialByID delete special by id
func (d *Dao) DelSpecialByID(c context.Context, id int64) (res sql.Result, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_delByMid)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _delByMid)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, id)
if err != nil {
log.Error("delete mid from ups fail, id=%d, err=%v", id, err)
}
return
}
//InsertSpecial insert special
func (d *Dao) InsertSpecial(c context.Context, special *model.UpSpecial, mids ...int64) (res sql.Result, err error) {
var count = len(mids)
if count == 0 {
err = errors.New("no data need update")
return
}
var insertSchema []string
var vals []interface{}
var nowStr = time.Now().Format(MysqlTimeFormat)
for _, mid := range mids {
insertSchema = append(insertSchema, "(?,?,?,?,?,?)")
vals = append(vals, mid, special.GroupID, special.Note, nowStr, nowStr, special.UID)
}
var insertSQL = _insertMidType + strings.Join(insertSchema, ",")
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(insertSQL)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, insertSQL)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, vals...)
if err != nil {
log.Error("insert ups fail, err=%v, groupid=%d, note=%s, mid=%v", err, special.GroupID, special.Note, mids)
}
return
}
//UpdateSpecialByID update special by id
func (d *Dao) UpdateSpecialByID(c context.Context, id int64, special *model.UpSpecial) (res sql.Result, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_updateByID)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _updateByID)
return
}
defer stmt.Close()
var timeStr = time.Now().Format(MysqlTimeFormat)
res, err = stmt.Exec(c, special.GroupID, special.Note, special.UID, timeStr, id)
if err != nil {
log.Error("update ups fail, err=%v, groupid=%d, note=%s, id=%d", err, special.GroupID, special.Note, id)
}
return
}
//GetSpecialByMidGroup get special by mid and group
func (d *Dao) GetSpecialByMidGroup(c context.Context, mid int64, groupID int64) (res *model.UpSpecial, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_selectByMidTypeWithGroup)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _selectByMidTypeWithGroup)
return
}
defer stmt.Close()
row := stmt.QueryRow(c, mid, groupID)
var note sql.NullString
var up = model.UpSpecial{}
switch err = row.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID); err {
case sql.ErrNoRows:
err = nil
return
case nil:
up.Note = note.String
res = &up
default:
log.Error("rows.Scan error(%v)", err)
return
}
return
}
//GetSpecialByID get special by id
func (d *Dao) GetSpecialByID(c context.Context, id int64) (res *model.UpSpecial, err error) {
rows, err := prepareAndQuery(c, d.managerDB, _selectByID, id)
if err != nil {
return
}
defer rows.Close()
var note sql.NullString
for rows.Next() {
var up = &model.UpSpecial{}
err = rows.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID)
up.Note = note.String
res = up
break
}
return
}
//GetSepcialCount get special count
func (d *Dao) GetSepcialCount(c context.Context, conditions ...dao.Condition) (count int, err error) {
var conditionStr, args, hasOperator = dao.ConcatCondition(conditions...)
var where = " WHERE "
if !hasOperator {
where = ""
}
rows, err := prepareAndQuery(c, d.managerDB, _selectCount+where+conditionStr, args...)
if err != nil {
log.Error("get special db fail, err=%+v", err)
return
}
defer rows.Close()
for rows.Next() {
rows.Scan(&count)
}
return
}
func parseUpGroupWithColor(rows *xsql.Rows) (up *model.UpSpecial, err error) {
var note sql.NullString
var colors sql.NullString
up = &model.UpSpecial{}
err = rows.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID, &colors)
if err != nil {
log.Error("scan row err, %v", err)
return
}
up.Note = note.String
if colors.Valid {
var colors = strings.Split(colors.String, "|")
if len(colors) >= 2 {
up.FontColor = colors[0]
up.BgColor = colors[1]
}
}
return
}
//GetSpecial get special from db
func (d *Dao) GetSpecial(c context.Context, conditions ...dao.Condition) (res []*model.UpSpecial, err error) {
var conditionStr, args, hasOperator = dao.ConcatCondition(conditions...)
var where = " WHERE "
if !hasOperator {
where = ""
}
rows, err := prepareAndQuery(c, d.managerDB, _upsWithGroupBaseWithColor+where+conditionStr, args...)
if err != nil {
log.Error("get special db fail, err=%+v", err)
return
}
defer rows.Close()
for rows.Next() {
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
if err != nil {
log.Error("scan row err, %v", err)
break
}
res = append(res, up)
}
return
}
//GetSpecialByMid get speical by mid
func (d *Dao) GetSpecialByMid(c context.Context, mid int64) (res []*model.UpSpecial, err error) {
var condition = dao.Condition{
Key: "ups.mid",
Operator: "=",
Value: mid,
}
return d.GetSpecial(c, condition)
}
// RawUpSpecial get up special propertys
func (d *Dao) RawUpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error) {
rows, err := d.managerDB.Query(c, _upSpecialSQL, mid)
if err != nil {
return
}
defer rows.Close()
us = new(upgrpc.UpSpecial)
for rows.Next() {
var groupID int64
if err = rows.Scan(&groupID); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
us.GroupIDs = append(us.GroupIDs, groupID)
}
return
}
// RawUpsSpecial get mult up special propertys
func (d *Dao) RawUpsSpecial(c context.Context, mids []int64) (mu map[int64]*upgrpc.UpSpecial, err error) {
rows, err := d.managerDB.Query(c, fmt.Sprintf(_upsSpecialSQL, xstr.JoinInts(mids)))
if err != nil {
return
}
defer rows.Close()
mu = make(map[int64]*upgrpc.UpSpecial, len(mids))
for rows.Next() {
var mid, groupID int64
if err = rows.Scan(&mid, &groupID); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
if mu[mid] == nil {
mu[mid] = new(upgrpc.UpSpecial)
}
mu[mid].GroupIDs = append(mu[mid].GroupIDs, groupID)
}
return
}
// UpGroupsMids get mids in one group.
func (d *Dao) UpGroupsMids(c context.Context, groupIDs []int64, lastID int64, ps int) (lid int64, gmids map[int64][]int64, err error) {
rows, err := d.managerDB.Query(c, fmt.Sprintf(_upGroupsMidsSQL, xstr.JoinInts(groupIDs)), lastID, ps)
if err != nil {
return
}
defer rows.Close()
gmids = make(map[int64][]int64)
for rows.Next() {
var id, gid, mid int64
if err = rows.Scan(&id, &mid, &gid); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
if id > lid {
lid = id
}
gmids[gid] = append(gmids[gid], mid)
}
return
}

View File

@@ -0,0 +1,138 @@
package manager
import (
"context"
"database/sql"
"fmt"
"strings"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
_insertGroup = "INSERT INTO up_group (name, tag, short_tag, colors, remark) VALUES (?,?,?,?,?)"
_checkGroupExist = "SELECT COUNT(0) FROM up_group WHERE (name=? OR tag=? OR short_tag=?) "
_updateGroupByID = "UPDATE up_group SET name=?, tag=?, short_tag=?, colors=?, remark=? WHERE id=?"
_removeGroupByID = "UPDATE up_group SET state=0 WHERE id=?"
_selectGroup = "SELECT id, name, tag, short_tag, remark, colors, state FROM up_group "
_upGroupsSQL = "SELECT id, name, tag, short_tag, remark, colors FROM up_group WHERE state = 1"
)
//AddGroup add group in db
func (d *Dao) AddGroup(c context.Context, groupAddInfo *model.AddGroupArg) (res sql.Result, err error) {
var color = fmt.Sprintf("%s|%s", groupAddInfo.FontColor, groupAddInfo.BgColor)
res, err = prepareAndExec(c, d.managerDB, _insertGroup, groupAddInfo.Name, groupAddInfo.Tag, groupAddInfo.ShortTag, color, groupAddInfo.Remark)
return
}
//CheckGroupExist check if group exist
func (d *Dao) CheckGroupExist(c context.Context, groupAddInfo *model.AddGroupArg, exceptid int64) (exist bool, err error) {
var sqlStr = _checkGroupExist
var args = []interface{}{groupAddInfo.Name, groupAddInfo.Tag, groupAddInfo.ShortTag}
if exceptid != 0 {
sqlStr += " AND id != ?"
args = append(args, exceptid)
}
rows, err := prepareAndQuery(c, d.managerDB, sqlStr, args...)
if err != nil {
return
}
defer rows.Close()
var count int
for rows.Next() {
err = rows.Scan(&count)
break
}
if err != nil {
return
}
exist = count > 0
return
}
//UpdateGroup update group
func (d *Dao) UpdateGroup(c context.Context, groupAddInfo *model.EditGroupArg) (res sql.Result, err error) {
if groupAddInfo.AddArg == nil {
return
}
var color = fmt.Sprintf("%s|%s", groupAddInfo.AddArg.FontColor, groupAddInfo.AddArg.BgColor)
res, err = prepareAndExec(c, d.managerDB, _updateGroupByID, groupAddInfo.AddArg.Name, groupAddInfo.AddArg.Tag, groupAddInfo.AddArg.ShortTag, color, groupAddInfo.AddArg.Remark, groupAddInfo.ID)
return
}
//RemoveGroup remove group
func (d *Dao) RemoveGroup(c context.Context, arg *model.RemoveGroupArg) (res sql.Result, err error) {
res, err = prepareAndExec(c, d.managerDB, _removeGroupByID, arg.ID)
return
}
//GetGroup get group
func (d *Dao) GetGroup(c context.Context, arg *model.GetGroupArg) (res []*model.UpGroup, err error) {
var con = dao.Condition{
Key: "state",
Operator: "=",
Value: arg.State,
}
var conditionStr, vals, _ = dao.ConcatCondition(con)
rows, err := prepareAndQuery(c, d.managerDB, _selectGroup+"WHERE "+conditionStr, vals...)
if err != nil {
return
}
defer rows.Close()
// id, name, tag, short_tag, remark, colors
var colorStr string
for rows.Next() {
var group = model.UpGroup{}
err = rows.Scan(&group.ID, &group.Name, &group.Tag, &group.ShortTag, &group.Remark, &colorStr, &group.State)
if err != nil {
log.Error("scan row failed, err=%v", err)
break
}
var colors = strings.Split(colorStr, "|")
if len(colors) >= 2 {
group.FontColor = colors[0]
group.BgColor = colors[1]
}
res = append(res, &group)
}
return
}
// UpGroups get up special group data.
func (d *Dao) UpGroups(c context.Context) (mug map[int64]*upgrpc.UpGroup, err error) {
rows, err := d.managerDB.Query(c, _upGroupsSQL)
if err != nil {
return
}
defer rows.Close()
mug = make(map[int64]*upgrpc.UpGroup)
for rows.Next() {
var (
colorStr string
colors []string
ug = new(upgrpc.UpGroup)
)
if err = rows.Scan(&ug.ID, &ug.Name, &ug.Tag, &ug.ShortTag, &ug.Note, &colorStr); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
colors = strings.Split(colorStr, "|")
if len(colors) >= 2 {
ug.FontColor = colors[0]
ug.BgColor = colors[1]
}
mug[ug.ID] = ug
}
return
}

View File

@@ -0,0 +1,82 @@
package manager
import (
"context"
"go-common/app/service/main/up/model"
"testing"
"github.com/smartystreets/goconvey/convey"
"strings"
)
func TestManagerAddGroup(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.AddGroupArg{}
)
convey.Convey("AddGroup", t, func(ctx convey.C) {
_, err := d.AddGroup(c, groupAddInfo)
if strings.Contains(err.Error(), "Error 1062") {
err = nil
}
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestManagerCheckGroupExist(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.AddGroupArg{}
exceptid = int64(0)
)
convey.Convey("CheckGroupExist", t, func(ctx convey.C) {
exist, err := d.CheckGroupExist(c, groupAddInfo, exceptid)
ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(exist, convey.ShouldNotBeNil)
})
})
}
func TestManagerUpdateGroup(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.EditGroupArg{}
)
convey.Convey("UpdateGroup", t, func(ctx convey.C) {
res, err := d.UpdateGroup(c, groupAddInfo)
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.ShouldBeNil)
})
})
}
func TestManagerRemoveGroup(t *testing.T) {
var (
c = context.TODO()
arg = &model.RemoveGroupArg{}
)
convey.Convey("RemoveGroup", t, func(ctx convey.C) {
res, err := d.RemoveGroup(c, arg)
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 TestManagerGetGroup(t *testing.T) {
var (
c = context.TODO()
arg = &model.GetGroupArg{}
)
convey.Convey("GetGroup", t, func(ctx convey.C) {
_, err := d.GetGroup(c, arg)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,41 @@
package manager
import (
"context"
"fmt"
upgrpc "go-common/app/service/main/up/api/v1"
)
const (
_upSpecialKey = "up_special_%d"
)
// upSpecialCacheKey 缓存key
func upSpecialCacheKey(mid int64) string {
return fmt.Sprintf(_upSpecialKey, mid)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpsSpecial(c context.Context, mids []int64) (map[int64]*upgrpc.UpSpecial, error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpSpecial(c context.Context, mid int64, us *upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpSpecial(c context.Context, mid int64) (res *upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpSpecial(c context.Context, mid int64) (err error)
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpsSpecial(c context.Context, mu map[int64]*upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpsSpecial(c context.Context, mid []int64) (res map[int64]*upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpsSpecial(c context.Context, mids []int64) (err error)
}

View File

@@ -0,0 +1,21 @@
package manager
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerupSpecialCacheKey(t *testing.T) {
convey.Convey("upSpecialCacheKey", t, func(convCtx convey.C) {
var (
mid = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := upSpecialCacheKey(mid)
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,181 @@
package manager
import (
"context"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUpSpecials(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("UpSpecials", t, func(ctx convey.C) {
ups, err := d.UpSpecials(c)
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(ups, convey.ShouldNotBeNil)
})
})
}
func TestManagerRefreshUpSpecialIncremental(t *testing.T) {
var (
c = context.TODO()
lastMTime = time.Now()
)
convey.Convey("RefreshUpSpecialIncremental", t, func(ctx convey.C) {
ups, err := d.RefreshUpSpecialIncremental(c, lastMTime)
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(len(ups), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestManagerDelSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("DelSpecialByID", t, func(ctx convey.C) {
res, err := d.DelSpecialByID(c, id)
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 TestManagerInsertSpecial(t *testing.T) {
var (
c = context.TODO()
special = &model.UpSpecial{}
mids = int64(0)
)
convey.Convey("InsertSpecial", t, func(ctx convey.C) {
res, err := d.InsertSpecial(c, special, mids)
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 TestManagerUpdateSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
special = &model.UpSpecial{}
)
convey.Convey("UpdateSpecialByID", t, func(ctx convey.C) {
res, err := d.UpdateSpecialByID(c, id, special)
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 TestManagerGetSpecialByMidGroup(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
groupID = int64(0)
)
convey.Convey("GetSpecialByMidGroup", t, func(ctx convey.C) {
res, err := d.GetSpecialByMidGroup(c, mid, groupID)
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.ShouldBeNil)
})
})
}
func TestManagerGetSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("GetSpecialByID", t, func(ctx convey.C) {
res, err := d.GetSpecialByID(c, id)
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.ShouldBeNil)
})
})
}
func TestManagerGetSepcialCount(t *testing.T) {
var (
c = context.TODO()
conditions dao.Condition
)
convey.Convey("GetSepcialCount", t, func(ctx convey.C) {
count, err := d.GetSepcialCount(c, conditions)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(count, convey.ShouldNotBeNil)
})
})
}
func TestManagerGetSpecial(t *testing.T) {
var (
c = context.TODO()
conditions dao.Condition
)
convey.Convey("GetSpecial", t, func(ctx convey.C) {
res, err := d.GetSpecial(c, conditions)
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 TestManagerGetSpecialByMid(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
)
convey.Convey("GetSpecialByMid", t, func(ctx convey.C) {
res, err := d.GetSpecialByMid(c, mid)
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.ShouldBeNil)
})
})
}
func TestManagerRawUpSpecial(t *testing.T) {
var (
c = context.TODO()
mid = int64(27515314)
)
convey.Convey("RawUpSpecial", t, func(ctx convey.C) {
res, err := d.RawUpSpecial(c, mid)
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 TestManagerRawUpsSpecial(t *testing.T) {
var (
c = context.TODO()
mids = []int64{27515314}
)
convey.Convey("RawUpsSpecial", t, func(ctx convey.C) {
res, err := d.RawUpsSpecial(c, mids)
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,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 = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/up/dao/monitor",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/model: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,120 @@
package monitor
import (
"bytes"
"context"
"crypto/md5"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"time"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/model"
"go-common/library/log"
)
const (
_uri = "/api/v1/message/add"
_method = "POST"
_fileType = "application/json"
)
// Dao is message dao.
type Dao struct {
c *conf.Config
client *http.Client
url string
}
// New new a message dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
client: &http.Client{
Timeout: time.Duration(time.Second * 1),
},
url: c.Monitor.Host + _uri,
}
return
}
// Send send exception message to owner.
func (d *Dao) Send(c context.Context, username, msg string) (err error) {
params := url.Values{}
now := time.Now().Unix()
params.Set("username", username)
params.Set("content", msg)
params.Set("title", "test")
params.Set("url", "")
params.Set("type", "wechat")
params.Set("token", d.c.Monitor.AppToken)
params.Set("timestamp", strconv.FormatInt(now, 10))
bap := &model.BAP{
UserName: params.Get("username"),
Content: params.Get("content"),
Title: params.Get("title"),
URL: params.Get("url"),
Ty: params.Get("type"),
Token: params.Get("token"),
TimeStamp: now,
Signature: d.getSign(params),
}
jsonStr, err := json.Marshal(bap)
if err != nil {
log.Error("monitor json.Marshal error (%v)", err)
return
}
req, err := http.NewRequest(_method, d.url, bytes.NewBuffer(jsonStr))
if err != nil {
log.Error("monitor http.NewRequest error (%v)", err)
return
}
req.Header.Add("Content-Type", _fileType)
// timeout
ctx, cancel := context.WithTimeout(c, 800*time.Millisecond)
req = req.WithContext(ctx)
defer cancel()
response, err := d.client.Do(req)
if err != nil {
log.Error("monitor d.client.Post error(%v)", err)
return
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
log.Error("monitor http.StatusCode nq http.StatusOK (%d) | url(%s)", response.StatusCode, d.url)
return
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Error("monitor ioutil.ReadAll error(%v)", err)
return
}
var result struct {
Status int `json:"status"`
Msg string `json:"msg"`
}
if err = json.Unmarshal(body, &result); err != nil {
log.Error("monitor json.Unmarshal error(%v)", err)
}
if result.Status != 0 {
log.Error("monitor get status(%d) msg(%s)", result.Status, result.Msg)
}
return
}
func (d *Dao) getSign(params url.Values) (sign string) {
for k, v := range params {
if len(v) == 0 {
params.Del(k)
}
}
h := md5.New()
io.WriteString(h, params.Encode()+d.c.Monitor.AppSecret)
sign = fmt.Sprintf("%x", h.Sum(nil))
return
}

View File

@@ -0,0 +1,69 @@
package monitor
import (
"context"
"flag"
"go-common/app/service/main/up/conf"
"net/url"
"os"
"testing"
"github.com/smartystreets/goconvey/convey"
"go-common/app/service/main/up/dao"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestMonitorSend(t *testing.T) {
var (
c = context.TODO()
username = ""
msg = ""
)
convey.Convey("Send", t, func(ctx convey.C) {
err := d.Send(c, username, msg)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestMonitorgetSign(t *testing.T) {
var (
params url.Values
)
convey.Convey("getSign", t, func(ctx convey.C) {
sign := d.getSign(params)
ctx.Convey("Then sign should not be nil.", func(ctx convey.C) {
ctx.So(sign, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,86 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"api_test.go",
"dao.cache_test.go",
"dao_test.go",
"mc.cache_test.go",
"mc_all_identity_test.go",
"mc_up_test.go",
"sign_up_test.go",
"up_info_test.go",
"up_switch_test.go",
"up_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"api.go",
"dao.cache.go",
"dao.go",
"mc.cache.go",
"mc_all_identity.go",
"mc_up.go",
"sign_up.go",
"up.go",
"up_info.go",
"up_switch.go",
],
importpath = "go-common/app/service/main/up/dao/up",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/openplatform/article/model:go_default_library",
"//app/interface/openplatform/article/rpc/client:go_default_library",
"//app/service/main/up/api/v1:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql: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",
"//library/sync/errgroup:go_default_library",
"//library/sync/pipeline/fanout: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,95 @@
package up
import (
"context"
"net/url"
"strconv"
"go-common/app/interface/openplatform/article/model"
"go-common/library/ecode"
"go-common/library/log"
)
const (
_picUpInfoURI string = "/link_draw_ex/v0/doc/check"
_blinkUpInfoURI string = "/clip_ext/v0/video/have"
)
// Pic pic return value
type Pic struct {
Has int `json:"has_doc"`
}
// Blink blink return value
type Blink struct {
Has int `json:"has"`
}
// Pic get pic up info.
func (d *Dao) Pic(c context.Context, mid int64, ip string) (has int, err error) {
params := url.Values{}
params.Set("uid", strconv.FormatInt(mid, 10))
var res struct {
Code int `json:"code"`
Data Pic `json:"data"`
}
err = d.client.Get(c, d.picUpInfoURL, ip, params, &res)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.picUpInfoURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("Pic url(%s) error(%v)", d.picUpInfoURL+"?"+params.Encode(), err)
err = ecode.Int(res.Code)
return
}
has = res.Data.Has
return
}
// Blink get BLink up info.
func (d *Dao) Blink(c context.Context, mid int64, ip string) (has int, err error) {
params := url.Values{}
params.Set("uid", strconv.FormatInt(mid, 10))
var res struct {
Code int `json:"code"`
Data Blink `json:"data"`
}
err = d.client.Get(c, d.blinkUpInfoURL, ip, params, &res)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.blinkUpInfoURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("Blink url(%s) error(%v)", d.blinkUpInfoURL+"?"+params.Encode(), err)
err = ecode.Int(res.Code)
return
}
has = res.Data.Has
return
}
// IsAuthor checks that whether user has permission to write article.
func (d *Dao) IsAuthor(c context.Context, mid int64, ip string) (isArt int, err error) {
var (
arg = &model.ArgMid{
Mid: mid,
RealIP: ip,
}
res bool
)
if res, err = d.art.IsAuthor(c, arg); err != nil {
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
log.Error("d.art.IsAuthor (%v) error(%v)", arg, err)
err = ecode.CreativeArticleRPCErr
}
if ecode.Cause(err) == ecode.ArtCreationNoPrivilege {
log.Error("d.art.IsAuthor(%d) error(%v)", mid, err)
}
return
}
if res {
isArt = 1
}
return
}

View File

@@ -0,0 +1,82 @@
package up
import (
"context"
"github.com/bouk/monkey"
"github.com/smartystreets/goconvey/convey"
httpx "go-common/library/net/http/blademaster"
"net/url"
"reflect"
"testing"
)
const (
uid = 12345
)
func TestUpPic(t *testing.T) {
var (
c = context.TODO()
mid = int64(uid)
ip = ""
)
convey.Convey("Pic", t, func(ctx convey.C) {
type result struct {
Code int `json:"code"`
Data Pic `json:"data"`
}
res := new(result)
guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.client), "Get", func(_ *httpx.Client, _ context.Context, _, _ string, _ url.Values, _ interface{}) error {
res.Code = 0
res.Data = Pic{Has: 1}
return nil
})
defer guard.Unpatch()
has, err := d.Pic(c, mid, ip)
ctx.Convey("Then err should be nil.has should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(has, convey.ShouldNotBeNil)
})
})
}
func TestUpBlink(t *testing.T) {
var (
c = context.TODO()
mid = int64(uid)
ip = ""
)
convey.Convey("Blink", t, func(ctx convey.C) {
type result struct {
Code int `json:"code"`
Data Blink `json:"data"`
}
res := new(result)
guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.client), "Get", func(_ *httpx.Client, _ context.Context, _, _ string, _ url.Values, _ interface{}) error {
res.Code = 0
res.Data = Blink{Has: 1}
return nil
})
defer guard.Unpatch()
has, err := d.Blink(c, mid, ip)
ctx.Convey("Then err should be nil.has should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(has, convey.ShouldNotBeNil)
})
})
}
func TestUpIsAuthor(t *testing.T) {
var (
c = context.TODO()
mid = int64(uid)
ip = ""
)
convey.Convey("IsAuthor", t, func(ctx convey.C) {
isArt, err := d.IsAuthor(c, mid, ip)
ctx.Convey("Then err should be nil.isArt should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(isArt, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,213 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package up is a generated cache proxy package.
It is generated from:
type _cache interface {
//cache: -nullcache=&model.Up{ID:-1} -check_null_code=$!=nil&&$.ID==-1
Up(c context.Context, mid int64) (up *model.Up, err error)
//cache: -nullcache=&model.UpSwitch{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpSwitch(c context.Context, mid int64) (up *model.UpSwitch, err error)
//cache: -nullcache=&model.UpInfoActiveReply{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpInfoActive(c context.Context, mid int64) (up *model.UpInfoActiveReply, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&model.UpInfoActiveReply{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpsInfoActive(c context.Context, mids []int64) (res map[int64]*model.UpInfoActiveReply, err error)
}
*/
package up
import (
"context"
"sync"
"go-common/app/service/main/up/model"
"go-common/library/stat/prom"
"go-common/library/sync/errgroup"
)
var _ _cache
// Up get data from cache if miss will call source method, then add to cache.
func (d *Dao) Up(c context.Context, id int64) (res *model.Up, err error) {
addCache := true
res, err = d.CacheUp(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && res.ID == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("Up")
return
}
prom.CacheMiss.Incr("Up")
res, err = d.RawUp(c, id)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &model.Up{ID: -1}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUp(c, id, miss)
})
return
}
// UpSwitch get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpSwitch(c context.Context, id int64) (res *model.UpSwitch, err error) {
addCache := true
res, err = d.CacheUpSwitch(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && res.ID == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("UpSwitch")
return
}
prom.CacheMiss.Incr("UpSwitch")
res, err = d.RawUpSwitch(c, id)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &model.UpSwitch{ID: -1}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpSwitch(c, id, miss)
})
return
}
// UpInfoActive get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpInfoActive(c context.Context, id int64) (res *model.UpInfoActiveReply, err error) {
addCache := true
res, err = d.CacheUpInfoActive(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && res.ID == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("UpInfoActive")
return
}
prom.CacheMiss.Incr("UpInfoActive")
res, err = d.RawUpInfoActive(c, id)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &model.UpInfoActiveReply{ID: -1}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpInfoActive(c, id, miss)
})
return
}
// UpsInfoActive get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpsInfoActive(c context.Context, keys []int64) (res map[int64]*model.UpInfoActiveReply, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheUpsInfoActive(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("UpsInfoActive", int64(len(keys)-len(miss)))
for k, v := range res {
if v != nil && v.ID == -1 {
delete(res, k)
}
}
missLen := len(miss)
if missLen == 0 {
return
}
missData := make(map[int64]*model.UpInfoActiveReply, missLen)
prom.CacheMiss.Add("UpsInfoActive", int64(missLen))
var mutex sync.Mutex
group, ctx := errgroup.WithContext(c)
if missLen > 1 {
group.GOMAXPROCS(1)
}
var run = func(ms []int64) {
group.Go(func() (err error) {
data, err := d.RawUpsInfoActive(ctx, ms)
mutex.Lock()
for k, v := range data {
missData[k] = v
}
mutex.Unlock()
return
})
}
var (
i int
n = missLen / 100
)
for i = 0; i < n; i++ {
run(miss[i*n : (i+1)*n])
}
if len(miss[i*n:]) > 0 {
run(miss[i*n:])
}
err = group.Wait()
if res == nil {
res = make(map[int64]*model.UpInfoActiveReply, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
for _, key := range miss {
if res[key] == nil {
missData[key] = &model.UpInfoActiveReply{ID: -1}
}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpsInfoActive(c, missData)
})
return
}

View File

@@ -0,0 +1,70 @@
package up
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpUp(t *testing.T) {
convey.Convey("Up", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Up(c, id)
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 TestUpUpSwitch(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("UpSwitch", t, func(ctx convey.C) {
_, err := d.UpSwitch(c, id)
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 TestUpUpInfoActive(t *testing.T) {
convey.Convey("UpInfoActive", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UpInfoActive(c, id)
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 TestUpUpsInfoActive(t *testing.T) {
convey.Convey("UpsInfoActive", t, func(ctx convey.C) {
var (
c = context.Background()
keys = []int64{0}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UpsInfoActive(c, keys)
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,80 @@
package up
import (
"context"
"time"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao/global"
"go-common/library/cache/memcache"
"go-common/library/database/sql"
httpx "go-common/library/net/http/blademaster"
"go-common/library/sync/pipeline/fanout"
article "go-common/app/interface/openplatform/article/rpc/client"
)
// DateLayout date layout
const DateLayout = "2006-01-02"
// Dao is creative dao.
type Dao struct {
// config
c *conf.Config
// db
db *sql.DB
//cache tool
cache *fanout.Fanout
//memcache pool
mcPool *memcache.Pool
mc *memcache.Pool
//up expiration
upExpire int32
// http client
client *httpx.Client
//api url
picUpInfoURL string
blinkUpInfoURL string
// rpc
art *article.Service
}
// New init db.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: sql.NewMySQL(c.DB.Creative),
cache: global.GetWorker(),
mcPool: memcache.NewPool(c.Memcache.Up),
upExpire: int32(time.Duration(c.Memcache.UpExpire) / time.Second),
// http client
client: httpx.NewClient(c.HTTPClient.Normal),
picUpInfoURL: c.Host.Live + _picUpInfoURI,
blinkUpInfoURL: c.Host.Live + _blinkUpInfoURI,
// rpc
art: article.New(c.ArticleRPC),
}
d.mc = d.mcPool
return
}
// Ping creativeDb
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}
// Close db
func (d *Dao) Close() (err error) {
if d.db != nil {
d.db.Close()
}
if d.mcPool != nil {
d.mcPool.Close()
}
return
}
//GetHTTPClient get http client
func (d *Dao) GetHTTPClient() *httpx.Client {
return d.client
}

View File

@@ -0,0 +1,74 @@
package up
import (
"context"
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/dao/global"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/h2non/gock.v1"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
global.Init(conf.Conf)
d = New(conf.Conf)
d.client.SetTransport(gock.DefaultTransport)
m.Run()
os.Exit(0)
}
// func httpMock(method, url string) *gock.Request {
// r := gock.New(url)
// r.Method = strings.ToUpper(method)
// return r
// }
func TestUpPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpGetHTTPClient(t *testing.T) {
convey.Convey("GetHTTPClient", t, func(ctx convey.C) {
p1 := d.GetHTTPClient()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,302 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package up is a generated mc cache package.
It is generated from:
type _mc interface {
//mc: -key=upCacheKey -expire=d.upExpire -encode=json
AddCacheUp(c context.Context, mid int64, up *model.Up) (err error)
//mc: -key=upCacheKey
CacheUp(c context.Context, mid int64) (up *model.Up, err error)
//mc: -key=upCacheKey
DelCacheUp(c context.Context, mid int64) (err error)
//mc: -key=upSwitchKey -expire=d.upExpire -encode=json
AddCacheUpSwitch(c context.Context, mid int64, up *model.UpSwitch) (err error)
//mc: -key=upSwitchKey
CacheUpSwitch(c context.Context, mid int64) (res *model.UpSwitch, err error)
//mc: -key=upSwitchKey
DelCacheUpSwitch(c context.Context, mid int64) (err error)
//mc: -key=upInfoActiveKey -expire=d.upExpire -encode=json
AddCacheUpInfoActive(c context.Context, mid int64, up *model.UpInfoActiveReply) (err error)
//mc: -key=upInfoActiveKey
CacheUpInfoActive(c context.Context, mid int64) (res *model.UpInfoActiveReply, err error)
//mc: -key=upInfoActiveKey
DelCacheUpInfoActive(c context.Context, mid int64) (err error)
// mc: -key=upInfoActiveKey -expire=d.upExpire -encode=json
AddCacheUpsInfoActive(c context.Context, res map[int64]*model.UpInfoActiveReply) (err error)
// mc: -key=upInfoActiveKey
CacheUpsInfoActive(c context.Context, mids []int64) (res map[int64]*model.UpInfoActiveReply, err error)
// mc: -key=upInfoActiveKey
DelCacheUpsInfoActive(c context.Context, mids []int64) (err error)
}
*/
package up
import (
"context"
"fmt"
"go-common/app/service/main/up/model"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// AddCacheUp Set data to mc
func (d *Dao) AddCacheUp(c context.Context, id int64, val *model.Up) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := upCacheKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUp")
log.Errorv(c, log.KV("AddCacheUp", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUp get data from mc
func (d *Dao) CacheUp(c context.Context, id int64) (res *model.Up, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upCacheKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUp")
log.Errorv(c, log.KV("CacheUp", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &model.Up{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUp")
log.Errorv(c, log.KV("CacheUp", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUp delete data from mc
func (d *Dao) DelCacheUp(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upCacheKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUp")
log.Errorv(c, log.KV("DelCacheUp", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUpSwitch Set data to mc
func (d *Dao) AddCacheUpSwitch(c context.Context, id int64, val *model.UpSwitch) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := upSwitchKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpSwitch")
log.Errorv(c, log.KV("AddCacheUpSwitch", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUpSwitch get data from mc
func (d *Dao) CacheUpSwitch(c context.Context, id int64) (res *model.UpSwitch, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSwitchKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUpSwitch")
log.Errorv(c, log.KV("CacheUpSwitch", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &model.UpSwitch{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpSwitch")
log.Errorv(c, log.KV("CacheUpSwitch", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUpSwitch delete data from mc
func (d *Dao) DelCacheUpSwitch(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSwitchKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUpSwitch")
log.Errorv(c, log.KV("DelCacheUpSwitch", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUpInfoActive Set data to mc
func (d *Dao) AddCacheUpInfoActive(c context.Context, id int64, val *model.UpInfoActiveReply) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := upInfoActiveKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpInfoActive")
log.Errorv(c, log.KV("AddCacheUpInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUpInfoActive get data from mc
func (d *Dao) CacheUpInfoActive(c context.Context, id int64) (res *model.UpInfoActiveReply, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upInfoActiveKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUpInfoActive")
log.Errorv(c, log.KV("CacheUpInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &model.UpInfoActiveReply{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpInfoActive")
log.Errorv(c, log.KV("CacheUpInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUpInfoActive delete data from mc
func (d *Dao) DelCacheUpInfoActive(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upInfoActiveKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUpInfoActive")
log.Errorv(c, log.KV("DelCacheUpInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUpsInfoActive Set data to mc
func (d *Dao) AddCacheUpsInfoActive(c context.Context, values map[int64]*model.UpInfoActiveReply) (err error) {
if len(values) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for id, val := range values {
key := upInfoActiveKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpsInfoActive")
log.Errorv(c, log.KV("AddCacheUpsInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}
// CacheUpsInfoActive get data from mc
func (d *Dao) CacheUpsInfoActive(c context.Context, ids []int64) (res map[int64]*model.UpInfoActiveReply, err error) {
l := len(ids)
if l == 0 {
return
}
keysMap := make(map[string]int64, l)
keys := make([]string, 0, l)
for _, id := range ids {
key := upInfoActiveKey(id)
keysMap[key] = id
keys = append(keys, key)
}
conn := d.mc.Get(c)
defer conn.Close()
replies, err := conn.GetMulti(keys)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsInfoActive")
log.Errorv(c, log.KV("CacheUpsInfoActive", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
return
}
for key, reply := range replies {
var v *model.UpInfoActiveReply
v = &model.UpInfoActiveReply{}
err = conn.Scan(reply, v)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsInfoActive")
log.Errorv(c, log.KV("CacheUpsInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
if res == nil {
res = make(map[int64]*model.UpInfoActiveReply, len(keys))
}
res[keysMap[key]] = v
}
return
}
// DelCacheUpsInfoActive delete data from mc
func (d *Dao) DelCacheUpsInfoActive(c context.Context, ids []int64) (err error) {
if len(ids) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for _, id := range ids {
key := upInfoActiveKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
continue
}
prom.BusinessErrCount.Incr("mc:DelCacheUpsInfoActive")
log.Errorv(c, log.KV("DelCacheUpsInfoActive", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}

View File

@@ -0,0 +1,132 @@
package up
import (
"context"
"go-common/app/service/main/up/model"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpAddCacheUp(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
val = &model.Up{}
)
convey.Convey("AddCacheUp", t, func(ctx convey.C) {
err := d.AddCacheUp(c, id, val)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpCacheUp(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("CacheUp", t, func(ctx convey.C) {
res, err := d.CacheUp(c, id)
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 TestUpDelCacheUp(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("DelCacheUp", t, func(ctx convey.C) {
err := d.DelCacheUp(c, id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpAddCacheUpSwitch(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
val = &model.UpSwitch{}
)
convey.Convey("AddCacheUpSwitch", t, func(ctx convey.C) {
err := d.AddCacheUpSwitch(c, id, val)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpCacheUpSwitch(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("CacheUpSwitch", t, func(ctx convey.C) {
res, err := d.CacheUpSwitch(c, id)
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 TestUpDelCacheUpSwitch(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("DelCacheUpSwitch", t, func(ctx convey.C) {
err := d.DelCacheUpSwitch(c, id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpAddCacheUpInfoActive(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
val = &model.UpInfoActiveReply{}
)
convey.Convey("AddCacheUpInfoActive", t, func(ctx convey.C) {
err := d.AddCacheUpInfoActive(c, id, val)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpCacheUpInfoActive(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("CacheUpInfoActive", t, func(ctx convey.C) {
res, err := d.CacheUpInfoActive(c, id)
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 TestUpDelCacheUpInfoActive(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("DelCacheUpInfoActive", t, func(ctx convey.C) {
err := d.DelCacheUpInfoActive(c, id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,54 @@
package up
import (
"context"
"strconv"
"go-common/app/service/main/up/model"
"go-common/library/cache/memcache"
"go-common/library/log"
)
const (
_prefix = "allID_"
)
func keyIdentityAll(mid int64) string {
return _prefix + strconv.FormatInt(mid, 10)
}
// IdentityAllCache get all up all of identify type cache.
func (d *Dao) IdentityAllCache(c context.Context, mid int64) (st *model.IdentifyAll, err error) {
var (
conn = d.mcPool.Get(c)
r *memcache.Item
)
defer conn.Close()
r, err = conn.Get(keyIdentityAll(mid))
if err != nil {
if err == memcache.ErrNotFound {
err = nil
} else {
log.Error("conn.Get2(%d) error(%v)", mid, err)
}
return
}
if err = conn.Scan(r, &st); err != nil {
log.Error("json.Unmarshal(%s) error(%v)", r.Value, err)
st = nil
}
return
}
// AddIdentityAllCache add all of up identity type cache.
func (d *Dao) AddIdentityAllCache(c context.Context, mid int64, st *model.IdentifyAll) (err error) {
var (
key = keyIdentityAll(mid)
)
conn := d.mcPool.Get(c)
defer conn.Close()
if err = conn.Set(&memcache.Item{Key: key, Object: st, Flags: memcache.FlagJSON, Expiration: d.upExpire}); err != nil {
log.Error("memcache.Set(%v) error(%v)", key, err)
}
return
}

View File

@@ -0,0 +1,54 @@
package up
import (
"context"
"go-common/app/service/main/up/model"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpkeyIdentityAll(t *testing.T) {
var (
mid = int64(0)
)
convey.Convey("keyIdentityAll", t, func(ctx convey.C) {
p1 := keyIdentityAll(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestUpIdentityAllCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
st = &model.IdentifyAll{}
)
convey.Convey("IdentityAllCache", t, func(ctx convey.C) {
err := d.AddIdentityAllCache(c, mid, st)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
st, err := d.IdentityAllCache(c, mid)
ctx.Convey("Then err should be nil.st should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(st, convey.ShouldNotBeNil)
})
})
}
func TestUpAddIdentityAllCache(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
st = &model.IdentifyAll{}
)
convey.Convey("AddIdentityAllCache", t, func(ctx convey.C) {
err := d.AddIdentityAllCache(c, mid, st)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,76 @@
package up
import (
"context"
"fmt"
"go-common/app/service/main/up/model"
)
const (
_upKey = "up_srv_%d"
_upSwitchKey = "up_sw_%d"
_upInfoActive = "up_info_active_%d"
)
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
//cache: -nullcache=&model.Up{ID:-1} -check_null_code=$!=nil&&$.ID==-1
Up(c context.Context, mid int64) (up *model.Up, err error)
//cache: -nullcache=&model.UpSwitch{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpSwitch(c context.Context, mid int64) (up *model.UpSwitch, err error)
//cache: -nullcache=&model.UpInfoActiveReply{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpInfoActive(c context.Context, mid int64) (up *model.UpInfoActiveReply, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&model.UpInfoActiveReply{ID:-1} -check_null_code=$!=nil&&$.ID==-1
UpsInfoActive(c context.Context, mids []int64) (res map[int64]*model.UpInfoActiveReply, err error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
//mc: -key=upCacheKey -expire=d.upExpire -encode=json
AddCacheUp(c context.Context, mid int64, up *model.Up) (err error)
//mc: -key=upCacheKey
CacheUp(c context.Context, mid int64) (up *model.Up, err error)
//mc: -key=upCacheKey
DelCacheUp(c context.Context, mid int64) (err error)
//mc: -key=upSwitchKey -expire=d.upExpire -encode=json
AddCacheUpSwitch(c context.Context, mid int64, up *model.UpSwitch) (err error)
//mc: -key=upSwitchKey
CacheUpSwitch(c context.Context, mid int64) (res *model.UpSwitch, err error)
//mc: -key=upSwitchKey
DelCacheUpSwitch(c context.Context, mid int64) (err error)
//mc: -key=upInfoActiveKey -expire=d.upExpire -encode=json
AddCacheUpInfoActive(c context.Context, mid int64, up *model.UpInfoActiveReply) (err error)
//mc: -key=upInfoActiveKey
CacheUpInfoActive(c context.Context, mid int64) (res *model.UpInfoActiveReply, err error)
//mc: -key=upInfoActiveKey
DelCacheUpInfoActive(c context.Context, mid int64) (err error)
// mc: -key=upInfoActiveKey -expire=d.upExpire -encode=json
AddCacheUpsInfoActive(c context.Context, res map[int64]*model.UpInfoActiveReply) (err error)
// mc: -key=upInfoActiveKey
CacheUpsInfoActive(c context.Context, mids []int64) (res map[int64]*model.UpInfoActiveReply, err error)
// mc: -key=upInfoActiveKey
DelCacheUpsInfoActive(c context.Context, mids []int64) (err error)
}
//upCacheKey 缓存key
func upCacheKey(mid int64) string {
return fmt.Sprintf(_upKey, mid)
}
//upSwitchCacheKey 缓存key
func upSwitchKey(mid int64) string {
return fmt.Sprintf(_upSwitchKey, mid)
}
//upInfoActiveCacheKey 缓存key
func upInfoActiveKey(mid int64) string {
return fmt.Sprintf(_upInfoActive, mid)
}
//DelCpUp 异步删除缓存
func (d *Dao) DelCpUp(c context.Context, mid int64) {
d.cache.Do(c, func(c context.Context) {
d.DelCacheUp(c, mid)
})
}

View File

@@ -0,0 +1,44 @@
package up
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpupCacheKey(t *testing.T) {
var (
mid = int64(0)
)
convey.Convey("upCacheKey", t, func(ctx convey.C) {
p1 := upCacheKey(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestUpupSwitchKey(t *testing.T) {
var (
mid = int64(0)
)
convey.Convey("upSwitchKey", t, func(ctx convey.C) {
p1 := upSwitchKey(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestUpDelCpUp(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
)
convey.Convey("DelCpUp", t, func(ctx convey.C) {
d.DelCpUp(c, mid)
ctx.Convey("No return values", func(ctx convey.C) {
})
})
}

View File

@@ -0,0 +1,37 @@
package up
import (
"context"
"go-common/app/service/main/up/dao/global"
"go-common/app/service/main/up/model"
"go-common/library/log"
"go-common/library/xstr"
"time"
)
const (
// _getHighAllyUpsSql .
_getHighAllyUpsSql = "SELECT id, mid, state, begin_date, end_date FROM sign_up WHERE mid IN (?) AND end_date >= ? AND state <> 100"
)
// GetHighAllyUps dao get high ally ups
func (d *Dao) GetHighAllyUps(c context.Context, mids []int64) (res []*model.SignUp, err error) {
midStr := xstr.JoinInts(mids)
now := time.Now().Format(DateLayout)
rows, err := global.GetUpCrmDB().Query(c, _getHighAllyUpsSql, midStr, now)
if err != nil {
log.Error("d.GetHighAllyUps error (%v)", err)
return
}
for rows.Next() {
r := &model.SignUp{}
err = rows.Scan(&r.ID, &r.Mid, &r.State, &r.BeginDate, &r.EndDate)
if err != nil {
log.Error("d.GetHighAllyUps scan error (%v)", err)
return
}
res = append(res, r)
}
return
}

View File

@@ -0,0 +1,24 @@
package up
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpGetHighAllyUps(t *testing.T) {
convey.Convey("GetHighAllyUps", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{0}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.GetHighAllyUps(c, mids)
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.ShouldBeEmpty)
})
})
})
}

View File

@@ -0,0 +1,66 @@
package up
import (
"context"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/app/service/main/up/dao/global"
"go-common/app/service/main/up/model"
"go-common/library/database/sql"
)
const (
// insert
_inUpInfoSQL = "INSERT INTO up (mid,attribute) VALUES (?,?) ON DUPLICATE KEY UPDATE attribute=?"
// select
_upInfoSQL = "SELECT id, mid, attribute FROM up WHERE mid = ?"
_upInfoActivitysSQL = "SELECT id, mid, activity FROM up_base_info WHERE id > ? AND business_type = 1 LIMIT ?"
)
// AddUp add up.
func (d *Dao) AddUp(c context.Context, u *model.Up) (id int64, err error) {
res, err := d.db.Exec(c, _inUpInfoSQL, u.MID, u.Attribute, u.Attribute)
if err != nil {
return
}
id, err = res.RowsAffected()
return
}
// RawUp get attribute.
func (d *Dao) RawUp(c context.Context, mid int64) (u *model.Up, err error) {
row := d.db.QueryRow(c, _upInfoSQL, mid)
u = &model.Up{}
if err = row.Scan(&u.ID, &u.MID, &u.Attribute); err != nil {
if err == sql.ErrNoRows {
u = nil
err = nil
return
}
}
return
}
// UpInfoActivitys list <id, UpActivity> k-v pairs
func (d *Dao) UpInfoActivitys(c context.Context, lastID int64, ps int) (mup map[int64]*upgrpc.UpActivity, err error) {
rows, err := global.GetUpCrmDB().Query(c, _upInfoActivitysSQL, lastID, ps)
if err != nil {
return
}
defer rows.Close()
mup = make(map[int64]*upgrpc.UpActivity, ps)
for rows.Next() {
var (
id int64
up = new(upgrpc.UpActivity)
)
if err = rows.Scan(&id, &up.Mid, &up.Activity); err != nil {
if err == sql.ErrNoRows {
err = nil
}
return
}
mup[id] = up
}
return
}

View File

@@ -0,0 +1,58 @@
package up
import (
"context"
"database/sql"
"errors"
"fmt"
"go-common/library/xstr"
"go-common/app/service/main/up/dao/global"
"go-common/app/service/main/up/model"
"go-common/library/log"
)
const (
// _getUpInfoActiveSQL .
_getUpInfoActiveSQL = "SELECT id, mid, active_tid FROM up_base_info WHERE mid = ?"
// _getUpsInfoActiveSQL .
_getUpsInfoActiveSQL = "SELECT id, mid, active_tid FROM up_base_info WHERE mid IN (%s)"
)
// RawUpInfoActive get up info active
func (d *Dao) RawUpInfoActive(ctx context.Context, mid int64) (upInfoActive *model.UpInfoActiveReply, err error) {
row := global.GetUpCrmDB().QueryRow(ctx, _getUpInfoActiveSQL, mid)
upInfoActive = &model.UpInfoActiveReply{}
if err = row.Scan(&upInfoActive.ID, &upInfoActive.MID, &upInfoActive.ActiveTid); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("RawUpInfoActive row.Scan error(%v)", err)
err = errors.New("RawUpInfoActive get data failed")
}
}
return
}
// RawUpsInfoActive get ups info active
func (d *Dao) RawUpsInfoActive(ctx context.Context, mids []int64) (res map[int64]*model.UpInfoActiveReply, err error) {
res = make(map[int64]*model.UpInfoActiveReply)
sql := fmt.Sprintf(_getUpsInfoActiveSQL, xstr.JoinInts(mids))
log.Info("SQL: %s", sql)
rows, err := global.GetUpCrmDB().Query(ctx, sql)
if err != nil {
log.Error("RawUpsInfoActive UpCrmDB.Query error(%v)", err)
return
}
for rows.Next() {
upInfoActive := model.UpInfoActiveReply{}
if err = rows.Scan(&upInfoActive.ID, &upInfoActive.MID, &upInfoActive.ActiveTid); err != nil {
log.Error("RawUpsInfoActive rows.Scan error(%v)", err)
return
}
res[upInfoActive.MID] = &upInfoActive
}
return
}

View File

@@ -0,0 +1,40 @@
package up
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpRawUpInfoActive(t *testing.T) {
convey.Convey("RawUpInfoActive", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
upInfoActive, err := d.RawUpInfoActive(c, mid)
ctx.Convey("Then err should be nil.upInfoActive should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(upInfoActive, convey.ShouldNotBeNil)
})
})
})
}
func TestUpRawUpsInfoActive(t *testing.T) {
convey.Convey("RawUpsInfoActive", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{0}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RawUpsInfoActive(c, mids)
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,38 @@
package up
import (
"context"
"database/sql"
"go-common/app/service/main/up/model"
)
const (
// insert
_inUPSwitchSQL = "INSERT INTO up_switch (mid, attribute) VALUES (?,?) ON DUPLICATE KEY UPDATE attribute=?"
// select
_getUPSwitchSQL = "SELECT id, mid, attribute FROM up_switch WHERE mid=?"
)
// SetSwitch add or update up switch.
func (d *Dao) SetSwitch(c context.Context, u *model.UpSwitch) (id int64, err error) {
res, err := d.db.Exec(c, _inUPSwitchSQL, u.MID, u.Attribute, u.Attribute)
if err != nil {
return
}
return res.RowsAffected()
}
// RawUpSwitch get up switch attribute.
func (d *Dao) RawUpSwitch(c context.Context, mid int64) (u *model.UpSwitch, err error) {
row := d.db.QueryRow(c, _getUPSwitchSQL, mid)
u = &model.UpSwitch{}
if err = row.Scan(&u.ID, &u.MID, &u.Attribute); err != nil {
if err == sql.ErrNoRows {
u = nil
err = nil
return
}
}
return
}

View File

@@ -0,0 +1,41 @@
package up
import (
"context"
"go-common/app/service/main/up/model"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestUpSetSwitch(t *testing.T) {
var (
c = context.Background()
u = &model.UpSwitch{
MID: int64(1),
Attribute: 0,
}
)
convey.Convey("SetSwitch", t, func(ctx convey.C) {
id, err := d.SetSwitch(c, u)
println(111, id)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(id, convey.ShouldNotBeNil)
})
})
}
func TestUpRawUpSwitch(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
)
convey.Convey("RawUpSwitch", t, func(ctx convey.C) {
_, err := d.RawUpSwitch(c, mid)
ctx.Convey("Then err should be nil.u should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
//ctx.So(u, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,56 @@
package up
import (
"context"
"testing"
"go-common/app/service/main/up/model"
"github.com/smartystreets/goconvey/convey"
)
func TestUpAddUp(t *testing.T) {
var (
c = context.Background()
u = &model.Up{
MID: int64(2089809),
Attribute: 0,
}
)
convey.Convey("AddUp", t, func(ctx convey.C) {
id, err := d.AddUp(c, u)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(id, convey.ShouldNotBeNil)
})
})
}
func TestUpRawUp(t *testing.T) {
var (
c = context.Background()
mid = int64(0)
)
convey.Convey("RawUp", t, func(ctx convey.C) {
u, err := d.RawUp(c, mid)
ctx.Convey("Then err should be nil.u should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(u, convey.ShouldNotBeNil)
})
})
}
func TestUpInfoActivitys(t *testing.T) {
var (
c = context.Background()
lastID = int64(0)
ps = 100
)
convey.Convey("UpInfoActivitys", t, func(ctx convey.C) {
u, err := d.UpInfoActivitys(c, lastID, ps)
ctx.Convey("Then err should be nil.u should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(u, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,93 @@
package dao
import "fmt"
const (
//logicNoOp = 0
logicOpAnd = 1
logicOpOr = 2
)
const (
//AppID appid
AppID = "main.archive.up-service"
//UatToken uat token
UatToken = "5f1660060bb011e8865c66d44b23cda7"
//TreeID uat treeid
TreeID = "15572"
)
// Condition 生成的condition为
// [before] [key] [operator] ? [after]
// 如
// [(] [id] [=] ? [and]
// [ctime] [>] ? [)]
// [order by] [time] nil [] //如果value是nil不会设置placeholder ?
type Condition struct {
logicOp int
Before string
Key string
Operator string
Value interface{}
After string
}
//ConcatCondition concat conditions
func ConcatCondition(conditions ...Condition) (conditionStr string, args []interface{}, hasOperator bool) {
hasOperator = false
for _, c := range conditions {
var questionMark = "?"
if c.Value == nil {
questionMark = ""
}
if c.Operator != "" {
hasOperator = true
}
var logicOp = ""
switch c.logicOp {
case logicOpAnd:
logicOp = " and "
case logicOpOr:
logicOp = " or "
}
conditionStr += fmt.Sprintf(" %s %s %s %s %s %s", logicOp, c.Before, c.Key, c.Operator, questionMark, c.After)
if c.Value != nil {
args = append(args, c.Value)
}
}
return
}
//AndCondition and condition
func AndCondition(conditions ...Condition) (result []Condition) {
return addLogicOperator(logicOpAnd, conditions...)
}
//OrCondition or condition
func OrCondition(conditions ...Condition) (result []Condition) {
return addLogicOperator(logicOpOr, conditions...)
}
func addLogicOperator(operator int, conditions ...Condition) (result []Condition) {
var isFirst = true
for _, v := range conditions {
if isFirst {
isFirst = false
} else {
v.logicOp = operator
}
result = append(result, v)
}
return
}
// Split split num by size; size should be positive
func Split(start int, end int, size int, f func(start int, end int)) {
for s := start; s < end; s += size {
e := s + size
if e > end {
e = end
}
f(s, e)
}
}

View File

@@ -0,0 +1,69 @@
package dao
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoConcatCondition(t *testing.T) {
var (
conditions Condition
)
convey.Convey("ConcatCondition", t, func(ctx convey.C) {
conditionStr, args, hasOperator := ConcatCondition(conditions)
ctx.Convey("Then conditionStr,args,hasOperator should not be nil.", func(ctx convey.C) {
ctx.So(hasOperator, convey.ShouldNotBeNil)
ctx.So(args, convey.ShouldBeNil)
ctx.So(conditionStr, convey.ShouldNotBeNil)
})
})
}
func TestDaoAndCondition(t *testing.T) {
var (
conditions Condition
)
convey.Convey("AndCondition", t, func(ctx convey.C) {
result := AndCondition(conditions)
ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
ctx.So(result, convey.ShouldNotBeNil)
})
})
}
func TestDaoOrCondition(t *testing.T) {
var (
conditions Condition
)
convey.Convey("OrCondition", t, func(ctx convey.C) {
result := OrCondition(conditions)
ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
ctx.So(result, convey.ShouldNotBeNil)
})
})
}
func TestDaoaddLogicOperator(t *testing.T) {
var (
operator = int(0)
conditions Condition
)
convey.Convey("addLogicOperator", t, func(ctx convey.C) {
result := addLogicOperator(operator, conditions)
ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
ctx.So(result, convey.ShouldNotBeNil)
})
})
}
func TestSplit(t *testing.T) {
var (
start = 0
end = 100
size = 10
f = func(start int, end int) {}
)
convey.Convey("split", t, func(ctx convey.C) {
Split(start, end, size, f)
})
}

Some files were not shown because too many files have changed in this diff Show More