首页 > 解决方案 > 使用 GoLand 基于 grpc proto 方法生成 server.go

问题描述

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

例如我们有some.proto

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

我想生成:

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

标签: gojetbrains-idegoland

解决方案


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

如果您想开发自己的插件,可以从阅读我们的SDK 文档开始。

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

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

推荐阅读