Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/fans_medal/api/liverpc:all-srcs",
"//app/service/live/fans_medal/cmd:all-srcs",
"//app/service/live/fans_medal/conf:all-srcs",
"//app/service/live/fans_medal/dao:all-srcs",
"//app/service/live/fans_medal/model:all-srcs",
"//app/service/live/fans_medal/server/http:all-srcs",
"//app/service/live/fans_medal/service:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,2 @@
# v1.0.0
1. 增加测试用例注释

View File

@@ -0,0 +1,8 @@
# Owner
liutengda
# Author
liutengda
# Reviewer
liutengda

View File

@@ -0,0 +1,12 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- liutengda
labels:
- live
- service
- service/live/fans_medal
options:
no_parent_owners: true
reviewers:
- liutengda

View File

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

View File

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

View File

@@ -0,0 +1,37 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
importpath = "go-common/app/service/live/fans_medal/api/liverpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/fans_medal/api/liverpc/v1:go_default_library",
"//app/service/live/fans_medal/api/liverpc/v2:go_default_library",
"//library/net/rpc/liverpc:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/fans_medal/api/liverpc/v1:all-srcs",
"//app/service/live/fans_medal/api/liverpc/v2:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,52 @@
// Code generated by liverpcgen, DO NOT EDIT.
// source: *.proto files under this directory
// If you want to change this file, Please see README in go-common/app/tool/liverpc/protoc-gen-liverpc/
package liverpc
import (
"go-common/app/service/live/fans_medal/api/liverpc/v1"
"go-common/app/service/live/fans_medal/api/liverpc/v2"
"go-common/library/net/rpc/liverpc"
)
// Client that represents a liverpc fans_medal service api
type Client struct {
cli *liverpc.Client
// V1FansMedal presents the controller in liverpc
V1FansMedal v1.FansMedal
// V1Medal presents the controller in liverpc
V1Medal v1.Medal
// V2Anchor presents the controller in liverpc
V2Anchor v2.Anchor
// V2HighQps presents the controller in liverpc
V2HighQps v2.HighQps
}
// DiscoveryAppId the discovery id is not the tree name
var DiscoveryAppId = "live.fansmedal"
// New a Client that represents a liverpc live.fansmedal service api
// conf can be empty, and it will use discovery to find service by default
// conf.AppID will be overwrite by a fixed value DiscoveryAppId
// therefore is no need to set
func New(conf *liverpc.ClientConfig) *Client {
if conf == nil {
conf = &liverpc.ClientConfig{}
}
conf.AppID = DiscoveryAppId
var realCli = liverpc.NewClient(conf)
cli := &Client{cli: realCli}
cli.clientInit(realCli)
return cli
}
func (cli *Client) GetRawCli() *liverpc.Client {
return cli.cli
}
func (cli *Client) clientInit(realCli *liverpc.Client) {
cli.V1FansMedal = v1.NewFansMedalRpcClient(realCli)
cli.V1Medal = v1.NewMedalRpcClient(realCli)
cli.V2Anchor = v2.NewAnchorRpcClient(realCli)
cli.V2HighQps = v2.NewHighQpsRpcClient(realCli)
}

View File

