Skip to content

Instantly share code, notes, and snippets.

@majest
Created June 21, 2021 16:40
Show Gist options
  • Save majest/41831ef025a9239aedce1e961be01893 to your computer and use it in GitHub Desktop.
Save majest/41831ef025a9239aedce1e961be01893 to your computer and use it in GitHub Desktop.
IFS=
for command in go unzip git curl node npm
do
which $command &>/dev/null && echo "$command in path" || echo "$command NOT FOUND"
done
GEN_VERSION=1.25.0
GRPC_VERSION=1.26.0
GENGRPC_VERSION=1.0.1
PROTOC_VERSION=3.14.0
PROTOGEN_VERSION=1.2.1
case "$(uname -s)" in
Darwin)
PROTOC_ZIP=protoc-$PROTOC_VERSION-osx-x86_64.zip
PROTOGEN=protoc-gen-grpc-web-$PROTOGEN_VERSION-darwin-x86_64
;;
Linux) ## If it also works on mac delete switch case
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip
PROTOGEN=protoc-gen-grpc-web-$PROTOGEN_VERSION-linux-x86_64
;;
*)
echo "Could not detect the operating system. ($(uname -s)) Protoc has to be installed manually" >&2
exit 1
;;
esac
# protoc-gen-grpc-gateway needs to be below version 2. Otherwise it will not be compatible with protoc-gen-go-grpc which also needs to be in the correct version (1.31.0) works.
# If it's any higher, etc won't be compatible with grpc version which need sto be 1.26
GO111MODULE=on go get google.golang.org/protobuf/cmd/protoc-gen-go@v${GEN_VERSION}
GO111MODULE=on go get google.golang.org/grpc@v${GRPC_VERSION}
git clone -b v1.31.0 https://github.com/grpc/grpc-go
cd grpc-go/cmd/protoc-gen-go-grpc
go install
cd ../../../ && rm -fr ./grpc-go
GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway > /dev/null 2>&1
GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 > /dev/null 2>&1
GO111MODULE=off go get github.com/googleapis/googleapis > /dev/null 2>&1
GO111MODULE=off go get github.com/grpc-ecosystem/grpc-gateway > /dev/null 2>&1
GO111MODULE=off go get github.com/protocolbuffers/protobuf > /dev/null 2>&1
GO111MODULE=off go get github.com/golang/mock/mockgen
GO111MODULE=off go install github.com/golang/mock/mockgen
GO111MODULE=on go get github.com/golang/mock/mockgen@v1.5.0
echo "Fetching: https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}"
curl -o ${PROTOC_ZIP} -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}
unzip -o $PROTOC_ZIP -d $GOPATH bin/protoc
unzip -o $PROTOC_ZIP -d $GOPATH 'include/*'
rm -f $PROTOC_ZIP
echo "Fetching https://github.com/grpc/grpc-web/releases/download/${PROTOGEN_VERSION}/${PROTOGEN}"
curl -o ${PROTOGEN} -L https://github.com/grpc/grpc-web/releases/download/${PROTOGEN_VERSION}/${PROTOGEN}
mv ${PROTOGEN} ${GOPATH}/bin/protoc-gen-grpc-web && chmod +x ${GOPATH}/bin/protoc-gen-grpc-web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment