From ec7c2181e29c5c648a1840ddd0a712ffbf0b703c Mon Sep 17 00:00:00 2001 From: longxboy Date: Sun, 27 Jun 2021 13:12:56 +0800 Subject: [PATCH] add source code installing (#1113) --- Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 9 +++++++++ README_zh.md | 9 +++++++++ 3 files changed, 75 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..6229ef156 --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +user := $(shell whoami) +rev := $(shell git rev-parse --short HEAD) + +# GOBIN > GOPATH > INSTALLDIR +GOBIN := $(shell echo ${GOBIN} | cut -d':' -f1) +GOPATH := $(shell echo $(GOPATH) | cut -d':' -f1) +BIN := "" + +# check GOBIN +ifneq ($(GOBIN),) + BIN=$(GOBIN) +else + # check GOPATH + ifneq ($(GOPATH),) + BIN=$(GOPATH)/bin + endif +endif + +all: + @cd cmd/kratos && go build && cd - &> /dev/null + @cd cmd/protoc-gen-go-errors && go build && cd - &> /dev/null + @cd cmd/protoc-gen-go-http && go build && cd - &> /dev/null + +.PHONY: install +.PHONY: uninstall +.PHONY: clean +.PHONY: fmt + +install: all +ifeq ($(user),root) +#root, install for all user + @cp ./cmd/kratos/kratos /usr/bin + @cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors /usr/bin + @cp ./cmd/protoc-gen-go-http/protoc-gen-go-http /usr/bin +else +#!root, install for current user + $(shell if [ -z $(BIN) ]; then read -p "Please select installdir: " REPLY; mkdir -p $${REPLY};\ + cp ./cmd/kratos/kratos $${REPLY}/;cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors $${REPLY}/;cp ./cmd/protoc-gen-go-http/protoc-gen-go-http $${REPLY}/;else mkdir -p $(BIN);\ + cp ./cmd/kratos/kratos $(BIN);cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors $(BIN);cp ./cmd/protoc-gen-go-http/protoc-gen-go-http $(BIN); fi) +endif + @which protoc-gen-go &> /dev/null || go get google.golang.org/protobuf/cmd/protoc-gen-go + @which protoc-gen-go-grpc &> /dev/null || go get google.golang.org/grpc/cmd/protoc-gen-go-grpc + @which protoc-gen-validate &> /dev/null || go get github.com/envoyproxy/protoc-gen-validate + @echo "install finished" + +uninstall: + $(shell for i in `which -a kratos | grep -v '/usr/bin/kratos' 2>/dev/null | sort | uniq`; do read -p "Press to remove $${i} (y/n): " REPLY; if [ $${REPLY} = "y" ]; then rm -f $${i}; fi; done) + $(shell for i in `which -a protoc-gen-go-grpc | grep -v '/usr/bin/protoc-gen-go-errors' 2>/dev/null | sort | uniq`; do read -p "Press to remove $${i} (y/n): " REPLY; if [ $${REPLY} = "y" ]; then rm -f $${i}; fi; done) + $(shell for i in `which -a protoc-gen-validate | grep -v '/usr/bin/protoc-gen-go-errors' 2>/dev/null | sort | uniq`; do read -p "Press to remove $${i} (y/n): " REPLY; if [ $${REPLY} = "y" ]; then rm -f $${i}; fi; done) + @echo "uninstall finished" + +clean: + @go mod tidy + @echo "clean finished" + +fmt: + @gofmt -s -w . \ No newline at end of file diff --git a/README.md b/README.md index db2186cab..1b2695ac2 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,18 @@ Kratos boosts your productivity. With the integration of excellent resources and - [protoc-gen-go](https://github.com/protocolbuffers/protobuf-go) ### Installing +##### install from go get: ``` go get github.com/go-kratos/kratos/cmd/kratos/v2@latest +kratos upgrade ``` +##### install from source code: +``` +git clone https://github.com/go-kratos/kratos +cd kratos +make install +``` + ### Create a service ``` # create project template diff --git a/README_zh.md b/README_zh.md index 5f1851f03..00e91177f 100644 --- a/README_zh.md +++ b/README_zh.md @@ -49,9 +49,18 @@ Kratos 一套轻量级 Go 微服务框架,包含大量微服务相关框架及 - [protoc-gen-go](https://github.com/protocolbuffers/protobuf-go) ### Installing +##### go get 安装: ``` go get github.com/go-kratos/kratos/cmd/kratos/v2@latest +kratos upgrade ``` +##### 源码编译安装: +``` +git clone https://github.com/go-kratos/kratos +cd kratos +make install +``` + ### Create a service ``` # 创建项目模板