FE-star / Plan-2022

2022年新一代前端课程
48 stars 20 forks source link

[data-processor] proto 和 ts interface #7

Closed shenxiang11 closed 2 years ago

shenxiang11 commented 2 years ago

ts 的 interface 没有办法从 proto 自动生成吗? 这两处某种意义上来说,是“重复的”

interface ActivityRequest {
    id: string
}

interface ActivityResponse {
    offer: Offer[]
}

interface Offer {
    nid: string
    title: string
    pict_url: string
    icons: Icon[]
}

interface Icon {
    type: string
    bg_color: string
    border_color: string
    font_color: string
    text: string
    source: string
}

interface ActivityService {
  Call(req: ActivityRequest): Observable<ActivityResponse>
}

service ActivityService {
    rpc Call(ActivityRequest) returns (ActivityResponse) {}
}

message ActivityRequest {
    string id = 1;
}

message ActivityResponse {
    repeated Offer offer = 1;
}

message Offer {
    string nid = 1;
    string title = 2;
    string pictUrl = 3;
    repeated Icon icons = 4;
}

message Icon {
    string type = 1;
    string bgColor = 2;
    string borderColor = 3;
    string fontColor = 4;
    string text = 5;
    string source = 6;
}
miniflycn commented 2 years ago

有的,参考:https://github.com/stephenh/ts-proto/blob/main/NESTJS.markdown

也可以参考:https://github.com/FE-star/activity-micro-service/blob/main/build.proto.sh

emmm,不过这不是我们课程主要内容,data processor应该做数据合并和裁剪,对接数据并不是核心内容。但主要想演示一下非HTTP怎么对接的