Skip to content

Commit

Permalink
repository created
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillmc committed Apr 17, 2024
0 parents commit a1f6b30
Show file tree
Hide file tree
Showing 91 changed files with 10,234 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Go

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.8'
cache-dependency-path: go.sum

- name: Build
run: go build -o ./bin/ -v ./...

- name: Test
run: go test -v ./...

linter:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21.8'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.53

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
args: --timeout=30m --config=./.golangci.pipeline.yaml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
/bin/
/vendor.protogen/
52 changes: 52 additions & 0 deletions .golangci.pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# More info on config here: https://golangci-lint.run/usage/configuration/#config-file
run:
concurrency: 8
timeout: 10m
issues-exit-code: 1
tests: true
skip-dirs:
- bin
- vendor
- var
- tmp
- .cache
skip-files:
- \.pb\.go$
- \.pb\.gw\.go$

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
govet:
check-shadowing: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2

linters:
disable-all: true
enable:
- errcheck
- goconst
- goimports
- gosec
- govet
- ineffassign
- megacheck
- revive
- typecheck
- unused

issues:
exclude-use-default: false
exclude:
# _ instead of err checks
- G104
- exported func .* returns unexported type .*, which can be annoying to use
- should have a package comment
- don't use an underscore in package name
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

99 changes: 99 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
include .env

LOCAL_BIN:=$(CURDIR)/bin

LOCAL_MIGRATION_DIR=$(MIGRATION_DIR)
LOCAL_MIGRATION_DSN="host=localhost port=$(PG_PORT) dbname=$(PG_DATABASE_NAME) user=$(PG_USER) password=$(PG_PASSWORD) sslmode=disable"

install-golangci-lint:
GOBIN=$(LOCAL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3

lint:
bin/golangci-lint run ./... --config .golangci.pipeline.yaml


install-deps:
GOBIN=$(LOCAL_BIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1
GOBIN=$(LOCAL_BIN) go install -mod=mod google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
GOBIN=$(LOCAL_BIN) go install github.com/pressly/goose/v3/cmd/goose@v3.14.0
GOBIN=$(LOCAL_BIN) go install github.com/envoyproxy/protoc-gen-validate@v0.10.1
GOBIN=$(LOCAL_BIN) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.15.2
GOBIN=$(LOCAL_BIN) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.15.2
GOBIN=$(LOCAL_BIN) go install github.com/rakyll/statik@v0.1.7

get-deps:
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc


generate:
mkdir -p pkg/swagger
make generate-user-api
make generate-auth-api
make generate-access-api
$(LOCAL_BIN)/statik -src=pkg/swagger/ -include='*.css,*.html,*.js,*.json,*.png'

generate-user-api:
mkdir -p pkg/user_v1
protoc --proto_path api/user_v1 --proto_path vendor.protogen \
--go_out=pkg/user_v1 --go_opt=paths=source_relative \
--plugin=protoc-gen-go=$(LOCAL_BIN)/protoc-gen-go \
--go-grpc_out=pkg/user_v1 --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=$(LOCAL_BIN)/protoc-gen-go-grpc \
--validate_out lang=go:pkg/user_v1 --validate_opt=paths=source_relative \
--plugin=protoc-gen-validate=$(LOCAL_BIN)/protoc-gen-validate \
--grpc-gateway_out=pkg/user_v1 --grpc-gateway_opt=paths=source_relative \
--plugin=protoc-gen-grpc-gateway=$(LOCAL_BIN)/protoc-gen-grpc-gateway \
--openapiv2_out=allow_merge=true,merge_file_name=api:pkg/swagger \
--plugin=protoc-gen-openapiv2=$(LOCAL_BIN)/protoc-gen-openapiv2 \
api/user_v1/user.proto

generate-auth-api:
mkdir -p pkg/auth_v1
protoc --proto_path api/auth_v1 \
--go_out=pkg/auth_v1 --go_opt=paths=source_relative \
--plugin=protoc-gen-go=$(LOCAL_BIN)/protoc-gen-go \
--go-grpc_out=pkg/auth_v1 --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=$(LOCAL_BIN)/protoc-gen-go-grpc \
api/auth_v1/auth.proto

generate-access-api:
mkdir -p pkg/access_v1
protoc --proto_path api/access_v1 \
--go_out=pkg/access_v1 --go_opt=paths=source_relative \
--plugin=protoc-gen-go=$(LOCAL_BIN)/protoc-gen-go \
--go-grpc_out=pkg/access_v1 --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=$(LOCAL_BIN)/protoc-gen-go-grpc \
api/access_v1/access.proto

local-migration-status:
$(LOCAL_BIN)/goose -dir ${LOCAL_MIGRATION_DIR} postgres ${LOCAL_MIGRATION_DSN} status -v

create-migration:
$(LOCAL_BIN)/goose -dir ${LOCAL_MIGRATION_DIR} create users_table sql

local-migration-up:
$(LOCAL_BIN)/goose -dir ${LOCAL_MIGRATION_DIR} postgres ${LOCAL_MIGRATION_DSN} up -v

local-migration-down:
$(LOCAL_BIN)/goose -dir ${LOCAL_MIGRATION_DIR} postgres ${LOCAL_MIGRATION_DSN} down -v

vendor-proto:
@if [ ! -d vendor.protogen/validate ]; then \
mkdir -p vendor.protogen/validate &&\
git clone https://github.com/envoyproxy/protoc-gen-validate vendor.protogen/protoc-gen-validate &&\
mv vendor.protogen/protoc-gen-validate/validate/*.proto vendor.protogen/validate &&\
rm -rf vendor.protogen/protoc-gen-validate ;\
fi
@if [ ! -d vendor.protogen/google ]; then \
git clone https://github.com/googleapis/googleapis vendor.protogen/googleapis &&\
mkdir -p vendor.protogen/google/ &&\
mv vendor.protogen/googleapis/google/api vendor.protogen/google &&\
rm -rf vendor.protogen/googleapis ;\
fi
@if [ ! -d vendor.protogen/protoc-gen-openapiv2 ]; then \
mkdir -p vendor.protogen/protoc-gen-openapiv2/options &&\
git clone https://github.com/grpc-ecosystem/grpc-gateway vendor.protogen/openapiv2 &&\
mv vendor.protogen/openapiv2/protoc-gen-openapiv2/options/*.proto vendor.protogen/protoc-gen-openapiv2/options &&\
rm -rf vendor.protogen/openapiv2 ;\
fi
15 changes: 15 additions & 0 deletions api/access_v1/access.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package access_v1;

import "google/protobuf/empty.proto";

option go_package = "github.com/kirillmc/trainings-auth/pkg/access_v1;access_v1";

service AccessV1{
rpc Check(CheckRequest) returns (google.protobuf.Empty);
}

message CheckRequest{
string endpoint_address = 1;
}
36 changes: 36 additions & 0 deletions api/auth_v1/auth.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax = "proto3";

package auth_v1;

option go_package = "github.com/kirillmc/trainings-auth/pkg/auth_v1;auth_v1";

service AuthV1{
rpc Login(LoginRequest) returns (LoginResponse);
rpc GetRefreshToken(GetRefreshTokenRequest) returns (GetRefreshTokenResponse);
rpc GetAccessToken(GetAccessTokenRequest) returns (GetAccessTokenResponse);
}

message LoginRequest{
string username = 1;
string password = 2;
}

message LoginResponse{
string refresh_token=1;
}

message GetRefreshTokenRequest{
string old_refresh_token=1;
}

message GetRefreshTokenResponse{
string refresh_token=1;
}

message GetAccessTokenRequest{
string refresh_token=1;
}

message GetAccessTokenResponse{
string access_token=1;
}

0 comments on commit a1f6b30

Please sign in to comment.