Skip to content

Commit 7c16667

Browse files
committed
feat: 升级grpc
1 parent 6b10802 commit 7c16667

File tree

7 files changed

+236
-43
lines changed

7 files changed

+236
-43
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,29 @@ and `micro user set [namespace]`.
8989
### From Source
9090

9191
```
92+
go install github.com/2637309949/micro/v3@latest
93+
```
94+
95+
### Install Binaries
96+
97+
#### Windows
98+
99+
```sh
100+
powershell -Command "iwr -useb https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.ps1 | iex"
101+
102+
```
103+
#### Linux
104+
105+
```sh
92106
wget -q https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.sh -O - | /bin/bash
93107
```
94108

109+
#### MacOS
110+
111+
```sh
112+
curl -fsSL https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.sh | /bin/bash
113+
```
114+
95115
### Run the server
96116

97117
```sh
@@ -149,9 +169,9 @@ Creating service helloworld
149169
├── main.go
150170
├── generate.go
151171
├── handler
152-
   └── helloworld.go
172+
└── helloworld.go
153173
├── proto
154-
   └── helloworld.proto
174+
└── helloworld.proto
155175
├── Dockerfile
156176
├── Makefile
157177
├── README.md

go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ require (
4545
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
4646
github.com/patrickmn/go-cache v2.1.0+incompatible
4747
github.com/pkg/errors v0.9.1
48-
github.com/prometheus/client_golang v1.11.0
48+
github.com/prometheus/client_golang v1.11.1
4949
github.com/rs/cors v1.8.2 // indirect
5050
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516
5151
github.com/stoewer/go-strcase v1.2.0
@@ -57,7 +57,9 @@ require (
5757
github.com/urfave/cli/v2 v2.3.0
5858
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca
5959
go.etcd.io/bbolt v1.3.6
60-
go.etcd.io/etcd v0.5.0-alpha.5.0.20200425165423-262c93980547
60+
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c
61+
go.etcd.io/etcd/api/v3 v3.5.4
62+
go.etcd.io/etcd/client/v3 v3.5.4
6163
go.uber.org/zap v1.17.0
6264
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
6365
golang.org/x/net v0.0.0-20220607020251-c690dde0001d
@@ -66,7 +68,3 @@ require (
6668
google.golang.org/protobuf v1.28.0
6769
tailscale.com v1.28.0
6870
)
69-
70-
// This can be removed once etcd becomes go gettable, version 3.4 and 3.5 is not,
71-
// see https://github.com/etcd-io/etcd/issues/11154 and https://github.com/etcd-io/etcd/issues/11931.
72-
replace google.golang.org/grpc => google.golang.org/grpc v1.27.1

go.sum

Lines changed: 69 additions & 19 deletions
Large diffs are not rendered by default.

plugin/etcd/etcd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import (
3232
"github.com/2637309949/micro/v3/service/logger"
3333
"github.com/2637309949/micro/v3/service/registry"
3434
hash "github.com/mitchellh/hashstructure"
35-
"go.etcd.io/etcd/clientv3"
35+
"go.etcd.io/etcd/api/v3/mvccpb"
36+
clientv3 "go.etcd.io/etcd/client/v3"
3637
"go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
37-
"go.etcd.io/etcd/mvcc/mvccpb"
3838
"go.uber.org/zap"
3939
)
4040

plugin/etcd/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/2637309949/micro/v3/service/registry"
26-
"go.etcd.io/etcd/clientv3"
26+
clientv3 "go.etcd.io/etcd/client/v3"
2727
)
2828

2929
type etcdWatcher struct {

scripts/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$ErrorActionPreference = 'stop'
22

33
# GitHub Org and Repo to get archives from
4-
$GitHubOrg="micro"
4+
$GitHubOrg="2637309949"
55
$GitHubRepo="micro"
66
$githubHeader = @{}
77

scripts/install.sh

Lines changed: 137 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

34
# GitHub Org and Repo to get archives from
45
GITHUB_ORG="2637309949"
56
GITHUB_REPO="micro"
6-
GITHUB_SSH="[email protected]:${GITHUB_ORG}/${GITHUB_REPO}.git"
7-
TMP_DIR=$(mktemp -d -t x-micro.XXXXXXXX)
7+
8+
# micro install directory
9+
MICRO_INSTALL_DIR="$HOME/bin"
10+
# micro cli name
11+
MICRO_CLI_NAME="micro"
12+
# micro cli install path
13+
MICRO_CLI_PATH="${MICRO_INSTALL_DIR}/${MICRO_CLI_NAME}"
14+
15+
# get machine ARCH
16+
ARCH=$(uname -m)
17+
# get machine OS
18+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
19+
# Linux requires sudo for $MICRO_INSTALL_DIR
20+
SUDO="false"
21+
22+
# Http request CLI
23+
HTTP_CLIENT=curl
824

925
getSystemInfo() {
1026
echo "Getting system information"
@@ -24,23 +40,132 @@ getSystemInfo() {
2440
echo "Your machine is running ${OS} on ${ARCH} CPU architecture"
2541
}
2642

43+
checkSupported() {
44+
local supported_osarch=(darwin-amd64 darwin-arm64 linux-amd64 linux-arm7 linux-arm64)
45+
local machine_osarch="${OS}-${ARCH}"
46+
47+
echo "Checking machine system support"
48+
for osarch in "${supported_osarch[@]}"; do
49+
if [ "$osarch" == "$machine_osarch" ]; then
50+
return
51+
fi
52+
done
53+
54+
echo "No prebuilt binary for ${machine_osarch}"
55+
exit 1
56+
}
57+
58+
checkHttpClient() {
59+
echo "Checking HTTP client"
60+
if type "curl" > /dev/null; then
61+
HTTP_CLIENT="curl"
62+
elif type "wget" > /dev/null; then
63+
HTTP_CLIENT="wget"
64+
else
65+
echo "Either curl or wget is required"
66+
exit 1
67+
fi
68+
}
69+
70+
sudoRun() {
71+
local CMD="$*"
72+
73+
if [ $EUID -ne 0 -a $SUDO = "true" ]; then
74+
CMD="sudo $CMD"
75+
fi
76+
77+
$CMD
78+
}
79+
80+
getLatestRelease() {
81+
local release_url="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
82+
local latest_release=""
83+
84+
echo "Getting the latest micro release"
85+
if [ "$HTTP_CLIENT" == "curl" ]; then
86+
latest_release=$(curl -s $release_url | grep \"tag_name\" | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
87+
else
88+
latest_release=$(wget -q --header="Accept: application/json" -O - $release_url | grep \"tag_name\" | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
89+
fi
90+
echo "Latest micro release found: ${latest_release}"
91+
92+
LATEST_RELEASE_TAG=$latest_release
93+
CLI_ARCHIVE="${MICRO_CLI_NAME}-${LATEST_RELEASE_TAG}-${OS}-${ARCH}.tar.gz"
94+
DOWNLOAD_BASE="https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download"
95+
DOWNLOAD_URL="${DOWNLOAD_BASE}/${LATEST_RELEASE_TAG}/${CLI_ARCHIVE}"
96+
97+
TMP_ROOT=$(mktemp -dt micro-install-XXXXXX)
98+
TMP_FILE="$TMP_ROOT/$CLI_ARCHIVE"
99+
100+
echo "Downloading $DOWNLOAD_URL ..."
101+
if [ "$HTTP_CLIENT" == "curl" ]; then
102+
curl -SsL "$DOWNLOAD_URL" -o "$TMP_FILE"
103+
else
104+
wget -q -O "$TMP_FILE" "$DOWNLOAD_URL"
105+
fi
106+
107+
if [ ! -f "$TMP_FILE" ]; then
108+
echo "Failed to download $DOWNLOAD_URL ..."
109+
exit 1
110+
fi
111+
}
112+
27113
installFile() {
28-
cd ${TMP_DIR} && go install
29-
cd ${TMP_DIR}/cmd/protoc-gen-micro && go install
30-
cd ${TMP_DIR}/cmd/protoc-gen-openapi && go install
31-
cd ${TMP_DIR}/cmd/protoc-gen-client && go install
114+
tar xf "$TMP_FILE" -C "$TMP_ROOT"
115+
local tmp_root_cli="$TMP_ROOT/$MICRO_CLI_NAME"
116+
117+
if [ ! -f "$tmp_root_cli" ]; then
118+
echo "Failed to unpack micro binary."
119+
exit 1
120+
fi
121+
122+
# mkdir if not exists
123+
if [ ! -d $MICRO_INSTALL_DIR ]; then
124+
mkdir -p $MICRO_INSTALL_DIR
125+
fi
126+
127+
chmod o+x $tmp_root_cli
128+
sudoRun cp "$tmp_root_cli" "$MICRO_INSTALL_DIR"
129+
130+
if [ -f "$MICRO_CLI_PATH" ]; then
131+
echo "$MICRO_CLI_NAME installed into $MICRO_INSTALL_DIR successfully."
132+
133+
$MICRO_CLI_PATH --version
134+
else
135+
echo "Failed to install $MICRO_CLI_NAME. Already exists."
136+
exit 1
137+
fi
138+
139+
if [ "$MICRO_CLI_PATH" != "$(which micro)" ]; then
140+
# From https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
141+
YELLOW='\033[1;33m'
142+
NC='\033[0m' # No Color
143+
printf "${YELLOW}Looks like there is an other micro installation in your path under \"$(which micro)\" already.\nPlease put \"export PATH=$MICRO_INSTALL_DIR:\$PATH\" in your bashrc.${NC}\n"
144+
fi
32145
}
33146

34-
cleanup() {
35-
rm ${TMP_DIR} -rf
147+
fail_trap() {
148+
result=$?
149+
if [ "$result" != "0" ]; then
150+
echo "Failed to install micro"
151+
fi
152+
cleanup
153+
exit $result
36154
}
37155

38-
cloneRepo() {
39-
git clone ${GITHUB_SSH} --depth=1 ${TMP_DIR}
156+
cleanup() {
157+
if [[ -d "${TMP_ROOT:-}" ]]; then
158+
rm -rf "$TMP_ROOT"
159+
fi
40160
}
41161

162+
# catch errors and print help
163+
trap "fail_trap" EXIT
164+
42165
# execute installation
43166
getSystemInfo
44-
cloneRepo
167+
checkSupported
168+
checkHttpClient
169+
getLatestRelease
45170
installFile
46-
cleanup
171+
cleanup

0 commit comments

Comments
 (0)