Skip to content

Commit

Permalink
Add script to generate go protobuf code
Browse files Browse the repository at this point in the history
Script can be invoked with "go generate", and also adds
or corrects the go_package compilation option in the dnstap
protobuf spec.
  • Loading branch information
cmikk committed Feb 9, 2021
1 parent b3fb968 commit ebb538e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dnstap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

//go:generate ./genproto.sh

package dnstap

const outputChannelSize = 32
Expand Down
1 change: 0 additions & 1 deletion dnstap.pb/dnstap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

syntax = "proto2";
package dnstap;

option go_package = "github.com/dnstap/golang-dnstap;dnstap";

// "Dnstap": this is the top-level dnstap type, which is a "union" type that
Expand Down
25 changes: 25 additions & 0 deletions genproto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

go_package() {
local file pkg line script
file=$1; shift
pkg=$1; shift

line="option go_package = \"$pkg\";"
grep "^$line\$" $file > /dev/null && return

script="/^package dnstap/|a|$line|.|w|q|"
if grep "^option go_package" $file > /dev/null; then
script="/^option go_package/d|1|${script}"
fi

echo "$script" | tr '|' '\n' | ed $file || exit
}

dir=$(dirname $0)
[ -n "$dir" ] && cd $dir

cd dnstap.pb

go_package dnstap.proto "github.com/dnstap/golang-dnstap;dnstap"
protoc --go_out=../../../.. dnstap.proto

0 comments on commit ebb538e

Please sign in to comment.