@@ -0,0 +1,62 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "v1_proto",
srcs = [
"FansMedal.proto",
"Medal.proto",
],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v1_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/live/fans_medal/api/liverpc/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"FansMedal.liverpc.go",
"Medal.liverpc.go",
],
embed = [":v1_go_proto"],
importpath = "go-common/app/service/live/fans_medal/api/liverpc/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/rpc/liverpc:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//proto: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,77 @@
// Code generated by protoc-gen-liverpc v0.1, DO NOT EDIT.
// source: v1/FansMedal.proto
/*
Package v1 is a generated liverpc stub package.
This code was generated with go-common/app/tool/liverpc/protoc-gen-liverpc v0.1.
It is generated from these files:
v1/FansMedal.proto
v1/Medal.proto
*/
package v1
import context "context"
import proto "github.com/golang/protobuf/proto"
import "go-common/library/net/rpc/liverpc"
var _ proto.Message // generate to suppress unused imports
// Imports only used by utility functions:
// ===================
// FansMedal Interface
// ===================
type FansMedal interface {
// * 获取已佩戴的勋章
//
GetWearedMedal(context.Context, *FansMedalGetWearedMedalReq) (*FansMedalGetWearedMedalResp, error)
// * 用户卡
// 基于某房间|主播的 用户卡片信息
TargetsWithMedal(context.Context, *FansMedalTargetsWithMedalReq) (*FansMedalTargetsWithMedalResp, error)
}
// =========================
// FansMedal Live Rpc Client
// =========================
type fansMedalRpcClient struct {
client *liverpc.Client
}
// NewFansMedalRpcClient creates a Rpc client that implements the FansMedal interface.
// It communicates using Rpc and can be configured with a custom HTTPClient.
func NewFansMedalRpcClient(client *liverpc.Client) FansMedal {
return &fansMedalRpcClient{
client: client,
}
}
func (c *fansMedalRpcClient) GetWearedMedal(ctx context.Context, in *FansMedalGetWearedMedalReq) (*FansMedalGetWearedMedalResp, error) {
out := new(FansMedalGetWearedMedalResp)
err := doRpcRequest(ctx, c.client, 1, "FansMedal.get_weared_medal", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *fansMedalRpcClient) TargetsWithMedal(ctx context.Context, in *FansMedalTargetsWithMedalReq) (*FansMedalTargetsWithMedalResp, error) {
out := new(FansMedalTargetsWithMedalResp)
err := doRpcRequest(ctx, c.client, 1, "FansMedal.targetsWithMedal", in, out)
if err != nil {
return nil, err
}
return out, nil
}
// =====
// Utils
// =====
func doRpcRequest(ctx context.Context, client *liverpc.Client, version int, method string, in, out proto.Message) (err error) {
err = client.Call(ctx, version, method, in, out)
return
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,124 @@
syntax = "proto3";
package fans_medal.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
service FansMedal {
/** 获取已佩戴的勋章
*
*/
rpc get_weared_medal (FansMedalGetWearedMedalReq) returns (FansMedalGetWearedMedalResp);
/** 用户卡
* 基于某房间|主播的 用户卡片信息
*/
rpc targetsWithMedal (FansMedalTargetsWithMedalReq) returns (FansMedalTargetsWithMedalResp);
}
message FansMedalGetWearedMedalReq {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
//
int64 source = 2 [(gogoproto.jsontag) = "source"];
//
bool need_rank = 3 [(gogoproto.jsontag) = "need_rank"];
//
bool need_today_intimacy = 4 [(gogoproto.jsontag) = "need_today_intimacy"];
//
bool ignore_userinfo = 5 [(gogoproto.jsontag) = "ignore_userinfo"];
}
message FansMedalGetWearedMedalResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message List {
// 用户uid
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
// up主uid
int64 target_id = 2 [(gogoproto.jsontag) = "target_id"];
// 勋章id
int64 medal_id = 3 [(gogoproto.jsontag) = "medal_id"];
// 勋章总经验值
int64 score = 4 [(gogoproto.jsontag) = "score"];
// 勋章等级
int64 level = 5 [(gogoproto.jsontag) = "level"];
// 当前等级亲密度
int64 intimacy = 6 [(gogoproto.jsontag) = "intimacy"];
// 当前等级升级所需
int64 next_intimacy = 7 [(gogoproto.jsontag) = "next_intimacy"];
// 佩戴状态 0:未佩戴 1:佩戴中
int64 status = 8 [(gogoproto.jsontag) = "status"];
// 来源 1直播 2:投币 3:充电
int64 source = 9 [(gogoproto.jsontag) = "source"];
// 领取渠道 1直播 2:主站
int64 receive_channel = 10 [(gogoproto.jsontag) = "receive_channel"];
// 是否已经领取
int64 is_receive = 11 [(gogoproto.jsontag) = "is_receive"];
// 主站佩戴状态 0:未佩戴 1:佩戴中
int64 master_status = 12 [(gogoproto.jsontag) = "master_status"];
// 领取时间
string receive_time = 13 [(gogoproto.jsontag) = "receive_time"];
// 今日亲密度上限
int64 today_intimacy = 14 [(gogoproto.jsontag) = "today_intimacy"];
// 最后佩戴的时间戳
int64 last_wear_time = 15 [(gogoproto.jsontag) = "last_wear_time"];
// 勋章名称
string medal_name = 16 [(gogoproto.jsontag) = "medal_name"];
// 用户uid
int64 master_available = 17 [(gogoproto.jsontag) = "master_available"];
// up主昵称
string target_name = 18 [(gogoproto.jsontag) = "target_name"];
// up主头像
string target_face = 19 [(gogoproto.jsontag) = "target_face"];
// 排名
string rank = 20 [(gogoproto.jsontag) = "rank"];
// 勋章颜色 不同等级颜色不同
int64 medal_color = 21 [(gogoproto.jsontag) = "medal_color"];
// 今天增加亲密度
int64 today_feed = 22 [(gogoproto.jsontag) = "today_feed"];
// 大航海类型 1 总督 2 提督 3 舰长
int64 guard_type = 23 [(gogoproto.jsontag) = "guard_type"];
// 今日亲密度上限
int64 day_limit = 24 [(gogoproto.jsontag) = "day_limit"];
}
message Data {
//
int64 max = 1 [(gogoproto.jsontag) = "max"];
//
int64 cnt = 2 [(gogoproto.jsontag) = "cnt"];
//
repeated List list = 3 [(gogoproto.jsontag) = "list"];
}
}
message FansMedalTargetsWithMedalReq {
// 用户id
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
// 主播id
repeated int64 target_ids = 2 [(gogoproto.jsontag) = "target_ids"];
}
message FansMedalTargetsWithMedalResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
string message = 3 [(gogoproto.jsontag) = "message"];
//
repeated int64 data = 4 [(gogoproto.jsontag) = "data"];
}

