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,68 @@
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 = "api_proto",
srcs = ["api.proto"],
tags = ["automanaged"],
deps = [
"@com_google_protobuf//:empty_proto",
"@gogo_special_proto//github.com/gogo/protobuf/gogoproto",
],
)
go_proto_library(
name = "api_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/bbq/topic/api",
proto = ":api_proto",
tags = ["automanaged"],
deps = [
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@io_bazel_rules_go//proto/wkt:empty_go_proto",
],
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"common.go",
],
embed = [":api_go_proto"],
importpath = "go-common/app/service/bbq/topic/api",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/log:go_default_library",
"//library/net/rpc/warden:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@io_bazel_rules_go//proto/wkt:empty_go_proto",
"@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"],
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,173 @@
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/empty.proto";
package bbq.service.topic.v1;
option go_package = "api";
option (gogoproto.goproto_getters_all) = false;
message ListExtensionReq {
repeated int64 svids = 1;
}
message ListExtensionReply {
repeated VideoExtension list = 1;
}
message UpdateVideoScoreReq {
int64 svid = 1;
double score = 2;
}
message UpdateVideoStateReq {
int64 svid = 1;
int32 state = 2;
}
message TopicVideosReq {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id"'];
string cursor_prev = 2[(gogoproto.moretags)='form:"cursor_prev"'];
string cursor_next = 3[(gogoproto.moretags)='form:"cursor_next"'];
}
message ListMultiTopicVideosReq {
repeated TopicVideosReq list = 1;
}
message VideoItem {
int64 svid = 1;
string cursor_value = 2;
int64 hot_type = 3;
}
message TopicDetail {
TopicInfo topic_info = 1;
repeated VideoItem list = 2;
bool has_more = 3[(gogoproto.jsontag) = "has_more"];
}
message ListDiscoveryTopicReq {
int32 page = 1[(gogoproto.moretags)='form:"page" validate:"required"'];
}
message ListDiscoveryTopicReply {
repeated TopicDetail list = 1;
bool has_more = 2;
}
message ListTopicsReq {
int32 page = 1[(gogoproto.moretags)='form:"page" validate:"required"'];
}
message ListTopicsReply {
bool has_more = 1[(gogoproto.jsontag) = "has_more"];
repeated TopicInfo list = 2;
}
message StickTopicReq {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id" validate:"required"'];
int64 op = 2[(gogoproto.moretags)='form:"op"'];// 0表示取消置顶1表示置顶
}
message StickTopicVideoReq {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id" validate:"required"'];
int64 svid = 2[(gogoproto.moretags)='form:"svid" validate:"required"'];
int64 op = 3[(gogoproto.moretags)='form:"op"'];// 0表示取消置顶1表示置顶
}
message SetStickTopicVideoReq {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id" validate:"required"'];
repeated int64 svids = 2[(gogoproto.moretags)='form:"svids"'];
}
// 所有查找走同一个接口
message ListCmsTopicsReq {
int32 page = 1[(gogoproto.moretags)='form:"page" validate:"required"'];
string name = 2[(gogoproto.moretags)='form:"name"'];
int64 topic_id = 3[(gogoproto.moretags)='form:"topic_id"'];
int32 state = 4[(gogoproto.moretags)='form:"state"'];
}
message ListCmsTopicsReply {
bool has_more = 1[(gogoproto.jsontag) = "has_more"];
repeated TopicInfo list = 2;
}
service Topic {
////////////////extension////////////////
rpc Register (VideoExtension) returns (.google.protobuf.Empty);
rpc ListExtension (ListExtensionReq) returns (ListExtensionReply);
//////////////////topic///////////////////
rpc UpdateVideoScore(UpdateVideoScoreReq) returns (.google.protobuf.Empty);
rpc UpdateVideoState(UpdateVideoStateReq) returns (.google.protobuf.Empty);
// 获取话题下的视频
rpc ListTopicVideos (TopicVideosReq) returns (TopicDetail);
// TODO: to deleted. 发现页分成先请求话题,再请求话题下视频
// 获取发现页下的话题
rpc ListDiscoveryTopics (ListDiscoveryTopicReq) returns (ListDiscoveryTopicReply);
// 推荐的话题,不会返回话题内的视频
rpc ListTopics (ListTopicsReq) returns (ListTopicsReply);
///// cms /////
rpc StickTopic(StickTopicReq) returns (.google.protobuf.Empty);
// 置顶、取消置顶话题下的视频需要cms先去判断该视频是否可以放在话题中
rpc StickTopicVideo(StickTopicVideoReq) returns (.google.protobuf.Empty);
rpc SetStickTopicVideo(SetStickTopicVideoReq) returns (.google.protobuf.Empty);
// 注意:该接口不支持复杂条件,当以下三种同时请求的时候只会按顺序选择一种进行返回:
// 话题name查找接口不区分隐藏返回数组但是暂时只会完全匹配
// 话题隐藏列表接口,按照时间反向排序
// 话题推荐列表接口,按照热度反向排序,其中第一页会包含置顶话题
rpc ListCmsTopics(ListCmsTopicsReq) returns (ListCmsTopicsReply);
// 修改话题简介topic_id必传传直接放在http请求里
rpc UpdateTopicDesc(TopicInfo) returns (.google.protobuf.Empty);
rpc UpdateTopicState(TopicInfo) returns (.google.protobuf.Empty);
// 话题详情页,含话题信息+视频信息
// 使用video-c的topic/detail接口php内部转换成cms逻辑
// 根据svid返回topic_id列表
rpc VideoTopic(VideoTopicReq) returns (VideoTopicReply);
}
message TopicVideoItem {
int64 topic_id = 1;
int64 svid = 2;
double score = 3;
int32 state = 4;
}
message VideoTopicReq {
int64 svid = 1[(gogoproto.moretags)='form:"svid"'];
}
message VideoTopicReply {
repeated TopicVideoItem list = 1;
}
message UpdateTopicStateReq {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id"'];
int32 op = 2[(gogoproto.moretags)='form:"op"'];// 0表示通过1表示下架
}
message TopicInfo {
int64 topic_id = 1[(gogoproto.moretags)='form:"topic_id"'];
string name = 2;
string desc = 3[(gogoproto.moretags)='form:"desc"'];
double score = 4;
int32 state = 5[(gogoproto.moretags)='form:"state"'];// 0表示通过1表示下架
int32 hot_type = 6[(gogoproto.jsontag)="hot_type"];
string cover_url = 7[(gogoproto.moretags)='form:"cover_url"'];
}
message TitleExtraItem {
int64 id = 1[(gogoproto.jsontag) = "id"];
int64 type = 2[(gogoproto.jsontag) = "type"];
string name = 3[(gogoproto.jsontag) = "name"];
int64 start = 4[(gogoproto.jsontag) = "start"];
int64 end = 5[(gogoproto.jsontag) = "end"];
string scheme = 6[(gogoproto.jsontag) = "scheme"];
}
// 用于传递给上游的extension通过序列化赋值给extension
message VideoExtension {
int64 svid = 1;
string extension = 2; // 序列化后的Extension会放在这里
}
// 结构化的extension真正的extension
message Extension {
repeated TitleExtraItem title_extra = 1;
}

View File

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

View File

@@ -0,0 +1,34 @@
package api
import (
"context"
"encoding/json"
"go-common/library/log"
)
// Transform2Interface 转换成interface
func Transform2Interface(ctx context.Context, data []byte) (inter interface{}, err error) {
err = json.Unmarshal(data, &inter)
if err != nil {
log.Errorw(ctx, "log", "transform to interface fail", "data", string(data))
return
}
return
}
// 话题的状态
const (
TopicStateAvailable = 0
TopicStateUnAvailable = 1
TopicVideoStateAvailable = 0
TopicVideoStateUnAvailable = 1
)
// 话题热门类型的enum用于TopicInfo->HotType字段
// 开始时使用了hot_type但其实就是表示特殊的话题状态
const (
TopicHotTypeHot = 1 // 热门
TopicHotTypeHistory = 2 // 历史,暂时只有客户端使用
TopicHotTypeStick = 4 // 置顶
)