LoginSignup
2
3

More than 5 years have passed since last update.

外部packageへのimportを含むprotoファイルをまとめてprotocでgo_outするシェルスクリプト

Last updated at Posted at 2017-06-03
src
  |
  |--api/
  |    |--foo.proto
  |    |
  |--bff/
  |    |--bar.proto
  |    |--empty.proto
  |    |

syntax = "proto3";

package api;

message Foo {
  uint32 id = 1;
}

syntax = "proto3";

package bff;

import "api/foo.proto";

message Bar {
  api.Foo foo = 1;
}

みたいな感じだとして、普通に

protoc --go_out=plugins=grpc:. bff/*.proto

とかしてもダメなので

#!/bin/bash
for file in `\find bff -name '*.proto'`; do
    temp="$temp $file"
done
protoc --go_out=plugins=grpc:. $temp

的な感じで。シェルスクリプト難しい。ちなみにgolangの場合、protocに食わせるprotoファイルはスペース区切りで一度に全指定しないとセルフインポートするコードが生成されて循環インポートでgoのbuildが死ぬ。あとprotoファイルのpackage名にハイフンがあると多分protocが死ぬ。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3