Skip to content

Instantly share code, notes, and snippets.

@yangyang5214
Last active December 25, 2023 13:30
Show Gist options
  • Save yangyang5214/32dcff31bd425dcf95452ad908880e1f to your computer and use it in GitHub Desktop.
Save yangyang5214/32dcff31bd425dcf95452ad908880e1f to your computer and use it in GitHub Desktop.
protoc add bson tag
#!/bin/bash
function add_tag() {
if [[ $(uname) == "Darwin" ]]; then
# macOS
sed -i '' -E 's/json:"([^"]*)"(.*)$/json:"\1" bson:"\1"\2/g' "$1"
else
# Linux
sed -i -E 's/json:"([^"]*)"(.*)$/json:"\1" bson:"\1"\2/g' "$1"
fi
}
# api is protoc out dir
files=$(find api -type f -name '*.pb.go' ! -name "*http.pb.go" ! -name "*grpc.pb.go")
for proto in $files ; do
echo 'add bson tag: '$proto
add_tag "$proto"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment