域名 AXUM.RS 将于 2025 年 10 月到期。我们无意再对其进行续费,如果你有意接续这个域名,请与我们取得联系。
  • AXUM.RS 现仅需人民币 3000 元(大写:叁仟元整。接受适度议价
  • 按照行业规则,AXUM.RS 到期后,大概率会进入长时间的赎回期,该期间内,如果你想拥有该域名,将要付出高额的费用
  • 我们已启用 AXUM.EU.ORG 域名,并将持续运营
  • 仅接受微信或支付宝交易
如果你对 AXUM.RS 有兴趣,请和我们进行联系:

数据结构与Protobuf

本章对我们项目的数据结构和proto进行定义。

proto 定义

分类服务的定义

syntax = "proto3";

package pb;

message Category {
  int32 id = 1;
  string name = 2;
  bool is_del = 3;
}

// --- 创建分类
message CreateCategoryRequest { string name = 1; }
message CreateCategoryReply { int32 id = 1; }

// -- 修改分类
message EditCategoryRequest {
  int32 id = 1;
  string name = 2;
}
message EditCategoryReply {
  int32 id = 1;
  bool ok = 2;
}

// -- 分类列表
message ListCategoryRequest {
  optional string name = 1; // 根据分类名称查找
  optional bool is_del = 2; // 是否删除
}
message ListCategoryReply { repeated Category categories = 1; }

// -- 删除/恢复分类
message ToggleCategoryRequest { int32 id = 1; }
message ToggleCategoryReply {
  int32 id = 1;
  bool is_del = 2;
}

// -- 分类是否存在
message CategoryExistsRequest {
  oneof condition {
    string name = 1;
    int32 id = 2;
  }
}
message CategoryExistsReply { bool exists = 1; }

// -- 分类详情
message GetCategoryRequest {
  int32 id = 1;
  optional bool is_del = 2;
}
message GetCategoryReply { optional Category category = 1; }

service CategoryService {
  // 创建分类
  rpc CreateCategory(CreateCategoryRequest) returns (CreateCategoryReply);
  // 修改分类
  rpc EditCategory(EditCategoryRequest) returns (EditCategoryReply);
  // 分类列表
  rpc ListCategory(ListCategoryRequest) returns (ListCategoryReply);
  // 删除/恢复分类
  rpc ToggleCategory(ToggleCategoryRequest) returns (ToggleCategoryReply);
  // 分类是否存在
  rpc CategoryExists(CategoryExistsRequest) returns (CategoryExistsReply);
  // 获取分类详情
  rpc GetCategory(GetCategoryRequest) returns (GetCategoryReply);
}

文章服务的定义

syntax = "proto3";

package pb;

import "google/protobuf/timestamp.proto";

message Topic {
  int64 id = 1;
  string title = 2;
  int32 category_id = 3;
  string summary = 4;
  string content = 5;
  int32 hit = 6;
  bool is_del = 7;
  google.protobuf.Timestamp dateline = 8;
}

message DatelineRange {
  google.protobuf.Timestamp start = 1;
  google.protobuf.Timestamp end = 2;
}

// -- 创建文章
message CreateTopicRequest {
  string title = 1;
  int32 category_id = 2;
  string content = 3;
  optional string summary = 4; // 如果没有提供摘要,则自动从内容中截取
}
message CreateTopicReply { int64 id = 1; }

// -- 修改文章
message EditTopicRequest {
  int64 id = 1;
  string title = 2;
  int32 category_id = 3;
  optional string summary = 4; // 如果没有提供摘要,则自动从内容中截取
  string content = 5;
}
message EditTopicReply {
  int64 id = 1;
  bool ok = 2;
}

// -- 文章列表
message ListTopicRequest {
  optional int32 page = 1;                   // 页码
  optional int32 category_id = 2;            // 分类
  optional string keyword = 3;               // 关键字
  optional bool is_del = 4;                  // 是否删除
  optional DatelineRange dateline_range = 5; // 时间区间
}
message ListTopicReply {
  int32 page = 1;            // 当前页码
  int32 page_size = 2;       // 每页条数
  int64 page_totoal = 3;     // 总页数
  int64 record_total = 4;    // 总记录数
  repeated Topic topics = 5; // 文章列表
}

// -- 删除/恢复文章
message ToggleTopicRequest { int64 id = 1; }
message ToggleTopicReply {
  int64 id = 1;
  bool is_del = 2;
}

// -- 获取文章详情
message GetTopicRequest {
  int64 id = 1;
  optional bool is_del = 2;
  optional bool inc_hit = 3; // 是否同时增加点击量
}
message GetTopicReply { optional Topic topic = 1; }

service TopicService {
  // 创建文章
  rpc CreateTopic(CreateTopicRequest) returns (CreateTopicReply);
  // 修改文章
  rpc EditTopic(EditTopicRequest) returns (EditTopicReply);
  // 文章列表
  rpc ListTopic(ListTopicRequest) returns (ListTopicReply);
  // 删除/恢复文章
  rpc ToggleTopic(ToggleTopicRequest) returns (ToggleTopicReply);
  // 获取文章详情
  rpc GetTopic(GetTopicRequest) returns (GetTopicReply);
}
要查看完整内容,请先登录