View File

@@ -0,0 +1,72 @@
// Code generated by protoc-gen-liverpc v0.1, DO NOT EDIT.
// source: v1/Medal.proto
package v1
import context "context"
import proto "github.com/golang/protobuf/proto"
import "go-common/library/net/rpc/liverpc"
var _ proto.Message // generate to suppress unused imports
// ===============
// Medal Interface
// ===============
type Medal interface {
// * up主开启勋章
//
Create(context.Context, *MedalCreateReq) (*MedalCreateResp, error)
// * 获取up主自己的勋章更严格的类型
//
Query(context.Context, *MedalQueryReq) (*MedalQueryResp, error)
// * 根据ID查询勋章详情返回严格的类型
//
QueryId(context.Context, *MedalQueryIdReq) (*MedalQueryIdResp, error)
}
// =====================
// Medal Live Rpc Client
// =====================
type medalRpcClient struct {
client *liverpc.Client
}
// NewMedalRpcClient creates a Rpc client that implements the Medal interface.
// It communicates using Rpc and can be configured with a custom HTTPClient.
func NewMedalRpcClient(client *liverpc.Client) Medal {
return &medalRpcClient{
client: client,
}
}
func (c *medalRpcClient) Create(ctx context.Context, in *MedalCreateReq) (*MedalCreateResp, error) {
out := new(MedalCreateResp)
err := doRpcRequest(ctx, c.client, 1, "Medal.create", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *medalRpcClient) Query(ctx context.Context, in *MedalQueryReq) (*MedalQueryResp, error) {
out := new(MedalQueryResp)
err := doRpcRequest(ctx, c.client, 1, "Medal.query", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *medalRpcClient) QueryId(ctx context.Context, in *MedalQueryIdReq) (*MedalQueryIdResp, error) {
out := new(MedalQueryIdResp)
err := doRpcRequest(ctx, c.client, 1, "Medal.query_id", in, out)
if err != nil {
return nil, err
}
return out, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,156 @@
syntax = "proto3";
package fans_medal.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
service Medal {
/** up主开启勋章
*
*/
rpc create (MedalCreateReq) returns (MedalCreateResp);
/** 获取up主自己的勋章更严格的类型
*
*/
rpc query (MedalQueryReq) returns (MedalQueryResp);
/** 根据ID查询勋章详情返回严格的类型
*
*/
rpc query_id (MedalQueryIdReq) returns (MedalQueryIdResp);
}
message MedalCreateReq {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
//
int64 source = 2 [(gogoproto.jsontag) = "source"];
}
message MedalCreateResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 勋章ID
int64 id = 1 [(gogoproto.jsontag) = "id"];
// up主uid
int64 uid = 2 [(gogoproto.jsontag) = "uid"];
// 勋章名称
string medal_name = 3 [(gogoproto.jsontag) = "medal_name"];
// 直播开通状态 0 冻结 1 可用
int64 live_status = 4 [(gogoproto.jsontag) = "live_status"];
// 主站开通状态 0 冻结 1 可用
int64 master_status = 5 [(gogoproto.jsontag) = "master_status"];
// 勋章审核状态 -1已拒绝 0未申请 1已申请 2已开通
int64 status = 6 [(gogoproto.jsontag) = "status"];
// 审核不通过通过的理由
string reason = 7 [(gogoproto.jsontag) = "reason"];
// 申请来源
int64 apply_source = 8 [(gogoproto.jsontag) = "apply_source"];
// 最后一次修改勋章名称的时间戳
int64 last_rename_time = 9 [(gogoproto.jsontag) = "last_rename_time"];
// 改名状态
int64 rename_status = 10 [(gogoproto.jsontag) = "rename_status"];
// 充电超过该数值可获得勋章
int64 charge_num = 11 [(gogoproto.jsontag) = "charge_num"];
// 投币超过该数值可获得勋章
int64 coin_num = 12 [(gogoproto.jsontag) = "coin_num"];
// 没有勋章时为 true
bool is_null = 13 [(gogoproto.jsontag) = "is_null"];
}
}
message MedalQueryReq {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
//
int64 source = 2 [(gogoproto.jsontag) = "source"];
}
message MedalQueryResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 勋章ID
int64 id = 1 [(gogoproto.jsontag) = "id"];
// up主uid
int64 uid = 2 [(gogoproto.jsontag) = "uid"];
// 勋章名称
string medal_name = 3 [(gogoproto.jsontag) = "medal_name"];
// 直播开通状态 0 冻结 1 可用
int64 live_status = 4 [(gogoproto.jsontag) = "live_status"];
// 主站开通状态 0 冻结 1 可用
int64 master_status = 5 [(gogoproto.jsontag) = "master_status"];
// 勋章审核状态 -1已拒绝 0未申请 1已申请 2已开通
int64 status = 6 [(gogoproto.jsontag) = "status"];
// 审核不通过通过的理由
string reason = 7 [(gogoproto.jsontag) = "reason"];
// 申请来源
int64 apply_source = 8 [(gogoproto.jsontag) = "apply_source"];
// 最后一次修改勋章名称的时间戳
int64 last_rename_time = 9 [(gogoproto.jsontag) = "last_rename_time"];
// 改名状态
int64 rename_status = 10 [(gogoproto.jsontag) = "rename_status"];
// 充电超过该数值可获得勋章
int64 charge_num = 11 [(gogoproto.jsontag) = "charge_num"];
// 投币超过该数值可获得勋章
int64 coin_num = 12 [(gogoproto.jsontag) = "coin_num"];
// 没有勋章时为 true
bool is_null = 13 [(gogoproto.jsontag) = "is_null"];
}
}
message MedalQueryIdReq {
//
int64 medal_id = 1 [(gogoproto.jsontag) = "medal_id"];
}
message MedalQueryIdResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
//
int64 id = 1 [(gogoproto.jsontag) = "id"];
//
int64 uid = 2 [(gogoproto.jsontag) = "uid"];
//
string medal_name = 3 [(gogoproto.jsontag) = "medal_name"];
//
int64 live_status = 4 [(gogoproto.jsontag) = "live_status"];
//
int64 master_status = 5 [(gogoproto.jsontag) = "master_status"];
//
int64 status = 6 [(gogoproto.jsontag) = "status"];
//
int64 reason = 7 [(gogoproto.jsontag) = "reason"];
//
int64 last_rename_time = 8 [(gogoproto.jsontag) = "last_rename_time"];
//
bool is_null = 9 [(gogoproto.jsontag) = "is_null"];
}
}

