【问题标题】:Generate server.go base on grpc proto method with GoLand使用 GoLand 基于 grpc proto 方法生成 server.go
【发布时间】:2018-08-08 08:36:50
【问题描述】:

GoLand 中是否有一些函数或插件可以基于 proto rpc 方法生成 server/server.go 方法?

例如我们有some.proto:

...
rpc AnyMetod (AnyRequest) return (AnyResponse)
...

我想生成:

func (s *Server) AnyMethod(ctx context.Context, req *AnyRequest) (*AnyResponse, error) {
    return &AnyResponse{}
}

【问题讨论】:

    标签: go jetbrains-ide goland


    【解决方案1】:

    目前我不知道有任何此类插件或功能可用。

    如果您想开发自己的插件,可以先阅读我们的SDK documentation

    作为替代方案,我认为您可以使用Live Templates 功能来实现与此非常相似的功能,其内容类似于以下示例的行,并定义可用于“Go | File”的模板上下文:

    func (s *$VAR4$) $VAR0$(ctx context.Context, req *$VAR1$) (*$VAR2$, error) {
        return &$VAR2${}
    }
    

    【讨论】:

    • 非常感谢您提供的信息:实时模板现在可以正常工作。我之前考虑过插件 - 现在我知道如何开始了:)
    猜你喜欢
    • 1970-01-01
    • 2021-01-27
    • 2018-08-01
    • 2021-04-17
    • 2016-06-14
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多