Skip to content

Commit

Permalink
updates (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
vshiva committed Jun 29, 2020
1 parent 15a171b commit 4e55b6b
Show file tree
Hide file tree
Showing 39 changed files with 1,907 additions and 1,995 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ cd servicebuilder
git remote add upstream git@github.com:cnative/servicebuilder.git
git remote set-url --push upstream no_push

make install-deptools clean bulid
make install-deptools clean build
```
2 changes: 1 addition & 1 deletion cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ in this example 'accounts' is the service name`)

newCmd.Flags().StringP("description", "", "", "a short description of the service")
newCmd.Flags().StringP("image-name", "i", "", "container image name")
newCmd.Flags().StringP("protoc-version", "", "v3.7.0", "protocol buffer version to use")
newCmd.Flags().StringP("protoc-version", "", "3.12.3", "protocol buffer version to use")
newCmd.Flags().StringP("http-route-prefix", "", "/api/v1", "http route prefix")
newCmd.Flags().StringP("deployment-type", "", "k8s", "deployment artifact to generate. Possible values [helm, k8s]")
newCmd.Flags().StringP("domain-name", "", "localhost", "domain name")
Expand Down
2 changes: 2 additions & 0 deletions internal/iwrap/metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/iwrap/tracing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

711 changes: 290 additions & 421 deletions internal/templates/grpcwithgw/grpc_service_with_gw.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/templates/grpcwithgw/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
log "github.com/sirupsen/logrus"
)

//go:generate go-bindata -o ./grpc_service_with_gw.go -pkg grpcwithgw -nomemcopy -nometadata -prefix tmplt tmplt/...
//go:generate go-bindata -o ./grpc_service_with_gw.go -pkg grpcwithgw -nomemcopy -prefix tmplt tmplt/...

type (
grpcServiceTemplateProvider struct {
Expand Down
60 changes: 39 additions & 21 deletions internal/templates/grpcwithgw/tmplt/Makefile.tmplt
Original file line number Diff line number Diff line change
@@ -1,52 +1,70 @@
export VERSION ?= dev
export VERSION ?= ${GIT_COMMIT}
export GIT_COMMIT ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo unknown)
export LD_FLAGS = -X "main.gitCommit=$(GIT_COMMIT)" -X "main.version=$(VERSION)"

export GOBIN = $(abspath .)/.tools/bin
export PATH := $(GOBIN):$(PATH)
export GO111MODULE=on
export PATH := $(GOBIN):$(abspath .)/bin:$(PATH)
export CGO_ENABLED=0

export V = 0
export Q = $(if $(filter 1,$V),,@)
export M = $(shell printf "\033[34;1m▶\033[0m")

export CC = go build -ldflags '$(LD_FLAGS)'

.PHONY: help
help:
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'

.PHONY: deps
deps:
go get -d -v ./...
$(info $(M) fetching deps …)
$Q go get -d -v ./...
$Q go mod tidy

.PHONY: install-deptools
install-deptools: deps ## install dependent go tools
$Q sh ./scripts/download_protoc.sh && \
go install golang.org/x/lint/golint/... && \
go install github.com/cnative/servicebuilder && \
go install github.com/golang/protobuf/protoc-gen-go && \
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway && \
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
; $(info $(M) installing protoc, golint, protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger)
$(info $(M) installing necessary tools …)
$Q sh ./scripts/install_tools_check.sh

.PHONY: gen
gen:
$Q go generate ./pkg/api ./internal/state ; $(info $(M) generating grpc api server handler, gateway, swagger and metrics & trace store …)

gen:
$Q go generate ./pkg/api ./pkg/state ; $(info $(M) generating grpc api server handler, gateway, swagger and metrics & trace store …)
.PHONY: fmt
fmt: ## run go fmt on all source files
$(info $(M) formatting …)
$Q goimports -w -local {{ .ModuleName }} ./cmd ./pkg ./internal

fmt: ; $(info $(M) formatting …) @ ## run go fmt on all source files
@go fmt ./...
.PHONY: vet
vet: ## run go vet on all source files
$(info $(M) vetting …)
$Q go vet ./...

vet: ; $(info $(M) vetting …) @ ## run go vet on all source files
@go vet ./...
.PHONY: lint
lint: ## run golint
$(info $(M) linting …)
$Q ./.tools/bin/golangci-lint --verbose run ./... --timeout=5m --modules-download-mode=vendor

lint: ; $(info $(M) linting …) @ ## run golint
@golint ./...
.PHONY: build
build: gen fmt vet ## build service
$(info $(M) building executable …)
$Q $(CC) -o bin/{{ .Name }} ./cmd

build: gen fmt vet lint ## build service
$Q go build -ldflags '$(LD_FLAGS)' -o bin/{{ .Name }} ./ ; $(info $(M) building executable …)
.PHONY: test
test: ## run go tests with race detector
$(info $(M) testing …)
$Q go test $(GO_TEST_FLAGS) $(shell go list ./...)

.PHONY: build-image
build-image: ## build container image using docker
$Q docker build --build-arg 'LD_FLAGS=$(LD_FLAGS)' -t {{ .ImageName }}:$(VERSION) . ; $(info $(M) building docker image …)

.PHONY: push-image
push-image: build-image ## build and publish container image using docker
$Q docker push {{ .ImageName }}:$(VERSION) ; $(info $(M) pushing docker image `…)

.PHONY: clean
clean: ; $(info $(M) cleaning …) @ ## cleanup everything
@rm -rf bin
@rm -rf test/tests.* test/coverage.*
6 changes: 3 additions & 3 deletions internal/templates/grpcwithgw/tmplt/README.md.tmplt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# {{ .Name }}

{{ .Name }} description
{{ .Description }}

{{ .Name }} is a service in based on [`servicebuilder`](https://github.com/cnative/servicebuilder/) that

Expand Down Expand Up @@ -50,9 +50,9 @@
- Add your project specific flags / command line arguments in `cmd/{{ .Name }}/server.go`
- Define your protobuf messaages and grpc services in `{{ .Name }}.proto` file.
- Run `make gen`. This will generate requred structs and service methods from the proto file.
- Implement the business logic for your service methods in `pkg/server` package
- Implement the business logic for your service methods
- Run `make build`. This will build a binary `{{ .Name }}` under `./bin` folder
- Often times the service needs to interact with some store. For example a sql store or a nosql store like mongo or bolddb. A Store interface defines all the persistence/repo methods and you there could be multiple implementations for the persistence layer. The store interface methods and various implmentations are defined in `pkg/state` package.
- Often times the service needs to interact with some store. For example a sql store or a nosql store like mongo or bolddb. A Store interface defines all the persistence/repo methods and you there could be multiple implementations for the persistence layer. The store interface methods and various implmentations are defined in `internal/state` package.

### Running

Expand Down
Loading

0 comments on commit 4e55b6b

Please sign in to comment.