View File

@@ -0,0 +1,64 @@
// Code generated by protoc-gen-liverpc v0.1, DO NOT EDIT.
// source: v2/Anchor.proto
/*
Package v2 is a generated liverpc stub package.
This code was generated with go-common/app/tool/liverpc/protoc-gen-liverpc v0.1.
It is generated from these files:
v2/Anchor.proto
v2/HighQps.proto
*/
package v2
import context "context"
import proto "github.com/golang/protobuf/proto"
import "go-common/library/net/rpc/liverpc"
var _ proto.Message // generate to suppress unused imports
// Imports only used by utility functions:
// ================
// Anchor Interface
// ================
type Anchor interface {
// * 查看房管的勋章信息
//
QueryLiveWearing(context.Context, *AnchorQueryLiveWearingReq) (*AnchorQueryLiveWearingResp, error)
}
// ======================
// Anchor Live Rpc Client
// ======================
type anchorRpcClient struct {
client *liverpc.Client
}
// NewAnchorRpcClient creates a Rpc client that implements the Anchor interface.
// It communicates using Rpc and can be configured with a custom HTTPClient.
func NewAnchorRpcClient(client *liverpc.Client) Anchor {
return &anchorRpcClient{
client: client,
}
}
func (c *anchorRpcClient) QueryLiveWearing(ctx context.Context, in *AnchorQueryLiveWearingReq) (*AnchorQueryLiveWearingResp, error) {
out := new(AnchorQueryLiveWearingResp)
err := doRpcRequest(ctx, c.client, 2, "Anchor.query_live_wearing", in, out)
if err != nil {
return nil, err
}
return out, nil
}
// =====
// Utils
// =====
func doRpcRequest(ctx context.Context, client *liverpc.Client, version int, method string, in, out proto.Message) (err error) {
err = client.Call(ctx, version, method, in, out)
return
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
syntax = "proto3";
package fans_medal.v2;
option go_package = "v2";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
service Anchor {
/** 查看房管的勋章信息
*
*/
rpc query_live_wearing (AnchorQueryLiveWearingReq) returns (AnchorQueryLiveWearingResp);
}
message AnchorQueryLiveWearingReq {
// 房管 uid
repeated int64 uid_list = 1 [(gogoproto.jsontag) = "uid_list"];
}
message AnchorQueryLiveWearingResp {
// code
int64 code = 1 [(gogoproto.jsontag) = "code"];
// msg
string msg = 2 [(gogoproto.jsontag) = "msg"];
// 勋章信息 map
map<int64, Medal> data = 3 [(gogoproto.jsontag) = "data"];
message Medal {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
//
int64 target_id = 2 [(gogoproto.jsontag) = "target_id"];
//
int64 medal_id = 3 [(gogoproto.jsontag) = "medal_id"];
//
string medal_name = 4 [(gogoproto.jsontag) = "medal_name"];
//
int64 level = 5 [(gogoproto.jsontag) = "level"];
}
}

View File

@@ -0,0 +1,62 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "v2_proto",
srcs = [
"Anchor.proto",
"HighQps.proto",
],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v2_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/live/fans_medal/api/liverpc/v2",
proto = ":v2_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"Anchor.liverpc.go",
"HighQps.liverpc.go",
],
embed = [":v2_go_proto"],
importpath = "go-common/app/service/live/fans_medal/api/liverpc/v2",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/rpc/liverpc:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//proto: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,85 @@
// Code generated by protoc-gen-liverpc v0.1, DO NOT EDIT.
// source: v2/HighQps.proto
package v2
import context "context"
import proto "github.com/golang/protobuf/proto"
import "go-common/library/net/rpc/liverpc"
var _ proto.Message // generate to suppress unused imports
// =================
// HighQps Interface
// =================
type HighQps interface {
// * 某个up主动态,评论中的勋章信息,提供给主站调用
//
ReplyMedals(context.Context, *HighQpsReplyMedalsReq) (*HighQpsReplyMedalsResp, error)
// * 获取直播站佩戴中的勋章
//
LiveWeared(context.Context, *HighQpsLiveWearedReq) (*HighQpsLiveWearedResp, error)
// * 获取用户在直播站领取过的勋章
//
LiveReceived(context.Context, *HighQpsLiveReceivedReq) (*HighQpsLiveReceivedResp, error)
// * 获取某个up主的勋章状态
//
UpMedal(context.Context, *HighQpsUpMedalReq) (*HighQpsUpMedalResp, error)
}
// =======================
// HighQps Live Rpc Client
// =======================
type highQpsRpcClient struct {
client *liverpc.Client
}
// NewHighQpsRpcClient creates a Rpc client that implements the HighQps interface.
// It communicates using Rpc and can be configured with a custom HTTPClient.
func NewHighQpsRpcClient(client *liverpc.Client) HighQps {
return &highQpsRpcClient{
client: client,
}
}
func (c *highQpsRpcClient) ReplyMedals(ctx context.Context, in *HighQpsReplyMedalsReq) (*HighQpsReplyMedalsResp, error) {
out := new(HighQpsReplyMedalsResp)
err := doRpcRequest(ctx, c.client, 2, "HighQps.reply_medals", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *highQpsRpcClient) LiveWeared(ctx context.Context, in *HighQpsLiveWearedReq) (*HighQpsLiveWearedResp, error) {
out := new(HighQpsLiveWearedResp)
err := doRpcRequest(ctx, c.client, 2, "HighQps.live_weared", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *highQpsRpcClient) LiveReceived(ctx context.Context, in *HighQpsLiveReceivedReq) (*HighQpsLiveReceivedResp, error) {
out := new(HighQpsLiveReceivedResp)
err := doRpcRequest(ctx, c.client, 2, "HighQps.live_received", in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *highQpsRpcClient) UpMedal(ctx context.Context, in *HighQpsUpMedalReq) (*HighQpsUpMedalResp, error) {
out := new(HighQpsUpMedalResp)
err := doRpcRequest(ctx, c.client, 2, "HighQps.up_medal", in, out)
if err != nil {
return nil, err
}
return out, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,153 @@
syntax = "proto3";
package fans_medal.v2;
option go_package = "v2";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
service HighQps {
/** 某个up主动态,评论中的勋章信息,提供给主站调用
*
*/
rpc reply_medals (HighQpsReplyMedalsReq) returns (HighQpsReplyMedalsResp);
/** 获取直播站佩戴中的勋章
*
*/
rpc live_weared (HighQpsLiveWearedReq) returns (HighQpsLiveWearedResp);
/** 获取用户在直播站领取过的勋章
*
*/
rpc live_received (HighQpsLiveReceivedReq) returns (HighQpsLiveReceivedResp);
/** 获取某个up主的勋章状态
*
*/
rpc up_medal (HighQpsUpMedalReq) returns (HighQpsUpMedalResp);
}
message HighQpsReplyMedalsReq {
//
int64 up_uid = 1 [(gogoproto.jsontag) = "up_uid"];
//
repeated UidList uid_list = 2 [(gogoproto.jsontag) = "uid_list"];
message UidList {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
}
}
message HighQpsReplyMedalsResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
repeated Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 用户uid
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
// 粉丝勋章ID
int64 medal_id = 2 [(gogoproto.jsontag) = "medal_id"];
// 粉丝名称ID
string medal_name = 3 [(gogoproto.jsontag) = "medal_name"];
// 粉丝勋章等级
int64 level = 4 [(gogoproto.jsontag) = "level"];
}
}
message HighQpsLiveWearedReq {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
}
message HighQpsLiveWearedResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 用户uid
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
// up主uid
int64 target_id = 2 [(gogoproto.jsontag) = "target_id"];
// 粉丝勋章id
int64 medal_id = 3 [(gogoproto.jsontag) = "medal_id"];
// 粉丝勋章等级
int64 level = 4 [(gogoproto.jsontag) = "level"];
// 粉丝勋章名称
string medal_name = 5 [(gogoproto.jsontag) = "medal_name"];
// 粉丝勋章颜色,根据等级变色
int64 medal_color = 6 [(gogoproto.jsontag) = "medal_color"];
}
}
message HighQpsLiveReceivedReq {
//
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
}
message HighQpsLiveReceivedResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
repeated Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 用户uid
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
// up主uid
int64 target_id = 2 [(gogoproto.jsontag) = "target_id"];
// 粉丝勋章id
int64 medal_id = 3 [(gogoproto.jsontag) = "medal_id"];
// 粉丝勋章等级
int64 level = 4 [(gogoproto.jsontag) = "level"];
// 粉丝勋章名称
string medal_name = 5 [(gogoproto.jsontag) = "medal_name"];
}
}
message HighQpsUpMedalReq {
// up主uid
int64 uid = 1 [(gogoproto.jsontag) = "uid"];
}
message HighQpsUpMedalResp {
//
int64 code = 1 [(gogoproto.jsontag) = "code"];
//
string msg = 2 [(gogoproto.jsontag) = "msg"];
//
Data data = 3 [(gogoproto.jsontag) = "data"];
message Data {
// 粉丝勋章id
int64 id = 1 [(gogoproto.jsontag) = "id"];
// up主uid
int64 uid = 2 [(gogoproto.jsontag) = "uid"];
// 直播站状态
int64 live_status = 3 [(gogoproto.jsontag) = "live_status"];
// 主站佩戴状态 0:未佩戴 1:佩戴中
int64 master_status = 4 [(gogoproto.jsontag) = "master_status"];
// 佩戴状态 0:未佩戴 1:佩戴中
int64 status = 5 [(gogoproto.jsontag) = "status"];
}
}

View File

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

View File

@@ -0,0 +1,47 @@
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/live/fans_medal/conf"
"go-common/app/service/live/fans_medal/server/http"
"go-common/app/service/live/fans_medal/service"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
log.Info("fans_medal-service start")
trace.Init(conf.Conf.Tracer)
defer trace.Close()
ecode.Init(conf.Conf.Ecode)
svc := service.New(conf.Conf)
http.Init(conf.Conf)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
svc.Close()
log.Info("fans_medal-service exit")
time.Sleep(time.Second)
return
case syscall.SIGHUP:
default:
return
}
}
}

View File

@@ -0,0 +1,35 @@
[mysql]
addr = "127.0.0.1:3306"
dsn = "test:test@tcp(127.0.0.1:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
readDSN = ["test:test@tcp(127.0.0.2:3306)/test? timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4","test:test@tcp(127.0.0.3:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"]
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "100ms"
execTimeout = "100ms"
tranTimeout = "200ms"
[redis]
name = "fans_medal-service"
proto = "tcp"
addr = ""
idle = 10
active = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "1m"
[memcache]
name = "fans_medal-service"
proto = "tcp"
addr = ""
active = 50
idle = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "24h"

View File

@@ -0,0 +1,40 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["conf.go"],
importpath = "go-common/app/service/live/fans_medal/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/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/verify:go_default_library",
"//library/net/trace:go_default_library",
"//vendor/github.com/BurntSushi/toml:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,88 @@
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"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
"go-common/library/net/trace"
"github.com/BurntSushi/toml"
)
var (
confPath string
client *conf.Client
// Conf config
Conf = &Config{}
)
// Config .
type Config struct {
Log *log.Config
BM *bm.ServerConfig
Verify *verify.Config
Tracer *trace.Config
Redis *redis.Config
Memcache *memcache.Config
MySQL *sql.Config
Ecode *ecode.Config
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init init conf
func Init() error {
if confPath != "" {
return local()
}
return remote()
}
func local() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}

