1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-10 00:29:01 +02:00
kratos/examples/blog/Makefile
opensite 44c2641da2
example/blog: add the usage example of validate in proto file for blog (#942)
* example/blog: add the usage example of validate in proto file for blog

* example/blog: use validator middleware instead of calling validate in every method that needs to be validated
2021-05-23 13:03:10 +08:00

66 lines
1.7 KiB
Makefile

GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
PROTO_FILES=$(shell find . -name *.proto)
KRATOS_VERSION=$(shell go mod graph |grep go-kratos/kratos/v2 |head -n 1 |awk -F '@' '{print $$2}')
KRATOS=$(GOPATH)/pkg/mod/github.com/go-kratos/kratos/v2@$(KRATOS_VERSION)
.PHONY: init
init:
go get -u github.com/go-kratos/kratos/cmd/kratos/v2
go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2
go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
.PHONY: proto
# generate proto
proto:
protoc --proto_path=. \
--proto_path=$(KRATOS)/api \
--proto_path=$(KRATOS)/third_party \
--proto_path=$(GOPATH)/src \
--go_out=paths=source_relative:. \
--go-grpc_out=paths=source_relative:. \
--go-http_out=paths=source_relative:. \
--go-errors_out=paths=source_relative:. $(PROTO_FILES)
.PHONY: validate
# generate pb validate for proto
validate:
protoc --proto_path=. \
--proto_path=$(KRATOS)/third_party \
--go_out=paths=source_relative:. \
--validate_out="lang=go:." \
$(PROTO_FILES)
.PHONY: swagger
# generate swagger file
swagger:
protoc --proto_path=. \
--proto_path=$(KRATOS)/third_party \
--openapiv2_out . \
--openapiv2_opt logtostderr=true \
$(PROTO_FILES)
.PHONY: run
run:
cd cmd/blog/ && go run .
.PHONY: ent
ent:
cd internal/data/ && ent generate ./ent/schema
.PHONY: generate
generate:
go generate ./...
.PHONY: build
build:
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
.PHONY: test
test:
go test -v ./... -cover