Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Tereshchenko committed Feb 11, 2024
1 parent 95eac1d commit 381e9a3
Show file tree
Hide file tree
Showing 20 changed files with 1,437 additions and 1 deletion.
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.20'
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.20'
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 @@
.idea
/bin/
.env
53 changes: 53 additions & 0 deletions .golangci.pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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
- exported method|type|function .* should have comment or be unexported
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
LOCAL_BIN:=$(CURDIR)/bin

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/golangci/golangci-lint/cmd/golangci-lint@v1.53.3

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-api:
mkdir -p pkg/user_v1
protoc --proto_path api/user_v1 \
--go_out=pkg/user_v1 --go_opt=paths=source_relative \
--plugin=protoc-gen-go=bin/protoc-gen-go \
--go-grpc_out=pkg/user_v1 --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=bin/protoc-gen-go-grpc \
api/user_v1/user.proto

lint:
GOBIN=$(LOCAL_BIN) ./bin/golangci-lint run ./... --config .golangci.pipeline.yaml
1 change: 0 additions & 1 deletion README.md

This file was deleted.

59 changes: 59 additions & 0 deletions api/user_v1/user.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
syntax = "proto3";

package user_v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

option go_package = "github.com/terdenan/msc_auth/pkg/user_v1;user_v1";

service UserV1 {
rpc Create(CreateRequest) returns (CreateResponse);
rpc Get(GetRequest) returns (GetResponse);
rpc Update(UpdateRequest) returns (google.protobuf.Empty);
rpc Delete(DeleteRequest) returns (google.protobuf.Empty);
}

enum Role {
user = 0;
admin = 1;
}

message CreateRequest {
string name = 1;
string email = 2;
string password = 3;
string password_confirm = 4;
Role role = 5;
}

message CreateResponse {
int64 id = 1;
}

message GetRequest {
int64 id = 1;
}

message GetResponse {
int64 id = 1;
string name = 2;
string email = 3;
Role role = 4;
google.protobuf.Timestamp created_at = 5;
google.protobuf.Timestamp updated_at = 6;
}

message UpdateRequest {
int64 id = 1;
google.protobuf.StringValue name = 2;
google.protobuf.StringValue email = 3;
oneof optional_role {
Role role = 4;
}
}

message DeleteRequest {
int64 id = 1;
}
21 changes: 21 additions & 0 deletions cmd/grpc_server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"context"
"log"

"github.com/terdenan/msc_auth/internal/app"
)

func main() {
ctx := context.Background()

a, err := app.NewApp(ctx)
if err != nil {
log.Fatalf("failed to init app: %s", err.Error())
}

if err := a.Run(); err != nil {
log.Fatalf("failed to run app: %s", err.Error())
}
}
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/terdenan/msc_auth

go 1.20

require (
github.com/brianvoe/gofakeit/v6 v6.28.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
34 changes: 34 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
15 changes: 15 additions & 0 deletions internal/api/user/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package user

import (
"context"

"github.com/brianvoe/gofakeit/v6"

desc "github.com/terdenan/msc_auth/pkg/user_v1"
)

func (s *UserServer) Create(_ context.Context, _ *desc.CreateRequest) (*desc.CreateResponse, error) {
return &desc.CreateResponse{
Id: gofakeit.Int64(),
}, nil
}
13 changes: 13 additions & 0 deletions internal/api/user/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package user

import (
"context"

"google.golang.org/protobuf/types/known/emptypb"

desc "github.com/terdenan/msc_auth/pkg/user_v1"
)

func (s *UserServer) Delete(_ context.Context, _ *desc.DeleteRequest) (*emptypb.Empty, error) {
return &emptypb.Empty{}, nil
}
21 changes: 21 additions & 0 deletions internal/api/user/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package user

import (
"context"

"github.com/brianvoe/gofakeit/v6"
"google.golang.org/protobuf/types/known/timestamppb"

desc "github.com/terdenan/msc_auth/pkg/user_v1"
)

func (s *UserServer) Get(_ context.Context, _ *desc.GetRequest) (*desc.GetResponse, error) {
return &desc.GetResponse{
Id: gofakeit.Int64(),
Name: gofakeit.Name(),
Email: gofakeit.Email(),
Role: desc.Role_user,
CreatedAt: timestamppb.New(gofakeit.Date()),
UpdatedAt: timestamppb.New(gofakeit.Date()),
}, nil
}
13 changes: 13 additions & 0 deletions internal/api/user/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package user

import (
desc "github.com/terdenan/msc_auth/pkg/user_v1"
)

type UserServer struct {
desc.UnimplementedUserV1Server
}

func NewUserServer() *UserServer {
return &UserServer{}
}
13 changes: 13 additions & 0 deletions internal/api/user/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package user

import (
"context"

"google.golang.org/protobuf/types/known/emptypb"

desc "github.com/terdenan/msc_auth/pkg/user_v1"
)

func (s *UserServer) Update(_ context.Context, _ *desc.UpdateRequest) (*emptypb.Empty, error) {
return &emptypb.Empty{}, nil
}
Loading

0 comments on commit 381e9a3

Please sign in to comment.