-
Notifications
You must be signed in to change notification settings - Fork 1
/
genproto.sh
50 lines (34 loc) · 1.9 KB
/
genproto.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
set -eu
function trap_handler {
MYSELF="$0" # equals to my script name
LASTLINE="$1" # argument 1: last line of error occurence
LASTERR="$2" # argument 2: error code of last command
echo "Error: line ${LASTLINE} - exit status of last command: ${LASTERR}"
exit $2
}
trap 'trap_handler ${LINENO} ${$?}' ERR
echo "Checking tools dependencies..."
which protoc
which protoc-gen-go
which protoc-gen-validate
GO_IMPORT_SPACES=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any,\
Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,\
Mgoogle/protobuf/struct.proto=github.com/golang/protobuf/ptypes/struct,\
Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,\
Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers,\
Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
#MOD=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any
#Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
protoc -Iprotos --go_out=${GO_IMPORT_SPACES},plugins=grpc:protos user.proto
protoc -I "${GOROOT}/include" -I protos/rbac -I "${GOPATH}/src" --go_out="${GO_IMPORT}:protos/rbac"--micro_out="${GO_IMPORT}:protos/rbac" --validate_out="lang=go:protos/rbac" rbac.proto
# 增加valid 校验
# protoc-go-inject-tag -input=protos/user.pb.go
# 去掉omitempty
# ls *.pb.go | xargs -n1 -IX bash -c "sed -e 's/,omitempty//' X > X.tmp && mv X{.tmp,}"
# 增加 bson:"-"
# ls *.pb.go | xargs -n1 -IX bash -c "sed -e 's/json\:\"-\"/json\:\"-\" bson:\"-\"/' X > X.tmp && mv X{.tmp,}"
# ls *.pb.go | xargs -n1 -IX bash -c "sed -e 's/json\:\"id\"/json\:\"id\" bson:\"_id\"/' X > X.tmp && mv X{.tmp,}"
# ls *.pb.go | xargs -n1 -IX bash -c "sed -e 's/json\:\"children\"/json\:\"children\" bson:\"-\"/' X > X.tmp && mv X{.tmp,}"
echo "Complete"
read -n1 -p "Press any key to continue..."