-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add example * add readme * Add user v1 service reg and tests * add user api v2 reg and tests * fix docs
- Loading branch information
Showing
76 changed files
with
6,112 additions
and
105 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
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,2 @@ | ||
.vscode | ||
coverage.txt |
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,21 @@ | ||
# Build stage | ||
FROM golang AS build-env | ||
ADD . /src | ||
ENV CGO_ENABLED=0 | ||
RUN apt-get update -y && \ | ||
# Build binary | ||
cd /src && \ | ||
go build -o /app/main && \ | ||
# Get gRPC health probe | ||
wget https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.5/grpc_health_probe-linux-amd64 -O /app/grpc_health_probe && \ | ||
chmod +x /app/grpc_health_probe | ||
|
||
# Production stage | ||
FROM alpine:3 | ||
COPY --from=build-env /app / | ||
|
||
# Create folder for logs | ||
RUN mkdir /var/log/archaeropteryx | ||
|
||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD /grpc_health_probe -addr 0.0.0.0:8080 || exit 1 | ||
ENTRYPOINT ["/main"] |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Ivan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,66 @@ | ||
help: | ||
@echo "Makefile for the archaeopteryx example." | ||
@echo "Available targets:" | ||
@echo " help - print help information" | ||
@echo " install - install required dependecies for the project" | ||
@echo " generate - generate proto files" | ||
@echo " lint - run linter" | ||
@echo " test - run unit tests" | ||
@echo " build - build application binary" | ||
@echo " run - run application" | ||
@echo " build_docker - build application docker image" | ||
@echo " run_docker - run application in docker" | ||
|
||
install: | ||
@echo "Install Buf generators" | ||
go get \ | ||
google.golang.org/protobuf/cmd/protoc-gen-go \ | ||
google.golang.org/grpc/cmd/protoc-gen-go-grpc \ | ||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ | ||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 | ||
go install \ | ||
google.golang.org/protobuf/cmd/protoc-gen-go \ | ||
google.golang.org/grpc/cmd/protoc-gen-go-grpc \ | ||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ | ||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 | ||
curl -sSL \ | ||
"https://github.com/bufbuild/buf/releases/download/v0.48.2/buf-$(shell uname -s)-$(shell uname -m)" \ | ||
-o "$(shell go env GOPATH)/bin/buf" && \ | ||
chmod +x "$(shell go env GOPATH)/bin/buf" | ||
|
||
echo "Install linter" | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.42.0 | ||
|
||
generate: | ||
@echo "Generate proto" | ||
buf mod update | ||
buf generate | ||
|
||
lint: | ||
@echo "Run linter" | ||
# Lint proto | ||
buf lint | ||
# Lint golang | ||
golangci-lint run | ||
|
||
test: | ||
@echo "Run unit tests" | ||
go test -v ./... -coverprofile coverage.txt -covermode atomic | ||
@echo "Code coverage" | ||
go tool cover -func coverage.txt | ||
|
||
build: | ||
@echo "Build app binary" | ||
go build | ||
|
||
run: | ||
@echo "Run app" | ||
go run . | ||
|
||
build_docker: | ||
@echo "Build docker image" | ||
docker build . --file Dockerfile --tag archaeopteryx_example | ||
|
||
run_docker: | ||
@echo "Run app in docker" | ||
docker run -p 8080:8080 -p 8090:8090 -e LOG_LEVEL=trace archaeopteryx_example |
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,73 @@ | ||
# archaeopteryx_example | ||
|
||
This project is a example of usage `archaeopteryx` for creating microservice on Golang with all required dependencies | ||
|
||
## Install dependencies | ||
|
||
```sh | ||
make install | ||
``` | ||
|
||
## Generate protobuf & docs | ||
|
||
```sh | ||
make generate | ||
``` | ||
|
||
## Presequinces | ||
|
||
`archaeopteryx` requires folder for log files. | ||
To create it run: | ||
```sh | ||
sudo mkdir /var/log/archaeopteryx | ||
sudo chown $USER /var/log/archaeopteryx | ||
``` | ||
|
||
## Build | ||
|
||
### Docker | ||
|
||
To build docker image use: | ||
```sh | ||
make build_docker | ||
``` | ||
|
||
## Run | ||
|
||
### Binary | ||
|
||
To run server use: | ||
```sh | ||
make run | ||
``` | ||
|
||
### Docker | ||
|
||
To run server in docker use: | ||
```sh | ||
make run_docker | ||
``` | ||
|
||
## Test | ||
|
||
### Unit test | ||
|
||
For unit tests use: | ||
```sh | ||
make test | ||
``` | ||
|
||
### Lint | ||
|
||
For lint use: | ||
```sh | ||
make lint | ||
``` | ||
|
||
### gRPC | ||
|
||
For testing gRPC API use [Kreya](https://kreya.app/) | ||
|
||
Folder `kreya` contains Kreya project for working with the project. | ||
|
||
Also `archaeopteryx` is compatible with [gRPC reflection](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) |
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,14 @@ | ||
version: v1beta1 | ||
plugins: | ||
- name: go | ||
out: proto/gen | ||
opt: paths=source_relative | ||
- name: go-grpc | ||
out: proto/gen | ||
opt: paths=source_relative | ||
- name: grpc-gateway | ||
out: proto/gen | ||
opt: paths=source_relative | ||
# Swagger docs | ||
- name: openapiv2 | ||
out: docs/swagger |
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,2 @@ | ||
# Generated by buf. DO NOT EDIT. | ||
version: v1 |
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,9 @@ | ||
version: v1beta1 | ||
name: buf.build/iakrevetkho/archaeopteryx_example | ||
build: | ||
roots: | ||
- proto | ||
lint: | ||
ignore: | ||
- health |
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,8 @@ | ||
version: 0.0.1 | ||
log: | ||
level: trace | ||
filename: /var/log/archaeopteryx/archaeopteryx.log | ||
maxSizeInMb: 20 | ||
maxAgeInDays: 30 | ||
maxBackups: 30 | ||
compress: true |
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,8 @@ | ||
package docs | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed swagger/* | ||
var Swagger embed.FS |
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,46 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "google/api/annotations.proto", | ||
"version": "version not set" | ||
}, | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"paths": {}, | ||
"definitions": { | ||
"protobufAny": { | ||
"type": "object", | ||
"properties": { | ||
"typeUrl": { | ||
"type": "string" | ||
}, | ||
"value": { | ||
"type": "string", | ||
"format": "byte" | ||
} | ||
} | ||
}, | ||
"rpcStatus": { | ||
"type": "object", | ||
"properties": { | ||
"code": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"message": { | ||
"type": "string" | ||
}, | ||
"details": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/protobufAny" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.