View File

@@ -0,0 +1,34 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/live/fans_medal/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/fans_medal/conf:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql: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,43 @@
package dao
import (
"context"
"go-common/app/service/live/fans_medal/conf"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
xsql "go-common/library/database/sql"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
redis *redis.Pool
db *xsql.DB
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
redis: redis.NewPool(c.Redis),
db: xsql.NewMySQL(c.MySQL),
}
return
}
// Close close the resource.
func (d *Dao) Close() {
d.mc.Close()
d.redis.Close()
d.db.Close()
return
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) error {
// TODO: if you need use mc,redis, please add
return d.db.Ping(c)
}

View File

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

View File

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

View File

@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["http.go"],
importpath = "go-common/app/service/live/fans_medal/server/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/fans_medal/conf:go_default_library",
"//app/service/live/fans_medal/service:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

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

View File

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

View File

@@ -0,0 +1,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["intimacy_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["intimacy.go"],
importpath = "go-common/app/service/live/fans_medal/service/intimacy",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,137 @@
package intimacy
// MaxLevel 大航海最高等级20级
var MaxLevel = 20
// levelConf 等级权益
type levelConf struct {
levelUpExp int // 升级所需
levelLimit int // 等级上限
sumScore int // 亲密度总和
}
// LevelConf 粉丝勋章等级配置
var LevelConf = []levelConf{
{0, 0, -1},
{201, 500, 0}, // 1
{300, 500, 201},
{500, 500, 501},
{700, 500, 1001},
{1000, 500, 1701}, //5
{1500, 1000, 2701},
{1600, 1000, 4201},
{1700, 1000, 5801},
{1900, 1000, 7501},
{5500, 1000, 9401}, //10
{10000, 1500, 14901},
{10000, 1500, 24901},
{10000, 1500, 34901},
{15000, 1500, 44901},
{40000, 1500, 59901}, //15
{50000, 2000, 99901},
{100000, 2000, 149901},
{250000, 2000, 249901},
{500000, 2000, 499901},
{1000000, 2000, 999901}, //20
}
// LimitAddition 大航海不同等级时的加成
// 0 没有大航海,不加成
// 1 总督 3倍加成
// 2 提督 2倍加成
// 3 舰长 1.5倍加成
var LimitAddition = [4]float32{1.0, 3.0, 2.0, 1.5}
// Increaser 亲密度增加前的状态
type Increaser struct {
currScore int // 当前等级
currLimit int // 当前消耗的上限
incrScore int // 本次增加的亲密度
skipLimit bool // 是否跳过每日上限的限制
}
// Result 亲密度增加后的结果
type Result struct {
incr int // 实际增加的亲密度
score int // 增加亲密度之后
limit int // 当前上限
level int // 亲密度增加后的等级
}
// IncreaseResult 亲密度增加结果,包含是否超过最低上线的标志
type IncreaseResult struct {
// 是否超过最低的上限,加上这个字段是为了提升性能
// 如果某一次增加亲密度没有超过最低的上限,就不需要请求该用户的大航海信息
// 减少一次网络请求
passLimit bool
retList [4]Result
}
// Increase 根据当前 score 计算增加亲密度之后的结果
// 粉丝勋章服务中最为核心的逻辑
func Increase(medal *Increaser) (ret IncreaseResult) {
// 用户在5上限是最大上限500在6级是最大上限是1000
// 如果他在当前上限为499的情况下增加两点亲密度
// 按增加之前的等级计算上限,会浪费掉一点亲密度
// 所以按增加之后的等级计算上限
sum := medal.currScore + medal.incrScore
newLevel, _ := GetLevel(sum)
// 把几种大航海等级对应的上限加成结果都计算出来
for i, addition := range LimitAddition {
incr := medal.incrScore
// 不消耗今日上限,直接按原数值加上
if medal.skipLimit {
ptr := &ret.retList[i]
ptr.incr = incr
ptr.limit = medal.currLimit
ptr.score = medal.currScore + incr
ptr.level, _ = GetLevel(ptr.score)
continue
}
// 新等级对应的上限,考虑大航海加成情况
maxLimit := addition * float32(LevelConf[newLevel].levelLimit)
// 今日还能加多少亲密度
leftLimit := int(maxLimit) - medal.currLimit
// 避免极端情况下该值为负
// 比如产品把大航海加成调低,某些土豪用户已有上限又较高
// 该值就会为负
if leftLimit < 0 {
leftLimit = 0
}
// 累加不能超过上限
if incr > leftLimit {
ret.passLimit = true
incr = leftLimit
}
ptr := &ret.retList[i]
ptr.incr = incr
ptr.limit = medal.currLimit + incr
ptr.score = medal.currScore + incr
ptr.level, _ = GetLevel(ptr.score)
}
return
}
// GetLevel 根据 score 计算等级和当前等级亲密度
func GetLevel(score int) (currLevel int, currIntimacy int) {
currLevel = MaxLevel
for currLevel > 0 {
conf := LevelConf[currLevel]
if score >= conf.sumScore {
currIntimacy = score - conf.sumScore
break
}
currLevel -= 1
}
return
}

View File

@@ -0,0 +1,160 @@
package intimacy
import (
"fmt"
"testing"
)
func TestLevelConf(t *testing.T) {
var sumScore = 0
level := 1
for level < MaxLevel {
conf := LevelConf[level]
sumScore += conf.levelUpExp
if sumScore != LevelConf[level+1].sumScore {
t.Error("LevelConf")
}
level += 1
}
}
type IncreaseCases struct {
param Increaser
ret IncreaseResult
}
var cases = []IncreaseCases{
{
Increaser{0, 0, 10000000, true},
IncreaseResult{
false,
[4]Result{
{10000000, 10000000, 0, 20},
{10000000, 10000000, 0, 20},
{10000000, 10000000, 0, 20},
{10000000, 10000000, 0, 20},
},
},
},
{
Increaser{0, 0, 1, false},
IncreaseResult{
false,
[4]Result{
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
},
},
},
{
Increaser{0, 0, 201, false},
IncreaseResult{
false,
[4]Result{
{201, 201, 201, 2},
{201, 201, 201, 2},
{201, 201, 201, 2},
{201, 201, 201, 2},
},
},
},
{
Increaser{0, 0, 2700, false},
IncreaseResult{
true,
[4]Result{
{500, 500, 500, 2},
{1500, 1500, 1500, 4},
{1000, 1000, 1000, 3},
{750, 750, 750, 3},
},
},
},
{
Increaser{1700, 499, 3001, false},
IncreaseResult{
true,
[4]Result{
{501, 2201, 1000, 5},
{2501, 4201, 3000, 7},
{1501, 3201, 2000, 6},
{1001, 2701, 1500, 6},
},
},
},
{
Increaser{1700, 499, 2, false},
IncreaseResult{
true,
[4]Result{
{1, 1701, 500, 5},
{2, 1702, 501, 5},
{2, 1702, 501, 5},
{2, 1702, 501, 5},
},
},
},
{
Increaser{1700, 499, 2, false},
IncreaseResult{
true,
[4]Result{
{1, 1701, 500, 5},
{2, 1702, 501, 5},
{2, 1702, 501, 5},
{2, 1702, 501, 5},
},
},
},
}
// TestIncrease 测试亲密度增加逻辑
// 这是核心接口
func TestIncrease(t *testing.T) {
testTimes := 2000
for testTimes > 0 {
testTimes -= 1
for i, currCase := range cases {
fmt.Println(currCase)
ret := Increase(&currCase.param)
if ret.passLimit != currCase.ret.passLimit {
t.Error("case ", i, "passLimit 计算错误")
}
for n := 0; n < 4; n++ {
ptr1 := &ret.retList[n]
ptr2 := &currCase.ret.retList[n]
if ptr1.score != ptr2.score {
t.Error("case ", i, "retList ", n, " score 计算错误")
}
if ptr1.limit != ptr2.limit {
t.Error("case ", i, "retList ", n, " limit 计算错误")
}
if ptr1.incr != ptr2.incr {
t.Error("case ", i, "incr ", n, " score 计算错误")
}
if ptr1.level != ptr2.level {
t.Error("case ", i, "level ", n, ptr1.level, " != ", ptr2.level)
}
}
}
}
}
func TestGetLevel(t *testing.T) {
fmt.Println(GetLevel(201))
for i, elem := range LevelConf {
currLevel, currIntimacy := GetLevel(elem.sumScore)
if currLevel != i || currIntimacy != 0 {
t.Error("GetLevel 有错 ", currLevel, currIntimacy)
}
}
}

View File

@@ -0,0 +1,33 @@
package service
import (
"context"
"go-common/app/service/live/fans_medal/conf"
"go-common/app/service/live/fans_medal/dao"
)
// Service struct
type Service struct {
c *conf.Config
dao *dao.Dao
}
// New init
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
dao: dao.New(c),
}
return s
}
// Ping Service
func (s *Service) Ping(c context.Context) (err error) {
return s.dao.Ping(c)
}
// Close Service
func (s *Service) Close() {
s.dao.Close()
}