jzero-io / jzero

Used to create project from templates and generate Server/Client code by proto and api file.
https://jzero.jaronnie.com/
MIT License
33 stars 2 forks source link

框架需要 api 版本控制管理能力 #22

Closed jaronnie closed 2 weeks ago

jaronnie commented 2 weeks ago

初始化 v2 版本 api, 先支持 proto

jzero ivm init --version v2
jzero ivm add <service_name>

v2 默认调用 v1 logic

func (l *SayHelloLogic) SayHello(in *hellov2pb.Empty) (*hellov2pb.SayHelloResponse, error) {
    logic := hellologic.NewSayHelloLogic(l.ctx, l.svcCtx)

    marshal, err := proto.Marshal(in)
    if err != nil {
        return nil, err
    }
    var oldIn hellopb.Empty
    err = proto.Unmarshal(marshal, &oldIn)
    if err != nil {
        return nil, err
    }

    hello, err := logic.SayHello(&oldIn)
    if err != nil {
        return nil, err
    }
    marshal, err = proto.Marshal(hello)
    if err != nil {
        return nil, err
    }
    var newResp hellov2pb.SayHelloResponse
    err = proto.Unmarshal(marshal, &newResp)
    if err != nil {
        return nil, err
    }

    return &newResp, nil
}
jaronnie commented 2 weeks ago

support