-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(new): service generation closes #2060 * refactor(new): more advanced makefile universal makefile usage, `make init` to install `protoc`
- Loading branch information
1 parent
7f4bc57
commit c41ab10
Showing
4 changed files
with
104 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package template | ||
|
||
var ( | ||
DepInstall = `PROTOC_GEN_GO := $(GOBIN)/protoc-gen-go | ||
PROTOC_GEN_MICRO := $(GOBIN)/protoc-gen-micro | ||
PROTOC = $(shell which protoc || echo "$(GOBIN)/protoc") | ||
# Generate protoc latest binary url | ||
PROTOC_RELEASE_BIN := protoc | ||
ifeq ($(GOOS), linux) | ||
ifeq ($(GOARCH), amd64) | ||
PROTOC_RELEASE = linux-x86_64 | ||
else ifeq ($(GOARCH), arm64) | ||
PROTOC_RELEASE = linux-aarch_64 | ||
else ifeq ($(GOARCH), 386) | ||
PROTOC_RELEASE = linux-x86_32 | ||
else | ||
echo >&2 "only support amd64, arm64 or 386 GOARCH" && exit 1 | ||
endif | ||
else ifeq ($(GOOS), darwin) | ||
ifeq ($(GOARCH), amd64) | ||
PROTOC_RELEASE = osx-x86_64 | ||
else ifeq ($(GOARCH), arm64) | ||
PROTOC_RELEASE = osx-aarch_64 | ||
else | ||
echo >&2 "only support amd64 or arm64 GOARCH" && exit 1 | ||
endif | ||
else ifeq ($(GOOS), windows) | ||
ifeq ($(GOARCH), amd64) | ||
PROTOC_RELEASE = win64 | ||
else ifeq ($(GOARCH), 386) | ||
PROTOC_RELEASE = win32 | ||
else | ||
echo >&2 "only support amd64 or 386 GOARCH" && exit 1 | ||
endif | ||
PROTOC_RELEASE_BIN = protoc.exe | ||
endif | ||
PROTOC_LATEST = https://github.com/protocolbuffers/protobuf/releases/latest | ||
PROTOC_VERSION = $(shell curl -Ls -o /dev/null -w %{url_effective} $(PROTOC_LATEST) | sed 's|.*/v||') | ||
PROTOC_RELEASE_URL = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_RELEASE).zip | ||
# Install dependencies | ||
.PHONY: init | ||
init: $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_MICRO) | ||
# Install protoc latest binary | ||
# from release https://github.com/protocolbuffers/protobuf/releases | ||
# to $(GOBIN) | ||
$(PROTOC): | ||
curl -LSs $(PROTOC_RELEASE_URL) -o protoc.zip | ||
unzip -qqj protoc.zip "bin/$(PROTOC_RELEASE_BIN)" -d "$(GOBIN)" && rm protoc.zip | ||
# Install protoc-gen-go | ||
$(PROTOC_GEN_GO): | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
# Install protoc-gen-micro | ||
$(PROTOC_GEN_MICRO): | ||
go install micro.dev/v4/cmd/protoc-gen-micro@master | ||
` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
package template | ||
|
||
var ( | ||
Makefile = ` | ||
GOPATH:=$(shell go env GOPATH) | ||
.PHONY: init | ||
init: | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
go install micro.dev/v4/cmd/protoc-gen-micro@latest | ||
go install micro.dev/v4/cmd/protoc-gen-openapi@latest | ||
.PHONY: api | ||
api: | ||
protoc --openapi_out=. --proto_path=. proto/{{.Alias}}.proto | ||
Makefile = `GOOS := $(shell go env GOOS) | ||
GOARCH := $(shell go env GOARCH) | ||
GOBIN := $(shell go env GOPATH)/bin | ||
NAME := $(shell basename $(CURDIR)) | ||
ifeq ($(GOOS),windows) | ||
TARGET := $(NAME).exe | ||
else | ||
TARGET := $(NAME) | ||
endif | ||
PROTO_FILES := $(wildcard proto/*.proto) | ||
PROTO_GO := $(PROTO_FILES:%.proto=%.pb.go) | ||
PROTO_GO_MICRO := $(PROTO_FILES:%.proto=%.pb.micro.go) | ||
.DEFAULT_GOAL := $(TARGET) | ||
# Build binary | ||
$(TARGET): proto/$(NAME).pb.micro.go | ||
go build -o $(TARGET) *.go | ||
.PHONY: clean | ||
clean: | ||
rm -f $(TARGET) $(PROTO_GO) $(PROTO_GO_MICRO) | ||
include dep-install.mk | ||
.PHONY: proto | ||
proto: | ||
protoc --proto_path=. --micro_out=. --go_out=:. proto/{{.Alias}}.proto | ||
.PHONY: build | ||
build: | ||
go build -o {{.Alias}} *.go | ||
proto: proto/$(NAME).pb.micro.go | ||
%.pb.go %.pb.micro.go: | ||
protoc --proto_path=. --go_out=:. --micro_out=. $(*).proto | ||
.PHONY: test | ||
test: | ||
go test -v ./... -cover | ||
.PHONY: docker | ||
docker: | ||
docker build . -t {{.Alias}}:latest | ||
docker build . -t $(NAME):latest | ||
` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters