alimy/mir

add Thrift idl as DSL support for go-mir

alimy opened this issue · 1 comments

alimy commented

Add Thrift idl as DSL support for go-mir

namespace go car

include "../base/common.thrift"
include "../base/car.thrift"

struct AdminCreateCarRequest {
    1:  string plate_num (api.raw = "plate_num", api.vd = "len($) > 0 && len($) < 25>"),
}

struct AdminDeleteCarRequest {
    1:  string id (api.raw = "id", api.vd = "len($) > 0 && len($) < 25>"),
}

struct AdminGetSomeCarsRequest {}

struct AdminGetAllCarsRequest {}

struct GetCarsRequest {}

struct GetCarRequest {
    1:  string id (api.raw = "id", api.vd = "len($) > 0 && len($) < 25>"),
}

service CarService {
    // for back-stage management
    common.NilResponse AdminCreateCar(1: AdminCreateCarRequest req) (api.post = "/admin/car", api.chain = "true"),
    common.NilResponse AdminDeleteCar(1: AdminDeleteCarRequest req) (api.delete = "/admin/car", api.chain = "true"),
    common.NilResponse AdminGetSomeCars(1: AdminGetSomeCarsRequest req) (api.get = "/admin/car/some"),
    common.NilResponse AdminGetAllCars(1: AdminGetAllCarsRequest req) (api.get = "/admin/car/all"),

    // for mini-program
    common.NilResponse GetCars(1: GetCarsRequest req) (api.get = "/cars"),
    common.NilResponse GetCar(1: GetCarRequest req) (api.get = "/car"),
} (api.group = "v1", api.chain = "true")
alimy commented

我是看到hertz项目中直接使用了Thrift来描述api服务接口然后生成代码,确定了其可行性,又仔细考量了一下go-mir现有的架构,可以引入该功能特性,逐开始着手落地。