generated from victor-skurikhin/home_work
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from victor-skurikhin/issue-2
MVP
- Loading branch information
Showing
29 changed files
with
2,472 additions
and
387 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
include Makefile.env | ||
|
||
## run: Compile and run server | ||
run: go-compile start | ||
|
||
## start: Start in development mode. Auto-starts when code changes. | ||
start: start-etcd-proxy | ||
|
||
## stop: Stop development mode. GO_ETCD_PROXY | ||
stop: stop-etcd-proxy | ||
|
||
start-etcd-proxy: stop-etcd-proxy | ||
@echo " > $(PROJECTNAME) is available at $(HTTP_ADDRESS) and gRPC at $(GRPC_ADDRESS)" | ||
@-cd ./$(DIR_ETCD_PROXY) && (./etcd-proxy -h $(HTTP_ADDRESS) -g $(GRPC_ADDRESS) & echo $$! > $(PID_GO_ETCD_PROXY)) | ||
@cat $(PID_GO_ETCD_PROXY) | sed "/^/s/^/ \> PID: /" | ||
|
||
stop-etcd-proxy: | ||
@echo " > stop by $(PID_GO_ETCD_PROXY)" | ||
@-touch $(PID_GO_ETCD_PROXY) | ||
@-kill `cat $(PID_GO_ETCD_PROXY)` 2> /dev/null || true | ||
@-rm $(PID_GO_ETCD_PROXY) | ||
|
||
restart-etcd-proxy: stop-etcd-proxy start-etcd-proxy | ||
|
||
## build: Build and the binary compile server | ||
build: go-build-etcd-proxy | ||
|
||
## clean: Clean build files. Runs `go clean` internally. | ||
clean: | ||
@(MAKEFILE) go-clean | ||
|
||
go-compile: go-build-etcd-proxy | ||
|
||
go-build-etcd-proxy: | ||
@echo " > Building GO_ETCD_PROXY binary..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) cd ./$(DIR_ETCD_PROXY) && go build -o ./etcd-proxy $(GOFILES) | ||
|
||
go-generate: | ||
@echo " > Generating dependency files..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(generate) | ||
|
||
go-get: | ||
@echo " > Checking if there is any missing dependencies..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get $(get) | ||
|
||
.PHONY: go-update-deps | ||
go-update-deps: | ||
@echo ">> updating Go dependencies" | ||
@for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \ | ||
go get $$m; \ | ||
done | ||
go mod tidy | ||
ifneq (,$(wildcard vendor)) | ||
go mod vendor | ||
endif | ||
|
||
go-install: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install $(GOFILES) | ||
|
||
go-swag: | ||
swag init -g $(MAIN_GO) --output $(DOCS_DIR) | ||
sed -i 's/"localhost:8080",/env.GetConfig().Address(),/' $(DOCS_GO) | ||
goimports -w $(DOCS_GO) | ||
|
||
go-clean: | ||
@echo " > Cleaning build cache" | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean | ||
|
||
cert: | ||
@cd cert; openssl req -x509 -newkey rsa:1024 -days 365 -nodes -keyout ca-key.pem -out ca-cert.pem -subj "/C=RU/ST=Moscow/L=Moscow/O=Tech School/OU=Education/CN=localhost/[email protected]" | ||
@echo "CA's self-signed certificate" | ||
@cd cert; openssl x509 -in ca-cert.pem -noout -text | ||
@cd cert; openssl req -newkey rsa:1024 -nodes -keyout server-key.pem -out server-req.pem -subj "/C=RU/ST=Moscow/L=Moscow/O=Tech School/OU=Education/CN=localhost/[email protected]" | ||
@cd cert; openssl x509 -req -in server-req.pem -days 60 -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile server-ext.cnf | ||
@echo "Server's signed certificate" | ||
@cd cert; openssl x509 -in server-cert.pem -noout -text | ||
|
||
################## | ||
# Implicit targets | ||
################## | ||
|
||
# This rulle is used to generate the message source files based | ||
# on the *.proto files. | ||
%.pb.go: %.proto | ||
@protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./$< | ||
|
||
#################################### | ||
# Major source code-generate targets | ||
#################################### | ||
generate: $(PROTO_PB_GO) | ||
@echo " > Done generating source files based on *.proto and Mock files." | ||
|
||
test: | ||
@echo " > Test Iteration ..." | ||
go vet -vettool=$(which statictest) ./... | ||
cd cmd/etcd-proxy | ||
|
||
.PHONY: cert help | ||
all: help | ||
help: Makefile | ||
@echo | ||
@echo " Choose a command run in "$(PROJECTNAME)":" | ||
@echo | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo |
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,39 @@ | ||
|
||
PROJECTNAME=$(shell basename "$(PWD)") | ||
|
||
# Go related variables. | ||
GOBASE=$(shell pwd) | ||
GOPATH="$(GOBASE)/vendor:$(GOBASE)" | ||
DIR_ETCD_PROXY=cmd/etcd-proxy | ||
GOBIN=$(GOBASE)/$(CMD_FAVORITES) | ||
GOFILES=$(wildcard *.go) | ||
|
||
# Redirect error output to a file, so we can show it in development mode. | ||
STDERR=/tmp/.$(PROJECTNAME)-stderr.txt | ||
|
||
# PID file will keep the process id of the etcd-proxy | ||
PID_GO_ETCD_PROXY=/tmp/.$(PROJECTNAME)-etcd-proxy.pid | ||
|
||
RANDOM=$(shell date +%s) | ||
RND1=$(shell echo "("$RANDOM" % 1024) + 63490" | bc) | ||
RND2=$(shell echo "("$RND1" + 1" | bc) | ||
GRPC_ADDRESS=localhost:$(RND2) | ||
HTTP_ADDRESS=localhost:$(RND1) | ||
TEMP_FILE=$(shell mktemp) | ||
DOCS_DIR=./docs | ||
DOCS_GO=$(DOCS_DIR)/docs.go | ||
MAIN_GO=./$(CMD_FAVORITES)/main.go | ||
|
||
# Make is verbose in Linux. Make it silent. | ||
MAKEFLAGS += --silent | ||
|
||
# Define where the *.proto files are located. | ||
PROTO_DIR = ./proto | ||
|
||
# Find all the proto files. | ||
# Extend this for subfolders. | ||
PROTO_FILES = $(wildcard $(PROTO_DIR)/*.proto) | ||
|
||
# Convert the names of the proto files to the name of the | ||
# generated header files. | ||
PROTO_PB_GO := $(PROTO_FILES:%.proto=%.pb.go) |
5 changes: 5 additions & 0 deletions
5
cmd/etcd-client/etcd-client.yaml → cmd/etcd-proxy/etcd-client.yaml
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
File renamed without changes.
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
Oops, something went wrong.