From 497618899369935f0deead481ec395b79661d8b2 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 23 Nov 2020 15:22:13 +0300
Subject: [PATCH 01/20] HW14 Completed

---
 hw12_13_14_15_calendar/Makefile               |  38 ++-
 .../api/private/grpcserver.proto              |  29 ++
 .../public}/google/api/annotations.proto      |   0
 .../public}/google/api/http.proto             |   0
 .../public}/google/api/httpbody.proto         |   0
 .../public}/grpcserver.proto                  |   4 +-
 .../cicd/docker-compose.yml                   |  17 +
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  34 +-
 hw12_13_14_15_calendar/cmd/scheduler/main.go  |  42 +++
 hw12_13_14_15_calendar/cmd/sender/main.go     |  42 +++
 .../configs/{config.toml => calendar.conf}    |   6 +-
 hw12_13_14_15_calendar/configs/scheduler.conf |  16 +
 hw12_13_14_15_calendar/configs/sender.conf    |  12 +
 .../deployments/docker-compose.yaml           |   1 -
 hw12_13_14_15_calendar/go.mod                 |  11 +-
 hw12_13_14_15_calendar/go.sum                 |  99 +-----
 .../internal/api/private/converters.go        |  22 ++
 .../internal/api/private/grpcclient.go        |  16 +
 .../internal/api/private/grpcserver.pb.go     | 314 ++++++++++++++++++
 .../internal/api/private/handlers.go          |  31 ++
 .../internal/api/private/handlers_test.go     |  84 +++++
 .../internal/api/private/server.go            |  36 ++
 .../{app/app.go => calendar/app_calendar.go}  |  16 +-
 .../internal/config/config.go                 |  51 ---
 .../internal/sender/app_sender.go             |  65 ++++
 .../internal/sheduler/app_scheduler.go        |  58 ++++
 .../internal/sheduler/scheduler.go            |  60 ++++
 .../migrations/20200924000000_init.sql        |   3 +-
 .../api/public}/converters.go                 |   4 +-
 .../api/public}/grpcserver.pb.go              | 131 ++++----
 .../api/public}/grpcserver.pb.gw.go           |   4 +-
 .../grpcserver => pkg/api/public}/handlers.go |   8 +-
 .../api/public}/handlers_test.go              |  25 +-
 .../grpcserver => pkg/api/public}/server.go   |  12 +-
 hw12_13_14_15_calendar/pkg/config/config.go   |  22 ++
 .../{internal => pkg}/config/config_test.go   |  13 +-
 hw12_13_14_15_calendar/pkg/config/types.go    |  50 +++
 .../{internal => pkg}/logger/logger.go        |  17 +-
 .../{internal => pkg}/logger/logger_test.go   |  19 +-
 hw12_13_14_15_calendar/pkg/rabbit/consumer.go |  52 +++
 hw12_13_14_15_calendar/pkg/rabbit/producer.go |  27 ++
 hw12_13_14_15_calendar/pkg/rabbit/rabbit.go   |  84 +++++
 .../{internal => pkg}/storage/event/event.go  |   1 +
 .../storage/memory/memory.go                  |  23 +-
 .../storage/memory/memory_test.go             |   2 +-
 .../{internal => pkg}/storage/sql/sql.go      |  44 ++-
 .../{internal => pkg}/storage/store.go        |   8 +-
 47 files changed, 1347 insertions(+), 306 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/api/private/grpcserver.proto
 rename hw12_13_14_15_calendar/{grpcserver => api/public}/google/api/annotations.proto (100%)
 rename hw12_13_14_15_calendar/{grpcserver => api/public}/google/api/http.proto (100%)
 rename hw12_13_14_15_calendar/{grpcserver => api/public}/google/api/httpbody.proto (100%)
 rename hw12_13_14_15_calendar/{grpcserver => api/public}/grpcserver.proto (97%)
 create mode 100644 hw12_13_14_15_calendar/cicd/docker-compose.yml
 create mode 100644 hw12_13_14_15_calendar/cmd/scheduler/main.go
 create mode 100644 hw12_13_14_15_calendar/cmd/sender/main.go
 rename hw12_13_14_15_calendar/configs/{config.toml => calendar.conf} (74%)
 create mode 100644 hw12_13_14_15_calendar/configs/scheduler.conf
 create mode 100644 hw12_13_14_15_calendar/configs/sender.conf
 delete mode 100644 hw12_13_14_15_calendar/deployments/docker-compose.yaml
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/converters.go
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/grpcclient.go
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/handlers.go
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/handlers_test.go
 create mode 100644 hw12_13_14_15_calendar/internal/api/private/server.go
 rename hw12_13_14_15_calendar/internal/{app/app.go => calendar/app_calendar.go} (69%)
 delete mode 100644 hw12_13_14_15_calendar/internal/config/config.go
 create mode 100644 hw12_13_14_15_calendar/internal/sender/app_sender.go
 create mode 100644 hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
 create mode 100644 hw12_13_14_15_calendar/internal/sheduler/scheduler.go
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/converters.go (94%)
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/grpcserver.pb.go (82%)
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/grpcserver.pb.gw.go (99%)
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/handlers.go (95%)
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/handlers_test.go (84%)
 rename hw12_13_14_15_calendar/{internal/grpcserver => pkg/api/public}/server.go (71%)
 create mode 100644 hw12_13_14_15_calendar/pkg/config/config.go
 rename hw12_13_14_15_calendar/{internal => pkg}/config/config_test.go (81%)
 create mode 100644 hw12_13_14_15_calendar/pkg/config/types.go
 rename hw12_13_14_15_calendar/{internal => pkg}/logger/logger.go (80%)
 rename hw12_13_14_15_calendar/{internal => pkg}/logger/logger_test.go (63%)
 create mode 100644 hw12_13_14_15_calendar/pkg/rabbit/consumer.go
 create mode 100644 hw12_13_14_15_calendar/pkg/rabbit/producer.go
 create mode 100644 hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
 rename hw12_13_14_15_calendar/{internal => pkg}/storage/event/event.go (92%)
 rename hw12_13_14_15_calendar/{internal => pkg}/storage/memory/memory.go (78%)
 rename hw12_13_14_15_calendar/{internal => pkg}/storage/memory/memory_test.go (95%)
 rename hw12_13_14_15_calendar/{internal => pkg}/storage/sql/sql.go (78%)
 rename hw12_13_14_15_calendar/{internal => pkg}/storage/store.go (80%)

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 29bfcd5..08daa51 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -1,22 +1,48 @@
 cdir = $(shell pwd)
 
-build:
+build-all:
 	go build -o ./bin/calendar ./cmd/calendar/main.go
+	go build -o ./bin/scheduler ./cmd/scheduler/main.go
+	go build -o ./bin/sender ./cmd/sender/main.go
 
-run:
-	go run ./cmd/calendar/main.go -config ./configs/config.toml
+start: build-all rabbit-start calendar-start scheduler-start sender-start
+
+stop: scheduler-stop sender-stop calendar-stop rabbit-stop
 
 test:
-	go test -race ./internal/...
+	go test -race ./internal/... ./pkg/... --tags calendar
 
 lint: install-lint-deps
-	golangci-lint run .cmd/... ./internal/...
+	golangci-lint run .cmd/... ./internal/...  ./pkg/...
 
 install-lint-deps:
 	(which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.30.0
 
 generate:
-	protoc  -I ./grpcserver  --go_out=plugins=grpc:./internal/grpcserver --grpc-gateway_out=logtostderr=true:./internal/grpcserver ./grpcserver/grpcserver.proto
+	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public --grpc-gateway_out=logtostderr=true:./pkg/api/public ./api/public/grpcserver.proto
+	protoc  -I ./api/private  --go_out=plugins=grpc:./internal/api/private ./api/private/grpcserver.proto
+
+rabbit-start:
+	sudo -S docker-compose -f ./cicd/docker-compose.yml up --build -d
+rabbit-stop:
+	sudo -S docker-compose -f ./cicd/docker-compose.yml down
+
+calendar-start:
+	nohup  ./bin/calendar -config ./configs/calendar.conf > /dev/null 2>&1 &
+calendar-stop:
+	kill -9 `pgrep calendar`
+
+scheduler-start:
+	nohup  ./bin/scheduler -config ./configs/scheduler.conf > /dev/null 2>&1 &
+scheduler-stop:
+	kill -9 `pgrep scheduler`
+
+sender-start:
+	nohup  ./bin/sender -config ./configs/sender.conf > /dev/null 2>&1 &
+sender-stop:
+	kill -9 `pgrep sender`
+
+
 
 
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/api/private/grpcserver.proto b/hw12_13_14_15_calendar/api/private/grpcserver.proto
new file mode 100644
index 0000000..8db4a9e
--- /dev/null
+++ b/hw12_13_14_15_calendar/api/private/grpcserver.proto
@@ -0,0 +1,29 @@
+syntax = "proto3";
+
+package private;
+
+option go_package = "private";
+
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/empty.proto";
+
+
+service grpc {
+  rpc GetNotifications(google.protobuf.Empty) returns (GetRsp) {}
+  rpc SetNotified(SetReq) returns (google.protobuf.Empty) {}
+}
+
+message GetRsp {
+  repeated Event Events = 1;
+}
+
+message SetReq {
+  int64 ID  = 1;
+}
+
+message Event {
+  int64 ID  = 1;
+  string Title = 2;
+  google.protobuf.Timestamp Date = 3;
+  int64 UserID = 4;
+}
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/grpcserver/google/api/annotations.proto b/hw12_13_14_15_calendar/api/public/google/api/annotations.proto
similarity index 100%
rename from hw12_13_14_15_calendar/grpcserver/google/api/annotations.proto
rename to hw12_13_14_15_calendar/api/public/google/api/annotations.proto
diff --git a/hw12_13_14_15_calendar/grpcserver/google/api/http.proto b/hw12_13_14_15_calendar/api/public/google/api/http.proto
similarity index 100%
rename from hw12_13_14_15_calendar/grpcserver/google/api/http.proto
rename to hw12_13_14_15_calendar/api/public/google/api/http.proto
diff --git a/hw12_13_14_15_calendar/grpcserver/google/api/httpbody.proto b/hw12_13_14_15_calendar/api/public/google/api/httpbody.proto
similarity index 100%
rename from hw12_13_14_15_calendar/grpcserver/google/api/httpbody.proto
rename to hw12_13_14_15_calendar/api/public/google/api/httpbody.proto
diff --git a/hw12_13_14_15_calendar/grpcserver/grpcserver.proto b/hw12_13_14_15_calendar/api/public/grpcserver.proto
similarity index 97%
rename from hw12_13_14_15_calendar/grpcserver/grpcserver.proto
rename to hw12_13_14_15_calendar/api/public/grpcserver.proto
index e37a601..5b0c4dd 100644
--- a/hw12_13_14_15_calendar/grpcserver/grpcserver.proto
+++ b/hw12_13_14_15_calendar/api/public/grpcserver.proto
@@ -1,8 +1,8 @@
 syntax = "proto3";
 
-package grpcserver;
+package public;
 
-option go_package = "grpcserver";
+option go_package = "public";
 
 import "google/protobuf/timestamp.proto";
 import "google/protobuf/duration.proto";
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
new file mode 100644
index 0000000..beb06ef
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/docker-compose.yml
@@ -0,0 +1,17 @@
+version: '2.0'
+services:
+  rabbitmq:
+    image: rabbitmq:3-management-alpine
+    hostname: "rabbitmq"
+    container_name: rabbitmq
+    environment:
+      RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
+      RABBITMQ_DEFAULT_USER: "rabbit"
+      RABBITMQ_DEFAULT_PASS: "rabbit"
+      RABBITMQ_DEFAULT_VHOST: "/"
+    ports:
+      - "5672:5672"
+      - "15672:15672"
+    expose:
+      - 5672
+      - 15672
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index 1a4ffe1..182c864 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"flag"
 	"github.com/grpc-ecosystem/grpc-gateway/runtime"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
 	"google.golang.org/grpc"
 	oslog "log"
 	"net"
@@ -13,26 +14,27 @@ import (
 	"syscall"
 
 	_ "github.com/go-sql-driver/mysql"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/grpcserver"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
-	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
 )
 
 var configFile string
 
 func init() {
-	flag.StringVar(&configFile, "config", "/etc/calendar/config.toml", "Path to configuration file")
+	flag.StringVar(&configFile, "config", "/etc/calendar.conf", "Path to configuration file")
 	flag.Parse()
 }
 
 func main() {
-	conf, err := config.NewConfig(configFile)
+	var conf config.Calendar
+	err := config.New(configFile, &conf)
 	if err != nil {
 		oslog.Fatal("не удалось открыть файл конфигурации:", err.Error())
 	}
-	log, err := logger.New(conf)
+	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
 		oslog.Fatal("не удалось запустить логер:", err.Error())
 	}
@@ -46,9 +48,9 @@ func main() {
 	}
 	st := store.NewStore(storeConf)
 
-	calendar := app.New(log, st)
+	calendar := calendar.New(log, st)
 
-	serverGRPC := grpcserver.New(calendar)
+	serverGRPC := public.New(calendar)
 	go func() {
 		if err := serverGRPC.Start(conf); err != nil {
 			log.Errorf("failed to start grpc server: " + err.Error())
@@ -56,6 +58,14 @@ func main() {
 		}
 	}()
 
+	serverAPI := private.New(calendar)
+	go func() {
+		if err := serverAPI.Start(private.Config(conf.API)); err != nil {
+			log.Errorf("failed to start API server: " + err.Error())
+			os.Exit(1)
+		}
+	}()
+
 	grpcDiler, err := grpc.Dial(net.JoinHostPort(conf.HTTP.Address, conf.HTTP.Port), grpc.WithInsecure())
 	if err != nil {
 		log.Errorf("can't dial grpc server: " + err.Error())
@@ -65,7 +75,7 @@ func main() {
 
 	grpcGwRouter := runtime.NewServeMux()
 
-	if err = grpcserver.RegisterGrpcHandler(context.Background(), grpcGwRouter, grpcDiler); err != nil {
+	if err = public.RegisterGrpcHandler(context.Background(), grpcGwRouter, grpcDiler); err != nil {
 		log.Errorf("can't register handlers for grpc-gateway: " + err.Error())
 		os.Exit(1)
 	}
@@ -81,7 +91,7 @@ func main() {
 	}()
 
 	signals := make(chan os.Signal, 1)
-	signal.Notify(signals,syscall.SIGINT)
+	signal.Notify(signals, syscall.SIGINT)
 	<-signals
 	signal.Stop(signals)
 	serverGRPC.Stop()
diff --git a/hw12_13_14_15_calendar/cmd/scheduler/main.go b/hw12_13_14_15_calendar/cmd/scheduler/main.go
new file mode 100644
index 0000000..5793fc3
--- /dev/null
+++ b/hw12_13_14_15_calendar/cmd/scheduler/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+	"context"
+	"flag"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sheduler"
+	"log"
+	"os"
+	"os/signal"
+	"syscall"
+
+	_ "github.com/go-sql-driver/mysql"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+)
+
+var configFile string
+
+func init() {
+	flag.StringVar(&configFile, "config", "/etc/scheduler.conf", "Path to configuration file")
+	flag.Parse()
+}
+
+func main() {
+	var conf sheduler.Config
+	err := config.New(configFile, &conf)
+	if err != nil {
+		log.Fatal("не удалось открыть файл конфигурации:", err.Error())
+	}
+	app := sheduler.New(conf)
+
+	ctx, cancel := context.WithCancel(context.Background())
+	if err = app.Start(ctx); err != nil {
+		app.Logger.Errorf("failed to start scheduler: ", err.Error())
+		os.Exit(1)
+	}
+
+	signals := make(chan os.Signal, 1)
+	signal.Notify(signals, syscall.SIGINT)
+	<-signals
+	signal.Stop(signals)
+	app.Stop(cancel)
+}
diff --git a/hw12_13_14_15_calendar/cmd/sender/main.go b/hw12_13_14_15_calendar/cmd/sender/main.go
new file mode 100644
index 0000000..ede4a82
--- /dev/null
+++ b/hw12_13_14_15_calendar/cmd/sender/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+	"context"
+	"flag"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sender"
+	"log"
+	"os"
+	"os/signal"
+	"syscall"
+
+	_ "github.com/go-sql-driver/mysql"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+)
+
+var configFile string
+
+func init() {
+	flag.StringVar(&configFile, "config", "/etc/sender.conf", "Path to configuration file")
+	flag.Parse()
+}
+
+func main() {
+	var conf sender.Config
+	err := config.New(configFile, &conf)
+	if err != nil {
+		log.Fatal("не удалось открыть файл конфигурации:", err.Error())
+	}
+	app := sender.New(conf)
+
+	ctx, cancel := context.WithCancel(context.Background())
+	if err = app.Start(ctx); err != nil {
+		app.Logger.Errorf("failed to start sender: ", err.Error())
+		os.Exit(1)
+	}
+
+	signals := make(chan os.Signal, 1)
+	signal.Notify(signals, syscall.SIGINT)
+	<-signals
+	signal.Stop(signals)
+	app.Stop(cancel)
+}
diff --git a/hw12_13_14_15_calendar/configs/config.toml b/hw12_13_14_15_calendar/configs/calendar.conf
similarity index 74%
rename from hw12_13_14_15_calendar/configs/config.toml
rename to hw12_13_14_15_calendar/configs/calendar.conf
index 4e7bb55..e787d79 100644
--- a/hw12_13_14_15_calendar/configs/config.toml
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -6,12 +6,16 @@ Port = "50051"
 Address = "localhost"
 Port = "50052"
 
+[API]
+Address = "localhost"
+Port = "50053"
+
 [Logger]
 File = "./calendar.log"
 Level = "INFO"
 
 [Storage]
-inMemory = false
+inMemory = true
 SQLHost = "localhost"
 SQLPort = "5432"
 SQLDbase = "calendar"
diff --git a/hw12_13_14_15_calendar/configs/scheduler.conf b/hw12_13_14_15_calendar/configs/scheduler.conf
new file mode 100644
index 0000000..2ea7915
--- /dev/null
+++ b/hw12_13_14_15_calendar/configs/scheduler.conf
@@ -0,0 +1,16 @@
+[Rabbitmq]
+Address = "localhost"
+Port = "5672"
+Login = "rabbit"
+Pass = "rabbit"
+Exchange = "calendar"
+Queue = "notifications"
+Key = "events"
+
+[Logger]
+File = "./calendar.log"
+Level = "INFO"
+
+[API]
+Address = "localhost"
+Port = "50053"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/configs/sender.conf b/hw12_13_14_15_calendar/configs/sender.conf
new file mode 100644
index 0000000..cbfd27d
--- /dev/null
+++ b/hw12_13_14_15_calendar/configs/sender.conf
@@ -0,0 +1,12 @@
+[Rabbitmq]
+Address = "localhost"
+Port = "5672"
+Login = "rabbit"
+Pass = "rabbit"
+Exchange = "calendar"
+Queue = "notifications"
+Key = "events"
+
+[Logger]
+File = "./calendar.log"
+Level = "INFO"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/deployments/docker-compose.yaml b/hw12_13_14_15_calendar/deployments/docker-compose.yaml
deleted file mode 100644
index 5db6fe9..0000000
--- a/hw12_13_14_15_calendar/deployments/docker-compose.yaml
+++ /dev/null
@@ -1 +0,0 @@
-version: "3"
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index 3a4d9fe..aa61bd3 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -5,18 +5,23 @@ go 1.14
 require (
 	github.com/BurntSushi/toml v0.3.1
 	github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec
-	github.com/daixiang0/gci v0.2.4 // indirect
-	github.com/dmitryt/otus-golang-hw/hw12_13_14_15_calendar v0.0.0-20200916093948-5ca8860569b6
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/golang/protobuf v1.4.2
 	github.com/grpc-ecosystem/grpc-gateway v1.15.0
-	github.com/rs/zerolog v1.20.0
+	github.com/kr/text v0.2.0 // indirect
+	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
+	github.com/pkg/errors v0.9.1 // indirect
+	github.com/sirupsen/logrus v1.4.2 // indirect
+	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
 	go.uber.org/zap v1.15.0 // indirect
 	golang.org/x/net v0.0.0-20200625001655-4c5254603344
+	golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
+	golang.org/x/text v0.3.3 // indirect
 	golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 // indirect
 	google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70
 	google.golang.org/grpc v1.32.0
 	google.golang.org/protobuf v1.25.0 // indirect
+	gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
 	gopkg.in/yaml.v2 v2.3.0 // indirect
 )
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index 500aaee..9358aa9 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -1,49 +1,27 @@
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
-dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
-github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec h1:tDOPo9NAXCjvoK35HgZyzQSNLmb3chZqN2tnO273Bro=
 github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec/go.mod h1:RZEHP3cxXvQlMuMjkpdh6qXA4b0CpjxnUBNxOpR0r30=
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
-github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
-github.com/daixiang0/gci v0.2.4/go.mod h1:+AV8KmHTGxxwp/pY84TLQfFKp2vuKXXJVzF3kD/hfR4=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/dmitryt/otus-golang-hw/hw12_13_14_15_calendar v0.0.0-20200916093948-5ca8860569b6 h1:kbX6KBmjfEYzBbEk2/bfAXgocxhzFQXH+5Tpr7gNg0k=
-github.com/dmitryt/otus-golang-hw/hw12_13_14_15_calendar v0.0.0-20200916093948-5ca8860569b6/go.mod h1:f//zKg1isd70tsJVPWphzKLXd7pvW4Owmtobh4uhuCQ=
 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
-github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
-github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
-github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
-github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
-github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
-github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
-github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
-github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
-github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
-github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
-github.com/go-playground/validator/v10 v10.3.0 h1:nZU+7q+yJoFmwvNgv/LnPUkwPal62+b2xXj0AU1Es7o=
-github.com/go-playground/validator/v10 v10.3.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
-github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
-github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
-github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
 github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
@@ -62,65 +40,37 @@ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
-github.com/grpc-ecosystem/go-grpc-middleware v1.2.1 h1:V59tBiPuMkySHwJkuq/OYkK0WnOLwCwD3UkTbEMr12U=
-github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
-github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU=
 github.com/grpc-ecosystem/grpc-gateway v1.15.0 h1:ntPNC9TD/6l2XDenJZe6T5lSMg95thpV9sGAqHX4WU8=
 github.com/grpc-ecosystem/grpc-gateway v1.15.0/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8=
-github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/ilyakaznacheev/cleanenv v1.2.5 h1:/SlcF9GaIvefWqFJzsccGG/NJdoaAwb7Mm7ImzhO3DM=
-github.com/ilyakaznacheev/cleanenv v1.2.5/go.mod h1:/i3yhzwZ3s7hacNERGFwvlhwXMDcaqwIzmayEhbRplk=
-github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
-github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
-github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
-github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
-github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
-github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
-github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
 github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
-github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
-github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
-github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
-github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
-github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
-github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
-github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
-github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
-github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
-github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
-github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
 github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
-github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
-github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
-github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs=
-github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
 github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
 github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
+github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
 github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
@@ -131,11 +81,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/tiburon-777/HW_OTUS v0.0.0-20200927064133-fc19ac2e8966 h1:LjBeW5xHnZQP7ZlViMBSaKP+HJhLSkOdSj7K7lXdbzg=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
-github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
 go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
-go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
@@ -144,47 +91,34 @@ go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKY
 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
 go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
-go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
 go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
 go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 h1:iMGN4xG0cnqj3t+zOM8wUB0BiPKHEwSxEZCvzcbZuvk=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
-golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
-golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
-golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
-golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
-golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e h1:JgcxKXxCjrA2tyDP/aNU9K0Ck5Czfk6C7e2tMw7+bSI=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
-golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
-golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
-golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -197,43 +131,28 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
-golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
-golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
 golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 h1:yaM5S0KcY0lIoZo7Fl+oi91b/DdlU2zuWpfHrpWbCS0=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
@@ -243,10 +162,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IV
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
-google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
-google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
 google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
@@ -256,8 +173,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
 google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
 google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
-google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
-google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
 google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
 google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
@@ -276,16 +191,14 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
-gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
-gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
@@ -294,5 +207,3 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
 honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
-olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24 h1:sreVOrDp0/ezb0CHKVek/l7YwpxPJqv+jT3izfSphA4=
-olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw=
diff --git a/hw12_13_14_15_calendar/internal/api/private/converters.go b/hw12_13_14_15_calendar/internal/api/private/converters.go
new file mode 100644
index 0000000..23c6831
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/converters.go
@@ -0,0 +1,22 @@
+package private
+
+import (
+	"github.com/golang/protobuf/ptypes"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+)
+
+func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, error) {
+	events := make([]*Event, len(evtMap))
+	var err error
+	var i int
+	for k, v := range evtMap {
+		evt := Event{ID: int64(k), Title: v.Title, UserID: v.UserID}
+		evt.Date, err = ptypes.TimestampProto(v.Date)
+		if err != nil {
+			return nil, err
+		}
+		events[i] = &evt
+		i++
+	}
+	return events, err
+}
diff --git a/hw12_13_14_15_calendar/internal/api/private/grpcclient.go b/hw12_13_14_15_calendar/internal/api/private/grpcclient.go
new file mode 100644
index 0000000..29d9baf
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/grpcclient.go
@@ -0,0 +1,16 @@
+package private
+
+import (
+	"net"
+
+	"google.golang.org/grpc"
+)
+
+func NewClient(addr, port string) (GrpcClient, error) {
+	conn, err := grpc.Dial(net.JoinHostPort(addr, port), grpc.WithInsecure())
+	if err != nil {
+		return nil, err
+	}
+	client := NewGrpcClient(conn)
+	return client, nil
+}
diff --git a/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go b/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
new file mode 100644
index 0000000..cb6e1ba
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
@@ -0,0 +1,314 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: grpcserver.proto
+
+package private
+
+import (
+	context "context"
+	fmt "fmt"
+	proto "github.com/golang/protobuf/proto"
+	empty "github.com/golang/protobuf/ptypes/empty"
+	timestamp "github.com/golang/protobuf/ptypes/timestamp"
+	grpc "google.golang.org/grpc"
+	codes "google.golang.org/grpc/codes"
+	status "google.golang.org/grpc/status"
+	math "math"
+)
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type GetRsp struct {
+	Events               []*Event `protobuf:"bytes,1,rep,name=Events,proto3" json:"Events,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *GetRsp) Reset()         { *m = GetRsp{} }
+func (m *GetRsp) String() string { return proto.CompactTextString(m) }
+func (*GetRsp) ProtoMessage()    {}
+func (*GetRsp) Descriptor() ([]byte, []int) {
+	return fileDescriptor_afa6debe97205904, []int{0}
+}
+
+func (m *GetRsp) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_GetRsp.Unmarshal(m, b)
+}
+func (m *GetRsp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_GetRsp.Marshal(b, m, deterministic)
+}
+func (m *GetRsp) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_GetRsp.Merge(m, src)
+}
+func (m *GetRsp) XXX_Size() int {
+	return xxx_messageInfo_GetRsp.Size(m)
+}
+func (m *GetRsp) XXX_DiscardUnknown() {
+	xxx_messageInfo_GetRsp.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_GetRsp proto.InternalMessageInfo
+
+func (m *GetRsp) GetEvents() []*Event {
+	if m != nil {
+		return m.Events
+	}
+	return nil
+}
+
+type SetReq struct {
+	ID                   int64    `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *SetReq) Reset()         { *m = SetReq{} }
+func (m *SetReq) String() string { return proto.CompactTextString(m) }
+func (*SetReq) ProtoMessage()    {}
+func (*SetReq) Descriptor() ([]byte, []int) {
+	return fileDescriptor_afa6debe97205904, []int{1}
+}
+
+func (m *SetReq) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_SetReq.Unmarshal(m, b)
+}
+func (m *SetReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_SetReq.Marshal(b, m, deterministic)
+}
+func (m *SetReq) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_SetReq.Merge(m, src)
+}
+func (m *SetReq) XXX_Size() int {
+	return xxx_messageInfo_SetReq.Size(m)
+}
+func (m *SetReq) XXX_DiscardUnknown() {
+	xxx_messageInfo_SetReq.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_SetReq proto.InternalMessageInfo
+
+func (m *SetReq) GetID() int64 {
+	if m != nil {
+		return m.ID
+	}
+	return 0
+}
+
+type Event struct {
+	ID                   int64                `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
+	Title                string               `protobuf:"bytes,2,opt,name=Title,proto3" json:"Title,omitempty"`
+	Date                 *timestamp.Timestamp `protobuf:"bytes,3,opt,name=Date,proto3" json:"Date,omitempty"`
+	UserID               int64                `protobuf:"varint,4,opt,name=UserID,proto3" json:"UserID,omitempty"`
+	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
+	XXX_unrecognized     []byte               `json:"-"`
+	XXX_sizecache        int32                `json:"-"`
+}
+
+func (m *Event) Reset()         { *m = Event{} }
+func (m *Event) String() string { return proto.CompactTextString(m) }
+func (*Event) ProtoMessage()    {}
+func (*Event) Descriptor() ([]byte, []int) {
+	return fileDescriptor_afa6debe97205904, []int{2}
+}
+
+func (m *Event) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_Event.Unmarshal(m, b)
+}
+func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_Event.Marshal(b, m, deterministic)
+}
+func (m *Event) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_Event.Merge(m, src)
+}
+func (m *Event) XXX_Size() int {
+	return xxx_messageInfo_Event.Size(m)
+}
+func (m *Event) XXX_DiscardUnknown() {
+	xxx_messageInfo_Event.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_Event proto.InternalMessageInfo
+
+func (m *Event) GetID() int64 {
+	if m != nil {
+		return m.ID
+	}
+	return 0
+}
+
+func (m *Event) GetTitle() string {
+	if m != nil {
+		return m.Title
+	}
+	return ""
+}
+
+func (m *Event) GetDate() *timestamp.Timestamp {
+	if m != nil {
+		return m.Date
+	}
+	return nil
+}
+
+func (m *Event) GetUserID() int64 {
+	if m != nil {
+		return m.UserID
+	}
+	return 0
+}
+
+func init() {
+	proto.RegisterType((*GetRsp)(nil), "private.GetRsp")
+	proto.RegisterType((*SetReq)(nil), "private.SetReq")
+	proto.RegisterType((*Event)(nil), "private.Event")
+}
+
+func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
+
+var fileDescriptor_afa6debe97205904 = []byte{
+	// 286 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4f, 0x6b, 0x32, 0x31,
+	0x10, 0x87, 0x5d, 0xff, 0xec, 0x8b, 0x23, 0xf8, 0x4a, 0x28, 0x12, 0xb6, 0x87, 0x2e, 0x7b, 0x28,
+	0x7b, 0x8a, 0xc5, 0x5e, 0x7a, 0xe9, 0xa5, 0xac, 0x88, 0x97, 0x1e, 0xa2, 0xbd, 0xf4, 0xb6, 0xda,
+	0x51, 0x02, 0x6a, 0xd2, 0x64, 0x5c, 0xe8, 0xa9, 0x5f, 0xbd, 0x98, 0xec, 0xb6, 0x60, 0xe9, 0x71,
+	0xe6, 0xf7, 0x64, 0x32, 0x4f, 0x02, 0xa3, 0x9d, 0x35, 0x1b, 0x87, 0xb6, 0x42, 0x2b, 0x8c, 0xd5,
+	0xa4, 0xd9, 0x3f, 0x63, 0x55, 0x55, 0x12, 0x26, 0x37, 0x3b, 0xad, 0x77, 0x7b, 0x9c, 0xf8, 0xf6,
+	0xfa, 0xb4, 0x9d, 0x90, 0x3a, 0xa0, 0xa3, 0xf2, 0x60, 0x02, 0x99, 0x5c, 0x5f, 0x02, 0x78, 0x30,
+	0xf4, 0x11, 0xc2, 0xec, 0x0e, 0xe2, 0x39, 0x92, 0x74, 0x86, 0xdd, 0x42, 0x3c, 0xab, 0xf0, 0x48,
+	0x8e, 0x47, 0x69, 0x27, 0x1f, 0x4c, 0x87, 0xa2, 0xbe, 0x41, 0xf8, 0xb6, 0xac, 0xd3, 0x8c, 0x43,
+	0xbc, 0x44, 0x92, 0xf8, 0xce, 0x86, 0xd0, 0x5e, 0x14, 0x3c, 0x4a, 0xa3, 0xbc, 0x23, 0xdb, 0x8b,
+	0x22, 0x3b, 0x41, 0xcf, 0x33, 0x97, 0x01, 0xbb, 0x82, 0xde, 0x4a, 0xd1, 0x1e, 0x79, 0x3b, 0x8d,
+	0xf2, 0xbe, 0x0c, 0x05, 0x13, 0xd0, 0x2d, 0x4a, 0x42, 0xde, 0x49, 0xa3, 0x7c, 0x30, 0x4d, 0x44,
+	0x58, 0x53, 0x34, 0x6b, 0x8a, 0x55, 0xe3, 0x21, 0x3d, 0xc7, 0xc6, 0x10, 0xbf, 0x38, 0xb4, 0x8b,
+	0x82, 0x77, 0xfd, 0xe4, 0xba, 0x9a, 0x7e, 0x42, 0xf7, 0xfc, 0x3a, 0xec, 0x11, 0x46, 0x73, 0xa4,
+	0x67, 0x4d, 0x6a, 0xab, 0x36, 0x25, 0x29, 0x7d, 0x74, 0x6c, 0xfc, 0x6b, 0xea, 0xec, 0x2c, 0x9f,
+	0xfc, 0xff, 0x96, 0x0b, 0xf6, 0x59, 0x8b, 0x3d, 0xc0, 0x60, 0xd9, 0x1c, 0xc7, 0x37, 0xf6, 0x43,
+	0x04, 0xdb, 0xe4, 0x8f, 0x51, 0x59, 0xeb, 0xa9, 0xff, 0xda, 0x7c, 0xc6, 0x3a, 0xf6, 0xe1, 0xfd,
+	0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x5f, 0x05, 0xc6, 0xb0, 0x01, 0x00, 0x00,
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConn
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion4
+
+// GrpcClient is the client API for Grpc service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
+type GrpcClient interface {
+	GetNotifications(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*GetRsp, error)
+	SetNotified(ctx context.Context, in *SetReq, opts ...grpc.CallOption) (*empty.Empty, error)
+}
+
+type grpcClient struct {
+	cc *grpc.ClientConn
+}
+
+func NewGrpcClient(cc *grpc.ClientConn) GrpcClient {
+	return &grpcClient{cc}
+}
+
+func (c *grpcClient) GetNotifications(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*GetRsp, error) {
+	out := new(GetRsp)
+	err := c.cc.Invoke(ctx, "/private.grpc/GetNotifications", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *grpcClient) SetNotified(ctx context.Context, in *SetReq, opts ...grpc.CallOption) (*empty.Empty, error) {
+	out := new(empty.Empty)
+	err := c.cc.Invoke(ctx, "/private.grpc/SetNotified", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// GrpcServer is the server API for Grpc service.
+type GrpcServer interface {
+	GetNotifications(context.Context, *empty.Empty) (*GetRsp, error)
+	SetNotified(context.Context, *SetReq) (*empty.Empty, error)
+}
+
+// UnimplementedGrpcServer can be embedded to have forward compatible implementations.
+type UnimplementedGrpcServer struct {
+}
+
+func (*UnimplementedGrpcServer) GetNotifications(ctx context.Context, req *empty.Empty) (*GetRsp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GetNotifications not implemented")
+}
+func (*UnimplementedGrpcServer) SetNotified(ctx context.Context, req *SetReq) (*empty.Empty, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method SetNotified not implemented")
+}
+
+func RegisterGrpcServer(s *grpc.Server, srv GrpcServer) {
+	s.RegisterService(&_Grpc_serviceDesc, srv)
+}
+
+func _Grpc_GetNotifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(empty.Empty)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(GrpcServer).GetNotifications(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/private.grpc/GetNotifications",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(GrpcServer).GetNotifications(ctx, req.(*empty.Empty))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Grpc_SetNotified_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(SetReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(GrpcServer).SetNotified(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/private.grpc/SetNotified",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(GrpcServer).SetNotified(ctx, req.(*SetReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+var _Grpc_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "private.grpc",
+	HandlerType: (*GrpcServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "GetNotifications",
+			Handler:    _Grpc_GetNotifications_Handler,
+		},
+		{
+			MethodName: "SetNotified",
+			Handler:    _Grpc_SetNotified_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "grpcserver.proto",
+}
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers.go b/hw12_13_14_15_calendar/internal/api/private/handlers.go
new file mode 100644
index 0000000..21277af
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers.go
@@ -0,0 +1,31 @@
+package private
+
+import (
+	"context"
+
+	"github.com/golang/protobuf/ptypes/empty"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/status"
+)
+
+type Service struct {
+	App calendar.App
+}
+
+func (s Service) GetNotifications(ctx context.Context, e *empty.Empty) (*GetRsp, error) {
+	tmp, err := s.App.Storage.GetNotifications()
+	if err != nil {
+		return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
+	}
+	l, err := s.buildEventList(tmp)
+	if err != nil {
+		return nil, status.Errorf(codes.Internal, "inconvertible")
+	}
+	return &GetRsp{Events: l}, nil
+}
+
+func (s Service) SetNotified(ctx context.Context, r *SetReq) (*empty.Empty, error) {
+	return nil, s.App.Storage.SetNotified(event.ID(r.ID))
+}
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers_test.go b/hw12_13_14_15_calendar/internal/api/private/handlers_test.go
new file mode 100644
index 0000000..7d34aa6
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers_test.go
@@ -0,0 +1,84 @@
+package private
+
+import (
+	"github.com/stretchr/testify/suite"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	oslog "log"
+	"testing"
+	"time"
+)
+
+var conf = config.Calendar{
+	HTTP:    config.Server{Address: "localhost", Port: "50511"},
+	GRPC:    config.Server{Address: "localhost", Port: "50512"},
+	API:     config.Server{Address: "localhost", Port: "50513"},
+	Logger:  config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false},
+	Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
+
+var storeConf = store.Config(conf.Storage)
+
+var testEvt = event.Event{Title: "Test event 1", Date: time.Now(), Latency: time.Hour * 24, Note: "First gen", UserID: 1111, NotifyTime: 0, Notified: false}
+
+func TestCalendarSuite(t *testing.T) {
+	suite.Run(t, new(TestSuite))
+}
+
+type TestSuite struct {
+	suite.Suite
+	srv Service
+}
+
+func (suite *TestSuite) SetupTest() {
+	log, err := logger.New(logger.Config(conf.Logger))
+	if err != nil {
+		oslog.Fatal("can't init logger")
+	}
+	suite.srv = Service{App: *calendar.New(log, store.NewStore(storeConf))}
+}
+
+func (s *TestSuite) TestGetNotifications() {
+	controlEvent := testEvt
+	s.createEvent(controlEvent)
+
+	returnedEvent := s.getNotifications()
+	s.Equal(controlEvent.Title, returnedEvent.Title)
+	s.Equal(controlEvent.UserID, returnedEvent.UserID)
+}
+
+func (s *TestSuite) TestSetNotified() {
+	controlEvent := testEvt
+	id := s.createEvent(controlEvent)
+
+	s.setNotified(id)
+	returnedEvent := s.getEventByID(id)
+	s.Equal(true, returnedEvent.Notified)
+}
+
+func (s *TestSuite) createEvent(ev event.Event) event.ID {
+	createdEvent, err := s.srv.App.Storage.Create(ev)
+	s.NoError(err, "can,t create event")
+	s.NotEqual(createdEvent, 0, `message ID may not be a "0"`)
+	return createdEvent
+}
+
+func (s *TestSuite) getNotifications() Event {
+	evs, err := s.srv.GetNotifications(nil, nil)
+	s.NoError(err, "can't get events")
+	s.Equal(1, len(evs.Events), "length of slice in responce must be a \"1\"")
+	return *evs.Events[0]
+}
+
+func (s *TestSuite) setNotified(id event.ID) {
+	_, err := s.srv.SetNotified(nil, &SetReq{ID: int64(id)})
+	s.NoError(err, "can't mark event as notified")
+}
+
+func (s *TestSuite) getEventByID(id event.ID) event.Event {
+	r, ok := s.srv.App.Storage.GetByID(id)
+	s.Equal(true, ok, "can't get event by id")
+	return r
+}
diff --git a/hw12_13_14_15_calendar/internal/api/private/server.go b/hw12_13_14_15_calendar/internal/api/private/server.go
new file mode 100644
index 0000000..1c857f6
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/api/private/server.go
@@ -0,0 +1,36 @@
+package private
+
+import (
+	"net"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	googrpc "google.golang.org/grpc"
+)
+
+type Server struct {
+	s   *googrpc.Server
+	app calendar.App
+}
+
+type Config struct {
+	Address string
+	Port    string
+}
+
+func New(app *calendar.App) Server {
+	return Server{s: googrpc.NewServer(), app: *app}
+}
+
+func (s *Server) Start(conf Config) error {
+	s.app.Logger.Infof("GRPC server starting")
+	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Address, conf.Port))
+	RegisterGrpcServer(s.s, &Service{})
+	if err != nil {
+		return err
+	}
+	return s.s.Serve(listnGrpc)
+}
+
+func (s *Server) Stop() {
+	s.s.GracefulStop()
+}
diff --git a/hw12_13_14_15_calendar/internal/app/app.go b/hw12_13_14_15_calendar/internal/calendar/app_calendar.go
similarity index 69%
rename from hw12_13_14_15_calendar/internal/app/app.go
rename to hw12_13_14_15_calendar/internal/calendar/app_calendar.go
index ffed7f0..c225eca 100644
--- a/hw12_13_14_15_calendar/internal/app/app.go
+++ b/hw12_13_14_15_calendar/internal/calendar/app_calendar.go
@@ -1,13 +1,12 @@
-package app
+package calendar
 
 import (
 	"context"
 	"net/http"
 	"time"
 
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
-	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
 )
 
 type Interface interface {
@@ -25,15 +24,6 @@ func New(logger logger.Interface, storage store.StorageInterface) *App {
 	return &App{Logger: logger, Storage: storage}
 }
 
-func (a *App) CreateEvent(ctx context.Context, title string) (err error) {
-	_, err = a.Storage.Create(event.Event{Title: title})
-	if err != nil {
-		a.Logger.Errorf("can not create event")
-	}
-	a.Logger.Infof("event created")
-	return err
-}
-
 func (a *App) Handler(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(200)
 	_, _ = w.Write([]byte("Hello! I'm calendar app!"))
diff --git a/hw12_13_14_15_calendar/internal/config/config.go b/hw12_13_14_15_calendar/internal/config/config.go
deleted file mode 100644
index bf7e135..0000000
--- a/hw12_13_14_15_calendar/internal/config/config.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package config
-
-import (
-	"io/ioutil"
-	"os"
-
-	"github.com/BurntSushi/toml"
-)
-
-type Config struct {
-	GRPC    Server
-	HTTP    Server
-	Logger  Logger
-	Storage Storage
-}
-
-type Server struct {
-	Address string
-	Port    string
-}
-
-type Logger struct {
-	File       string
-	Level      string
-	MuteStdout bool
-}
-
-type Storage struct {
-	InMemory bool
-	SQLHost  string
-	SQLPort  string
-	SQLDbase string
-	SQLUser  string
-	SQLPass  string
-}
-
-// Confita может быти и хороша, но она не возвращает ошибки, если не может распарсить файл в структуру. Мне не нравится такая "молчаливость".
-func NewConfig(configFile string) (Config, error) {
-	f, err := os.Open(configFile)
-	if err != nil {
-		return Config{}, err
-	}
-	defer f.Close()
-	s, err := ioutil.ReadAll(f)
-	if err != nil {
-		return Config{}, err
-	}
-	var config Config
-	_, err = toml.Decode(string(s), &config)
-	return config, err
-}
diff --git a/hw12_13_14_15_calendar/internal/sender/app_sender.go b/hw12_13_14_15_calendar/internal/sender/app_sender.go
new file mode 100644
index 0000000..778d10b
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/sender/app_sender.go
@@ -0,0 +1,65 @@
+package sender
+
+import (
+	"context"
+	"encoding/json"
+	oslog "log"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/rabbit"
+)
+
+type Sender struct {
+	Logger logger.Interface
+	Rabbit *rabbit.Rabbit
+	Queue  string
+}
+
+type Config struct {
+	Rabbitmq config.Rabbit
+	Logger   config.Logger
+}
+
+func New(conf Config) Sender {
+	log, err := logger.New(logger.Config(conf.Logger))
+	if err != nil {
+		oslog.Fatal("не удалось запустить логер:", err.Error())
+	}
+	rb, err := rabbit.Attach(rabbit.Config(conf.Rabbitmq))
+	if err != nil {
+		log.Fatalf("failed to connect to RabbitMQ:", err.Error())
+	}
+	return Sender{Logger: log, Rabbit: rb, Queue: conf.Rabbitmq.Queue}
+}
+
+func (s *Sender) Start(ctx context.Context) error {
+	msg, err := s.Rabbit.Consume(ctx, s.Queue)
+	if err != nil {
+		return err
+	}
+
+	go func() {
+		for {
+			select {
+			case m := <-msg:
+				var data []private.Event
+				err := json.Unmarshal(m.Data, &data)
+				if err != nil {
+					s.Logger.Errorf("can`t unmarshal data", err)
+				}
+				for _, v := range data {
+					s.Logger.Infof("User %s notified about event %s", v.UserID, v.ID)
+				}
+			case <-ctx.Done():
+				return
+			}
+		}
+	}()
+	return nil
+}
+
+func (s *Sender) Stop(cancel context.CancelFunc) {
+	cancel()
+}
diff --git a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
new file mode 100644
index 0000000..bb27d41
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
@@ -0,0 +1,58 @@
+package sheduler
+
+import (
+	"context"
+	oslog "log"
+	"time"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/rabbit"
+)
+
+type Scheduler struct {
+	CalendarAPI config.Server
+	Logger      logger.Interface
+	Rabbit      *rabbit.Rabbit
+}
+
+type Config struct {
+	CalendarAPI config.Server
+	Rabbitmq    config.Rabbit
+	Storage     config.Storage
+	Logger      config.Logger
+}
+
+func New(conf Config) Scheduler {
+	log, err := logger.New(logger.Config(conf.Logger))
+	if err != nil {
+		oslog.Fatal("не удалось запустить логер:", err.Error())
+	}
+	rb, err := rabbit.New(rabbit.Config(conf.Rabbitmq))
+	if err != nil {
+		log.Fatalf("failed to connect to RabbitMQ:", err.Error())
+	}
+	return Scheduler{CalendarAPI: conf.CalendarAPI, Logger: log, Rabbit: rb}
+}
+
+func (s *Scheduler) Start(ctx context.Context) error {
+	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit) }, 1*time.Minute)
+	go func() {
+		for {
+			select {
+			case err := <-fetcher:
+				s.Logger.Infof("fetcher closed")
+				if err != nil {
+					s.Logger.Errorf("...with error:", err)
+				}
+			case <-ctx.Done():
+				return
+			}
+		}
+	}()
+	return nil
+}
+
+func (s *Scheduler) Stop(cancel context.CancelFunc) {
+	cancel()
+}
diff --git a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
new file mode 100644
index 0000000..6e99db8
--- /dev/null
+++ b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
@@ -0,0 +1,60 @@
+package sheduler
+
+import (
+	"context"
+	"encoding/json"
+	"time"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/rabbit"
+)
+
+func riseOnTick(ctx context.Context, log logger.Interface, fn func() interface{}, interval time.Duration) <-chan interface{} {
+	valueStream := make(chan interface{})
+	go func() {
+		t := time.NewTicker(interval)
+		defer func() {
+			t.Stop()
+			close(valueStream)
+		}()
+		for {
+			select {
+			case <-ctx.Done():
+				return
+			case <-t.C:
+				select {
+				case <-ctx.Done():
+					return
+				default:
+					log.Infof("scheduler come to rabbit")
+					valueStream <- fn()
+				}
+			}
+		}
+	}()
+	return valueStream
+}
+
+func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit) error {
+	cli, err := private.NewClient(calendarAPI.Address, calendarAPI.Port)
+	if err != nil {
+		return err
+	}
+	resp, err := cli.GetNotifications(ctx, nil)
+	if err != nil {
+		return err
+	}
+	for event := range resp.Events {
+		b, err := json.Marshal(event)
+		if err != nil {
+			return err
+		}
+		err = rb.Publish(string(b))
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
diff --git a/hw12_13_14_15_calendar/migrations/20200924000000_init.sql b/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
index c048c95..5d48a9b 100644
--- a/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
+++ b/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
@@ -7,7 +7,8 @@ CREATE TABLE events (
 	latency int(16) NOT NULL,
 	note text,
 	userID int(16),
-	notifyTime int(16)
+	notifyTime int(16),
+	notified bool
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;;
 -- +goose StatementEnd
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/converters.go b/hw12_13_14_15_calendar/pkg/api/public/converters.go
similarity index 94%
rename from hw12_13_14_15_calendar/internal/grpcserver/converters.go
rename to hw12_13_14_15_calendar/pkg/api/public/converters.go
index 0c6c67c..1bdcade 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/converters.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/converters.go
@@ -1,10 +1,10 @@
-package grpcserver
+package public
 
 import (
 	"time"
 
 	"github.com/golang/protobuf/ptypes"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
 func (s Service) buildStorageEvent(pbe *CreateReq) (res event.Event, err error) {
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.go b/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go
similarity index 82%
rename from hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.go
rename to hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go
index 910758a..b595e75 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go
@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // source: grpcserver.proto
 
-package grpcserver
+package public
 
 import (
 	context "context"
@@ -466,7 +466,7 @@ func (m *GetByIDResp) GetEvents() []*Event {
 
 type GetByDateReq struct {
 	Date                 *timestamp.Timestamp `protobuf:"bytes,1,opt,name=Date,proto3" json:"Date,omitempty"`
-	Range                QueryRange           `protobuf:"varint,2,opt,name=Range,proto3,enum=grpcserver.QueryRange" json:"Range,omitempty"`
+	Range                QueryRange           `protobuf:"varint,2,opt,name=Range,proto3,enum=public.QueryRange" json:"Range,omitempty"`
 	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
 	XXX_unrecognized     []byte               `json:"-"`
 	XXX_sizecache        int32                `json:"-"`
@@ -551,61 +551,62 @@ func (m *GetByDateResp) GetEvents() []*Event {
 }
 
 func init() {
-	proto.RegisterEnum("grpcserver.QueryRange", QueryRange_name, QueryRange_value)
-	proto.RegisterType((*Event)(nil), "grpcserver.Event")
-	proto.RegisterType((*CreateReq)(nil), "grpcserver.CreateReq")
-	proto.RegisterType((*CreateRsp)(nil), "grpcserver.CreateRsp")
-	proto.RegisterType((*UpdateReq)(nil), "grpcserver.UpdateReq")
-	proto.RegisterType((*DeleteReq)(nil), "grpcserver.DeleteReq")
-	proto.RegisterType((*ListResp)(nil), "grpcserver.ListResp")
-	proto.RegisterType((*GetByIDReq)(nil), "grpcserver.GetByIDReq")
-	proto.RegisterType((*GetByIDResp)(nil), "grpcserver.GetByIDResp")
-	proto.RegisterType((*GetByDateReq)(nil), "grpcserver.GetByDateReq")
-	proto.RegisterType((*GetByDateResp)(nil), "grpcserver.GetByDateResp")
+	proto.RegisterEnum("public.QueryRange", QueryRange_name, QueryRange_value)
+	proto.RegisterType((*Event)(nil), "public.Event")
+	proto.RegisterType((*CreateReq)(nil), "public.CreateReq")
+	proto.RegisterType((*CreateRsp)(nil), "public.CreateRsp")
+	proto.RegisterType((*UpdateReq)(nil), "public.UpdateReq")
+	proto.RegisterType((*DeleteReq)(nil), "public.DeleteReq")
+	proto.RegisterType((*ListResp)(nil), "public.ListResp")
+	proto.RegisterType((*GetByIDReq)(nil), "public.GetByIDReq")
+	proto.RegisterType((*GetByIDResp)(nil), "public.GetByIDResp")
+	proto.RegisterType((*GetByDateReq)(nil), "public.GetByDateReq")
+	proto.RegisterType((*GetByDateResp)(nil), "public.GetByDateResp")
 }
 
 func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
 
 var fileDescriptor_afa6debe97205904 = []byte{
-	// 608 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0x4f, 0x6f, 0xd3, 0x4c,
-	0x10, 0xc6, 0x5f, 0x27, 0x8e, 0x53, 0x4f, 0xf3, 0x96, 0x74, 0x14, 0x52, 0xd7, 0xad, 0x4a, 0xb4,
-	0x17, 0x42, 0x84, 0x6c, 0x29, 0x15, 0x12, 0xf4, 0x46, 0x71, 0x04, 0x81, 0x36, 0x14, 0x2b, 0x15,
-	0x82, 0x13, 0x6e, 0xbb, 0x8d, 0x2c, 0x25, 0xb6, 0xb1, 0x37, 0x95, 0xa2, 0x2a, 0x17, 0xbe, 0x02,
-	0x1f, 0x8d, 0xaf, 0xc0, 0x15, 0xee, 0xdc, 0x90, 0xd7, 0x6b, 0xc7, 0xf9, 0x27, 0xe8, 0x99, 0x5b,
-	0x76, 0x9f, 0x99, 0xdf, 0xcc, 0xec, 0x3c, 0x8a, 0xa1, 0x3a, 0x08, 0x83, 0xcb, 0x88, 0x86, 0x37,
-	0x34, 0x34, 0x82, 0xd0, 0x67, 0x3e, 0xc2, 0xec, 0x46, 0x7f, 0x30, 0xf0, 0xfd, 0xc1, 0x90, 0x9a,
-	0x5c, 0xb9, 0x18, 0x5f, 0x9b, 0xcc, 0x1d, 0xd1, 0x88, 0x39, 0xa3, 0x20, 0x09, 0xd6, 0x0f, 0x16,
-	0x03, 0xae, 0xc6, 0xa1, 0xc3, 0x5c, 0xdf, 0x13, 0xfa, 0xde, 0xa2, 0x4e, 0x47, 0x01, 0x9b, 0x08,
-	0x71, 0x5f, 0x88, 0x4e, 0xe0, 0x9a, 0x8e, 0xe7, 0xf9, 0x8c, 0x67, 0x46, 0x89, 0x4a, 0x7e, 0x49,
-	0x50, 0xea, 0xdc, 0x50, 0x8f, 0xe1, 0x16, 0x14, 0xba, 0x96, 0x26, 0x35, 0xa4, 0x66, 0xd1, 0x2e,
-	0x74, 0x2d, 0xac, 0x41, 0xa9, 0xef, 0xb2, 0x21, 0xd5, 0x0a, 0x0d, 0xa9, 0xa9, 0xda, 0xc9, 0x01,
-	0x0d, 0x90, 0x2d, 0x87, 0x51, 0xad, 0xd8, 0x90, 0x9a, 0x9b, 0x6d, 0xdd, 0x48, 0xe0, 0x46, 0x5a,
-	0xd9, 0xe8, 0xa7, 0xad, 0xdb, 0x3c, 0x0e, 0x0f, 0xa1, 0x7c, 0xe2, 0x30, 0xea, 0x5d, 0x4e, 0x34,
-	0x99, 0xa7, 0xec, 0x2e, 0xa5, 0x58, 0x62, 0x18, 0x3b, 0x8d, 0x44, 0x04, 0xb9, 0xe7, 0x33, 0xaa,
-	0x95, 0x78, 0x65, 0xfe, 0x1b, 0xeb, 0xa0, 0x9c, 0x47, 0x34, 0xec, 0x5a, 0x9a, 0xc2, 0x5b, 0x14,
-	0x27, 0x7c, 0x06, 0xd0, 0xf3, 0x99, 0x7b, 0x3d, 0x89, 0x2b, 0x6b, 0xe5, 0x3f, 0xd5, 0xc8, 0x05,
-	0x93, 0x1f, 0x12, 0xa8, 0x2f, 0x42, 0xea, 0x30, 0x6a, 0xd3, 0xcf, 0xff, 0xc0, 0xbc, 0x7b, 0xd9,
-	0xb8, 0x51, 0xb0, 0xb8, 0x6e, 0x62, 0x81, 0x7a, 0x1e, 0x5c, 0x89, 0xb7, 0x58, 0xf4, 0xc2, 0x43,
-	0x61, 0x12, 0xfe, 0x36, 0x9b, 0xed, 0x6d, 0x23, 0xe7, 0x67, 0x2e, 0xd8, 0x89, 0x1e, 0x97, 0xb0,
-	0xe8, 0x90, 0xae, 0xa4, 0x90, 0x27, 0xb0, 0x71, 0xe2, 0x46, 0xcc, 0xa6, 0x51, 0x80, 0x8f, 0x40,
-	0xe1, 0x19, 0x91, 0x26, 0x35, 0x8a, 0xab, 0x91, 0x22, 0x80, 0xec, 0x03, 0xbc, 0xa4, 0xec, 0x78,
-	0xd2, 0xb5, 0x56, 0x41, 0x9f, 0xc2, 0x66, 0xa6, 0xde, 0x8d, 0x3b, 0x84, 0x0a, 0xcf, 0xb4, 0xc4,
-	0xd0, 0xe9, 0xaa, 0xa5, 0xbf, 0x5c, 0xf5, 0x63, 0x28, 0xd9, 0x8e, 0x37, 0x48, 0x0c, 0xb3, 0xd5,
-	0xae, 0xe7, 0x2b, 0xbd, 0x1b, 0xd3, 0x70, 0xc2, 0x55, 0x3b, 0x09, 0x22, 0x47, 0xf0, 0x7f, 0xae,
-	0xda, 0x9d, 0x3a, 0x6d, 0xb5, 0x00, 0x66, 0x40, 0x2c, 0x43, 0xd1, 0x7a, 0xfe, 0xa1, 0xfa, 0x1f,
-	0x6e, 0x80, 0xfc, 0xbe, 0xd3, 0x79, 0x53, 0x95, 0x50, 0x85, 0xd2, 0xe9, 0xdb, 0x5e, 0xff, 0x55,
-	0xb5, 0xd0, 0xfe, 0x59, 0x04, 0x39, 0x06, 0xe1, 0x6b, 0x50, 0x92, 0x6d, 0xe3, 0xfd, 0x3c, 0x39,
-	0x33, 0xbc, 0xbe, 0xea, 0x3a, 0x0a, 0x08, 0x7e, 0xf9, 0xf6, 0xfd, 0x6b, 0xa1, 0x42, 0xca, 0x26,
-	0xe5, 0xd5, 0x8f, 0xa4, 0x16, 0x9e, 0x81, 0x92, 0x98, 0x63, 0x9e, 0x95, 0x19, 0x46, 0xaf, 0x2f,
-	0xbd, 0x56, 0x27, 0xfe, 0x0b, 0x22, 0x3b, 0x1c, 0xb6, 0xad, 0x57, 0x04, 0xcc, 0xbc, 0xed, 0x5a,
-	0xd3, 0x98, 0x78, 0x0a, 0x4a, 0x62, 0x94, 0x79, 0x62, 0x66, 0x9e, 0xb5, 0xc4, 0x1a, 0x27, 0x6e,
-	0xb5, 0xe6, 0x88, 0xd8, 0x01, 0x39, 0xb6, 0x16, 0xae, 0xc9, 0xd2, 0x6b, 0xf9, 0x22, 0xa9, 0x09,
-	0xc9, 0x3d, 0xce, 0x52, 0x31, 0x1d, 0x15, 0xcf, 0xa0, 0x2c, 0xcc, 0x84, 0x73, 0xeb, 0x9c, 0xf9,
-	0x4f, 0xdf, 0x59, 0x79, 0x1f, 0x05, 0x69, 0x63, 0x38, 0xdf, 0xd8, 0x27, 0x50, 0xb3, 0xb5, 0xa3,
-	0xb6, 0x94, 0x2b, 0xbc, 0xa7, 0xef, 0xae, 0x51, 0xa2, 0x80, 0x1c, 0x70, 0xae, 0x46, 0xea, 0x19,
-	0x97, 0xdb, 0x60, 0x6a, 0xde, 0xc6, 0x21, 0xd3, 0xe3, 0xca, 0xc7, 0xdc, 0xb7, 0xe4, 0x42, 0xe1,
-	0x83, 0x1f, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xc6, 0xe4, 0xd7, 0xf2, 0x72, 0x06, 0x00, 0x00,
+	// 613 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0xcb, 0x6e, 0xd3, 0x5c,
+	0x10, 0xc7, 0x3f, 0x27, 0x8e, 0x53, 0x4f, 0x2f, 0x5f, 0x3a, 0x94, 0x62, 0xdc, 0xaa, 0x44, 0x07,
+	0x21, 0x45, 0x59, 0xd8, 0x22, 0x45, 0x48, 0xb0, 0xa2, 0xc5, 0x11, 0xb5, 0x28, 0x45, 0x58, 0xa9,
+	0xb8, 0xec, 0x9c, 0xf4, 0x34, 0x58, 0x4a, 0xec, 0x83, 0x7d, 0x52, 0x29, 0xaa, 0xb2, 0xe1, 0x15,
+	0x78, 0x2b, 0xb6, 0xbc, 0x02, 0x5b, 0x1e, 0x80, 0x1d, 0xf2, 0xf1, 0xb1, 0xd3, 0x5c, 0x2a, 0xb2,
+	0x67, 0x17, 0xcf, 0x7f, 0xe6, 0x37, 0x33, 0x9e, 0xbf, 0x1c, 0xa8, 0xf5, 0x63, 0xd6, 0x4b, 0x68,
+	0x7c, 0x45, 0x63, 0x8b, 0xc5, 0x11, 0x8f, 0x50, 0x63, 0xa3, 0xee, 0x20, 0xe8, 0x99, 0x0f, 0xfa,
+	0x51, 0xd4, 0x1f, 0x50, 0x5b, 0x44, 0xbb, 0xa3, 0x4b, 0x9b, 0x07, 0x43, 0x9a, 0x70, 0x7f, 0xc8,
+	0xb2, 0x44, 0xf3, 0x60, 0x3e, 0xe1, 0x62, 0x14, 0xfb, 0x3c, 0x88, 0x42, 0xa9, 0xef, 0xcd, 0xeb,
+	0x74, 0xc8, 0xf8, 0x58, 0x8a, 0xfb, 0x52, 0xf4, 0x59, 0x60, 0xfb, 0x61, 0x18, 0x71, 0x51, 0x99,
+	0x64, 0x2a, 0xf9, 0xad, 0x40, 0xa5, 0x7d, 0x45, 0x43, 0x8e, 0x5b, 0x50, 0x72, 0x1d, 0x43, 0xa9,
+	0x2b, 0x8d, 0xb2, 0x57, 0x72, 0x1d, 0xdc, 0x81, 0x4a, 0x27, 0xe0, 0x03, 0x6a, 0x94, 0xea, 0x4a,
+	0x43, 0xf7, 0xb2, 0x07, 0xb4, 0x40, 0x75, 0x7c, 0x4e, 0x8d, 0x72, 0x5d, 0x69, 0xac, 0xb7, 0x4c,
+	0x2b, 0x83, 0x5b, 0x79, 0x67, 0xab, 0x93, 0x8f, 0xee, 0x89, 0x3c, 0x3c, 0x84, 0xea, 0xa9, 0xcf,
+	0x69, 0xd8, 0x1b, 0x1b, 0xaa, 0x28, 0xb9, 0xbf, 0x50, 0xe2, 0xc8, 0x65, 0xbc, 0x3c, 0x13, 0x11,
+	0xd4, 0xb3, 0x88, 0x53, 0xa3, 0x22, 0x3a, 0x8b, 0xdf, 0xb8, 0x0b, 0xda, 0x79, 0x42, 0x63, 0xd7,
+	0x31, 0x34, 0x31, 0xa2, 0x7c, 0xc2, 0x67, 0x00, 0x67, 0x11, 0x0f, 0x2e, 0xc7, 0x69, 0x67, 0xa3,
+	0xfa, 0xb7, 0x1e, 0x37, 0x92, 0xc9, 0x2f, 0x05, 0xf4, 0x97, 0x31, 0xf5, 0x39, 0xf5, 0xe8, 0x97,
+	0x7f, 0x60, 0xdf, 0xbd, 0x62, 0xdd, 0x84, 0xcd, 0x9f, 0x9b, 0xbc, 0x00, 0xfd, 0x9c, 0x5d, 0xc8,
+	0x77, 0x31, 0xef, 0x85, 0x87, 0xd2, 0x24, 0xe2, 0xdd, 0xac, 0xb7, 0x36, 0xad, 0xcc, 0xb9, 0x96,
+	0x08, 0x7a, 0x99, 0x96, 0xe2, 0x1d, 0x3a, 0xa0, 0x4b, 0x09, 0xe4, 0x31, 0xac, 0x9d, 0x06, 0x09,
+	0xf7, 0x68, 0xc2, 0xf0, 0x11, 0x68, 0xa2, 0x22, 0x31, 0x94, 0x7a, 0x79, 0x11, 0x27, 0x45, 0xb2,
+	0x0f, 0xf0, 0x8a, 0xf2, 0xe3, 0xb1, 0xeb, 0x2c, 0x03, 0x3e, 0x81, 0xf5, 0x42, 0x5d, 0x9d, 0xf9,
+	0x19, 0x36, 0x44, 0x95, 0x23, 0x17, 0xcd, 0xcf, 0xab, 0xac, 0x78, 0xde, 0x06, 0x54, 0x3c, 0x3f,
+	0xec, 0x67, 0x26, 0xd9, 0x6a, 0x61, 0xde, 0xe5, 0xdd, 0x88, 0xc6, 0x63, 0xa1, 0x78, 0x59, 0x02,
+	0x79, 0x0a, 0x9b, 0x37, 0x3a, 0xad, 0x3c, 0x61, 0xb3, 0x09, 0x30, 0x85, 0x61, 0x15, 0xca, 0xce,
+	0xd1, 0xc7, 0xda, 0x7f, 0xb8, 0x06, 0xea, 0xfb, 0x76, 0xfb, 0x75, 0x4d, 0x41, 0x1d, 0x2a, 0x6f,
+	0xde, 0x9e, 0x75, 0x4e, 0x6a, 0xa5, 0xd6, 0xf7, 0x32, 0xa8, 0xe9, 0x57, 0x05, 0x8f, 0x41, 0xcb,
+	0x2e, 0x8b, 0xdb, 0x39, 0xb5, 0x30, 0xb6, 0x39, 0x1f, 0x4a, 0x18, 0xc1, 0xaf, 0x3f, 0x7e, 0x7e,
+	0x2b, 0x6d, 0x90, 0xaa, 0x4d, 0x45, 0xd7, 0xe7, 0x4a, 0x13, 0x4f, 0x41, 0xcb, 0x0c, 0x30, 0x65,
+	0x14, 0x86, 0x30, 0x77, 0x17, 0xde, 0x4c, 0x3b, 0xfd, 0xc4, 0x90, 0x7b, 0x02, 0xb4, 0x6d, 0x6e,
+	0x48, 0x90, 0x7d, 0xed, 0x3a, 0x93, 0x94, 0xe6, 0x82, 0x96, 0x99, 0x61, 0x4a, 0x2b, 0xcc, 0x71,
+	0x2b, 0x6d, 0x47, 0xd0, 0xb6, 0x9a, 0x33, 0x34, 0x3c, 0x02, 0x35, 0xb5, 0x0e, 0xde, 0x52, 0x65,
+	0xd6, 0xf2, 0x06, 0xb9, 0xc1, 0xc8, 0xff, 0x82, 0xa3, 0x63, 0xbe, 0x1e, 0x9e, 0x40, 0x55, 0x9a,
+	0x05, 0x8b, 0x93, 0x4d, 0xbd, 0x65, 0xde, 0x59, 0x88, 0x25, 0x2c, 0x1f, 0x06, 0x67, 0x87, 0xf9,
+	0x00, 0x7a, 0x71, 0x56, 0xdc, 0x99, 0xa9, 0x93, 0x9e, 0x32, 0xef, 0x2e, 0x89, 0x26, 0x8c, 0x1c,
+	0x08, 0x9e, 0x41, 0x76, 0x0b, 0x9e, 0x38, 0xf1, 0xc4, 0xbe, 0x4e, 0x53, 0x26, 0xc7, 0x6b, 0x9f,
+	0xe4, 0xff, 0x41, 0x57, 0x13, 0x0b, 0x1e, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0x88, 0xff, 0xa1,
+	0x0a, 0x32, 0x06, 0x00, 0x00,
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -638,7 +639,7 @@ func NewGrpcClient(cc *grpc.ClientConn) GrpcClient {
 
 func (c *grpcClient) Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*CreateRsp, error) {
 	out := new(CreateRsp)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/Create", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/Create", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -647,7 +648,7 @@ func (c *grpcClient) Create(ctx context.Context, in *CreateReq, opts ...grpc.Cal
 
 func (c *grpcClient) Update(ctx context.Context, in *UpdateReq, opts ...grpc.CallOption) (*empty.Empty, error) {
 	out := new(empty.Empty)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/Update", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/Update", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -656,7 +657,7 @@ func (c *grpcClient) Update(ctx context.Context, in *UpdateReq, opts ...grpc.Cal
 
 func (c *grpcClient) Delete(ctx context.Context, in *DeleteReq, opts ...grpc.CallOption) (*empty.Empty, error) {
 	out := new(empty.Empty)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/Delete", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/Delete", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -665,7 +666,7 @@ func (c *grpcClient) Delete(ctx context.Context, in *DeleteReq, opts ...grpc.Cal
 
 func (c *grpcClient) List(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ListResp, error) {
 	out := new(ListResp)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/List", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/List", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -674,7 +675,7 @@ func (c *grpcClient) List(ctx context.Context, in *empty.Empty, opts ...grpc.Cal
 
 func (c *grpcClient) GetByID(ctx context.Context, in *GetByIDReq, opts ...grpc.CallOption) (*GetByIDResp, error) {
 	out := new(GetByIDResp)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/GetByID", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/GetByID", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -683,7 +684,7 @@ func (c *grpcClient) GetByID(ctx context.Context, in *GetByIDReq, opts ...grpc.C
 
 func (c *grpcClient) GetByDate(ctx context.Context, in *GetByDateReq, opts ...grpc.CallOption) (*GetByDateResp, error) {
 	out := new(GetByDateResp)
-	err := c.cc.Invoke(ctx, "/grpcserver.grpc/GetByDate", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/public.grpc/GetByDate", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -737,7 +738,7 @@ func _Grpc_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/Create",
+		FullMethod: "/public.grpc/Create",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).Create(ctx, req.(*CreateReq))
@@ -755,7 +756,7 @@ func _Grpc_Update_Handler(srv interface{}, ctx context.Context, dec func(interfa
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/Update",
+		FullMethod: "/public.grpc/Update",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).Update(ctx, req.(*UpdateReq))
@@ -773,7 +774,7 @@ func _Grpc_Delete_Handler(srv interface{}, ctx context.Context, dec func(interfa
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/Delete",
+		FullMethod: "/public.grpc/Delete",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).Delete(ctx, req.(*DeleteReq))
@@ -791,7 +792,7 @@ func _Grpc_List_Handler(srv interface{}, ctx context.Context, dec func(interface
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/List",
+		FullMethod: "/public.grpc/List",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).List(ctx, req.(*empty.Empty))
@@ -809,7 +810,7 @@ func _Grpc_GetByID_Handler(srv interface{}, ctx context.Context, dec func(interf
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/GetByID",
+		FullMethod: "/public.grpc/GetByID",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).GetByID(ctx, req.(*GetByIDReq))
@@ -827,7 +828,7 @@ func _Grpc_GetByDate_Handler(srv interface{}, ctx context.Context, dec func(inte
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/grpcserver.grpc/GetByDate",
+		FullMethod: "/public.grpc/GetByDate",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(GrpcServer).GetByDate(ctx, req.(*GetByDateReq))
@@ -836,7 +837,7 @@ func _Grpc_GetByDate_Handler(srv interface{}, ctx context.Context, dec func(inte
 }
 
 var _Grpc_serviceDesc = grpc.ServiceDesc{
-	ServiceName: "grpcserver.grpc",
+	ServiceName: "public.grpc",
 	HandlerType: (*GrpcServer)(nil),
 	Methods: []grpc.MethodDesc{
 		{
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.gw.go b/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go
similarity index 99%
rename from hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.gw.go
rename to hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go
index 54ea6e2..a86236c 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/grpcserver.pb.gw.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go
@@ -2,11 +2,11 @@
 // source: grpcserver.proto
 
 /*
-Package grpcserver is a reverse proxy.
+Package public is a reverse proxy.
 
 It translates gRPC into RESTful JSON APIs.
 */
-package grpcserver
+package public
 
 import (
 	"io"
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/handlers.go b/hw12_13_14_15_calendar/pkg/api/public/handlers.go
similarity index 95%
rename from hw12_13_14_15_calendar/internal/grpcserver/handlers.go
rename to hw12_13_14_15_calendar/pkg/api/public/handlers.go
index 28f1ace..44894e6 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/handlers.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handlers.go
@@ -1,17 +1,17 @@
-package grpcserver
+package public
 
 import (
 	"context"
 
 	"github.com/golang/protobuf/ptypes/empty"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
 
 type Service struct {
-	App app.App
+	App calendar.App
 }
 
 func (s Service) Create(ctx context.Context, e *CreateReq) (*CreateRsp, error) {
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/handlers_test.go b/hw12_13_14_15_calendar/pkg/api/public/handlers_test.go
similarity index 84%
rename from hw12_13_14_15_calendar/internal/grpcserver/handlers_test.go
rename to hw12_13_14_15_calendar/pkg/api/public/handlers_test.go
index c92c391..adaf634 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/handlers_test.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handlers_test.go
@@ -1,19 +1,24 @@
-package grpcserver
+package public
 
 import (
 	"github.com/golang/protobuf/ptypes"
 	"github.com/golang/protobuf/ptypes/timestamp"
 	"github.com/stretchr/testify/suite"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
-	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
 	oslog "log"
 	"testing"
 	"time"
 )
 
-var conf = config.Config{HTTP: config.Server{Address: "localhost", Port: "50511"}, GRPC: config.Server{Address: "localhost", Port: "50512"}, Logger: config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false}, Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
+var conf = config.Calendar{
+	HTTP:    config.Server{Address: "localhost", Port: "50511"},
+	GRPC:    config.Server{Address: "localhost", Port: "50512"},
+	API:     config.Server{Address: "localhost", Port: "50513"},
+	Logger:  config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false},
+	Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
 
 var storeConf = store.Config(conf.Storage)
 
@@ -31,11 +36,11 @@ type TestSuite struct {
 }
 
 func (suite *TestSuite) SetupTest() {
-	log, err := logger.New(conf)
+	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
 		oslog.Fatal("can't init logger")
 	}
-	suite.srv = Service{App: *app.New(log, store.NewStore(storeConf))}
+	suite.srv = Service{App: *calendar.New(log, store.NewStore(storeConf))}
 }
 
 func (s *TestSuite) TestCreateEvent() {
@@ -74,7 +79,7 @@ func (s *TestSuite) TestListEvent() {
 	s.createEvent(&testEvent)
 
 	eventList := s.listEvents()
-	s.GreaterOrEqual(len(eventList),1)
+	s.GreaterOrEqual(len(eventList), 1)
 	s.Equal(testEvt1.Title, eventList[0].Title)
 }
 
@@ -91,7 +96,7 @@ func (s *TestSuite) TestGetEventByDate() {
 	s.createEvent(&testEvent)
 
 	eventList := s.getEventByDate(testEvent.Date)
-	s.GreaterOrEqual(len(eventList),1)
+	s.GreaterOrEqual(len(eventList), 1)
 	s.Equal(testEvent.Title, eventList[0].Title)
 }
 
diff --git a/hw12_13_14_15_calendar/internal/grpcserver/server.go b/hw12_13_14_15_calendar/pkg/api/public/server.go
similarity index 71%
rename from hw12_13_14_15_calendar/internal/grpcserver/server.go
rename to hw12_13_14_15_calendar/pkg/api/public/server.go
index 7a3411a..1d88db1 100644
--- a/hw12_13_14_15_calendar/internal/grpcserver/server.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/server.go
@@ -1,23 +1,23 @@
-package grpcserver
+package public
 
 import (
 	"net"
 
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	googrpc "google.golang.org/grpc"
 )
 
 type Server struct {
 	s   *googrpc.Server
-	app app.App
+	app calendar.App
 }
 
-func New(app *app.App) Server {
+func New(app *calendar.App) Server {
 	return Server{s: googrpc.NewServer(), app: *app}
 }
 
-func (s *Server) Start(conf config.Config) error {
+func (s *Server) Start(conf config.Calendar) error {
 	s.app.Logger.Infof("GRPC server starting")
 	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.GRPC.Address, conf.GRPC.Port))
 	RegisterGrpcServer(s.s, &Service{})
diff --git a/hw12_13_14_15_calendar/pkg/config/config.go b/hw12_13_14_15_calendar/pkg/config/config.go
new file mode 100644
index 0000000..4945f71
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/config/config.go
@@ -0,0 +1,22 @@
+package config
+
+import (
+	"io/ioutil"
+	"os"
+
+	"github.com/BurntSushi/toml"
+)
+
+func New(configFile string, str interface{}) error {
+	f, err := os.Open(configFile)
+	if err != nil {
+		return err
+	}
+	defer f.Close()
+	s, err := ioutil.ReadAll(f)
+	if err != nil {
+		return err
+	}
+	_, err = toml.Decode(string(s), str)
+	return err
+}
diff --git a/hw12_13_14_15_calendar/internal/config/config_test.go b/hw12_13_14_15_calendar/pkg/config/config_test.go
similarity index 81%
rename from hw12_13_14_15_calendar/internal/config/config_test.go
rename to hw12_13_14_15_calendar/pkg/config/config_test.go
index 3fdd126..cff5012 100644
--- a/hw12_13_14_15_calendar/internal/config/config_test.go
+++ b/hw12_13_14_15_calendar/pkg/config/config_test.go
@@ -37,19 +37,22 @@ SQLHost = "localhost"`)
 	goodfile.Sync()
 
 	t.Run("No such file", func(t *testing.T) {
-		c, e := NewConfig("adfergdth")
-		require.Equal(t, Config{}, c)
+		var c Calendar
+		e := New("adfergdth", &c)
+		require.Equal(t, Calendar{}, c)
 		require.Error(t, e)
 	})
 
 	t.Run("Bad file", func(t *testing.T) {
-		c, e := NewConfig(badfile.Name())
-		require.Equal(t, Config{}, c)
+		var c Calendar
+		e := New(badfile.Name(), &c)
+		require.Equal(t, Calendar{}, c)
 		require.Error(t, e)
 	})
 
 	t.Run("TOML reading", func(t *testing.T) {
-		c, e := NewConfig(goodfile.Name())
+		var c Calendar
+		e := New(goodfile.Name(), &c)
 		require.Equal(t, true, c.Storage.InMemory)
 		require.Equal(t, "localhost", c.Storage.SQLHost)
 		require.NoError(t, e)
diff --git a/hw12_13_14_15_calendar/pkg/config/types.go b/hw12_13_14_15_calendar/pkg/config/types.go
new file mode 100644
index 0000000..b180406
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/config/types.go
@@ -0,0 +1,50 @@
+package config
+
+type Calendar struct {
+	GRPC    Server
+	HTTP    Server
+	API     Server
+	Logger  Logger
+	Storage Storage
+}
+
+type Scheduler struct {
+	Rabbitmq Rabbit
+	Storage  Storage
+	Logger   Logger
+}
+
+type Sender struct {
+	Rabbitmq Rabbit
+	Logger   Logger
+}
+
+type Server struct {
+	Address string
+	Port    string
+}
+
+type Rabbit struct {
+	Login    string
+	Pass     string
+	Address  string
+	Port     string
+	Exchange string
+	Queue    string
+	Key      string
+}
+
+type Logger struct {
+	File       string
+	Level      string
+	MuteStdout bool
+}
+
+type Storage struct {
+	InMemory bool
+	SQLHost  string
+	SQLPort  string
+	SQLDbase string
+	SQLUser  string
+	SQLPass  string
+}
diff --git a/hw12_13_14_15_calendar/internal/logger/logger.go b/hw12_13_14_15_calendar/pkg/logger/logger.go
similarity index 80%
rename from hw12_13_14_15_calendar/internal/logger/logger.go
rename to hw12_13_14_15_calendar/pkg/logger/logger.go
index 005ca88..c9fdfca 100644
--- a/hw12_13_14_15_calendar/internal/logger/logger.go
+++ b/hw12_13_14_15_calendar/pkg/logger/logger.go
@@ -7,7 +7,6 @@ import (
 	"strings"
 
 	amitralog "github.com/amitrai48/logger"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
 )
 
 type Interface interface {
@@ -22,21 +21,27 @@ type Logger struct {
 	Logger amitralog.Logger
 }
 
+type Config struct {
+	File       string
+	Level      string
+	MuteStdout bool
+}
+
 var validLevel = map[string]bool{"debug": true, "info": true, "warn": true, "error": true, "fatal": true}
 
-func New(conf config.Config) (Interface, error) {
-	if conf.Logger.File == "" || !validLevel[strings.ToLower(conf.Logger.Level)] {
+func New(conf Config) (Interface, error) {
+	if conf.File == "" || !validLevel[strings.ToLower(conf.Level)] {
 		return nil, errors.New("invalid logger config")
 	}
 
 	c := amitralog.Configuration{
-		EnableConsole:     !conf.Logger.MuteStdout,
+		EnableConsole:     !conf.MuteStdout,
 		ConsoleLevel:      amitralog.Fatal,
 		ConsoleJSONFormat: false,
 		EnableFile:        true,
-		FileLevel:         strings.ToLower(conf.Logger.Level),
+		FileLevel:         strings.ToLower(conf.Level),
 		FileJSONFormat:    true,
-		FileLocation:      conf.Logger.File,
+		FileLocation:      conf.File,
 	}
 
 	if err := amitralog.NewLogger(c, amitralog.InstanceZapLogger); err != nil {
diff --git a/hw12_13_14_15_calendar/internal/logger/logger_test.go b/hw12_13_14_15_calendar/pkg/logger/logger_test.go
similarity index 63%
rename from hw12_13_14_15_calendar/internal/logger/logger_test.go
rename to hw12_13_14_15_calendar/pkg/logger/logger_test.go
index 3efbd7d..edc4b28 100644
--- a/hw12_13_14_15_calendar/internal/logger/logger_test.go
+++ b/hw12_13_14_15_calendar/pkg/logger/logger_test.go
@@ -2,7 +2,6 @@ package logger
 
 import (
 	"github.com/stretchr/testify/require"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
 	"io/ioutil"
 	oslog "log"
 	"os"
@@ -17,11 +16,7 @@ func TestLoggerLogic(t *testing.T) {
 	}
 	defer os.Remove(tmpfile.Name())
 
-	conf := config.Config{Logger: struct {
-		File       string
-		Level      string
-		MuteStdout bool
-	}{File: tmpfile.Name(), Level: "warn", MuteStdout: false}}
+	conf := Config{File: tmpfile.Name(), Level: "warn", MuteStdout: false}
 	log, err := New(conf)
 	if err != nil {
 		oslog.Fatal(err)
@@ -42,21 +37,13 @@ func TestLoggerLogic(t *testing.T) {
 
 func TestLoggerNegative(t *testing.T) {
 	t.Run("Bad file name", func(t *testing.T) {
-		conf := config.Config{Logger: struct {
-			File       string
-			Level      string
-			MuteStdout bool
-		}{File: "", Level: "debug", MuteStdout: true}}
+		conf := Config{File: "", Level: "debug", MuteStdout: true}
 		_, err := New(conf)
 		require.Error(t, err, "invalid logger config")
 	})
 
 	t.Run("Bad level", func(t *testing.T) {
-		conf := config.Config{Logger: struct {
-			File       string
-			Level      string
-			MuteStdout bool
-		}{File: "asdafad", Level: "wegretryjt", MuteStdout: true}}
+		conf := Config{File: "asdafad", Level: "wegretryjt", MuteStdout: true}
 		_, err := New(conf)
 		require.Error(t, err, "invalid logger config")
 	})
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/consumer.go b/hw12_13_14_15_calendar/pkg/rabbit/consumer.go
new file mode 100644
index 0000000..8182005
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/rabbit/consumer.go
@@ -0,0 +1,52 @@
+package rabbit
+
+import (
+	"context"
+	"fmt"
+	"log"
+
+	"github.com/streadway/amqp"
+)
+
+type RMQConnection interface {
+	Channel() (*amqp.Channel, error)
+}
+
+type Message struct {
+	Ctx  context.Context
+	Data []byte
+}
+
+func (r *Rabbit) Consume(ctx context.Context, queue string) (<-chan Message, error) {
+	messages := make(chan Message)
+	deliveries, err := r.Channel.Consume(queue, "", false, false, false, false, nil)
+	if err != nil {
+		return nil, fmt.Errorf("start consuming: %w", err)
+	}
+
+	go func() {
+		for {
+			select {
+			case <-ctx.Done():
+				return
+			case del := <-deliveries:
+				if err := del.Ack(false); err != nil {
+					log.Println(err)
+				}
+
+				msg := Message{
+					Ctx:  context.TODO(),
+					Data: del.Body,
+				}
+
+				select {
+				case <-ctx.Done():
+					return
+				case messages <- msg:
+				}
+			}
+		}
+	}()
+
+	return messages, nil
+}
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/producer.go b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
new file mode 100644
index 0000000..b1c9b59
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
@@ -0,0 +1,27 @@
+package rabbit
+
+import (
+	"encoding/json"
+
+	"github.com/streadway/amqp"
+)
+
+func (r *Rabbit) Publish(body string) error {
+	b, err := json.Marshal([]byte(body))
+	if err != nil {
+		return err
+	}
+	err = r.Channel.Publish(
+		r.Exchange, // exchange
+		r.Key,      // routing key
+		false,      // mandatory
+		false,      // immediate
+		amqp.Publishing{
+			ContentType: "application/json; charset=utf-8",
+			Body:        b,
+		})
+	if err != nil {
+		return err
+	}
+	return nil
+}
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
new file mode 100644
index 0000000..a5a76d4
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
@@ -0,0 +1,84 @@
+package rabbit
+
+import (
+	"github.com/streadway/amqp"
+)
+
+type Rabbit struct {
+	Connection *amqp.Connection
+	Channel    *amqp.Channel
+	Exchange   string
+	Key        string
+	Queue      string
+}
+
+type Config struct {
+	Login    string
+	Pass     string
+	Address  string
+	Port     string
+	Exchange string
+	Queue    string
+	Key      string
+}
+
+func New(conf Config) (*Rabbit, error) {
+	conn, err := amqp.Dial("amqp://" + conf.Login + ":" + conf.Pass + "@" + conf.Address + ":" + conf.Port + "/")
+	if err != nil {
+		return nil, err
+	}
+	ch, err := conn.Channel()
+	if err != nil {
+		return nil, err
+	}
+	err = ch.ExchangeDeclare(
+		conf.Exchange, // name
+		"direct",      // type
+		true,          // durable
+		false,         // auto-deleted
+		false,         // internal
+		false,         // no-wait
+		nil,           // arguments
+	)
+	if err != nil {
+		return nil, err
+	}
+	q, err := ch.QueueDeclare(
+		conf.Queue,
+		false,
+		false,
+		false,
+		false,
+		nil,
+	)
+	if err != nil {
+		return nil, err
+	}
+	err = ch.QueueBind(q.Name, conf.Key, conf.Exchange, false, nil)
+	if err != nil {
+		return nil, err
+	}
+	return &Rabbit{Connection: conn, Channel: ch}, nil
+}
+
+func Attach(conf Config) (*Rabbit, error) {
+	conn, err := amqp.Dial("amqp://" + conf.Login + ":" + conf.Pass + "@" + conf.Address + ":" + conf.Port + "/")
+	if err != nil {
+		return nil, err
+	}
+	ch, err := conn.Channel()
+	if err != nil {
+		return nil, err
+	}
+	return &Rabbit{Connection: conn, Channel: ch, Exchange: conf.Exchange, Queue: conf.Queue, Key: conf.Key}, nil
+}
+
+func (r *Rabbit) Close() error {
+	if err := r.Channel.Close(); err != nil {
+		return err
+	}
+	if err := r.Connection.Close(); err != nil {
+		return err
+	}
+	return nil
+}
diff --git a/hw12_13_14_15_calendar/internal/storage/event/event.go b/hw12_13_14_15_calendar/pkg/storage/event/event.go
similarity index 92%
rename from hw12_13_14_15_calendar/internal/storage/event/event.go
rename to hw12_13_14_15_calendar/pkg/storage/event/event.go
index 1c4b4a8..e8b2b83 100644
--- a/hw12_13_14_15_calendar/internal/storage/event/event.go
+++ b/hw12_13_14_15_calendar/pkg/storage/event/event.go
@@ -13,4 +13,5 @@ type Event struct {
 	Note       string
 	UserID     int64
 	NotifyTime time.Duration
+	Notified   bool
 }
diff --git a/hw12_13_14_15_calendar/internal/storage/memory/memory.go b/hw12_13_14_15_calendar/pkg/storage/memory/memory.go
similarity index 78%
rename from hw12_13_14_15_calendar/internal/storage/memory/memory.go
rename to hw12_13_14_15_calendar/pkg/storage/memory/memory.go
index 4a1d909..4ed0356 100644
--- a/hw12_13_14_15_calendar/internal/storage/memory/memory.go
+++ b/hw12_13_14_15_calendar/pkg/storage/memory/memory.go
@@ -4,7 +4,7 @@ import (
 	"sync"
 	"time"
 
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
 type Storage struct {
@@ -65,6 +65,27 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 	return res, nil
 }
 
+func (s *Storage) GetNotifications() (map[event.ID]event.Event, error) {
+	s.Mu.Lock()
+	defer s.Mu.Unlock()
+	res := make(map[event.ID]event.Event)
+	for k, v := range s.Events {
+		if time.Until(v.Date) <= v.NotifyTime && !v.Notified {
+			res[k] = v
+		}
+	}
+	return res, nil
+}
+
+func (s *Storage) SetNotified(id event.ID) error {
+	s.Mu.Lock()
+	tmp := s.Events[id]
+	tmp.Notified = true
+	s.Events[id] = tmp
+	s.Mu.Unlock()
+	return nil
+}
+
 func getEndDate(startDate time.Time, rng string) time.Time {
 	switch rng {
 	case "DAY":
diff --git a/hw12_13_14_15_calendar/internal/storage/memory/memory_test.go b/hw12_13_14_15_calendar/pkg/storage/memory/memory_test.go
similarity index 95%
rename from hw12_13_14_15_calendar/internal/storage/memory/memory_test.go
rename to hw12_13_14_15_calendar/pkg/storage/memory/memory_test.go
index 5735453..4012106 100644
--- a/hw12_13_14_15_calendar/internal/storage/memory/memory_test.go
+++ b/hw12_13_14_15_calendar/pkg/storage/memory/memory_test.go
@@ -2,7 +2,7 @@ package memory
 
 import (
 	"github.com/stretchr/testify/require"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 	"testing"
 	"time"
 )
diff --git a/hw12_13_14_15_calendar/internal/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
similarity index 78%
rename from hw12_13_14_15_calendar/internal/storage/sql/sql.go
rename to hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index 97667ea..0aefdfc 100644
--- a/hw12_13_14_15_calendar/internal/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -4,7 +4,7 @@ import (
 	"database/sql"
 	"time"
 
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
 const dateTimeLayout = "2006-01-02 15:04:00 -0700"
@@ -159,6 +159,48 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 	return res, nil
 }
 
+func (s *Storage) GetNotifications() (map[event.ID]event.Event, error) {
+	res := make(map[event.ID]event.Event)
+	results, err := s.db.Query(
+		`SELECT (id,title,date,latency,note,userID,notifyTime)
+				from events
+				where 	($1>date-notifyTime) AND (NOT notified)
+				ORDER BY id`,
+		time.Now())
+	if err != nil {
+		return nil, err
+	}
+	defer results.Close()
+	for results.Next() {
+		var id event.ID
+		var evt event.Event
+		var dateRaw string
+		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
+		if err != nil {
+			return nil, err
+		}
+		evt.Date, err = time.Parse(dateTimeLayout, dateRaw)
+		if err != nil {
+			return nil, err
+		}
+		res[id] = evt
+	}
+	if results.Err() != nil {
+		return nil, results.Err()
+	}
+	return res, nil
+}
+
+func (s *Storage) SetNotified(id event.ID) error {
+	_, err := s.db.Exec(
+		`UPDATE events set 
+		notified=true 
+		where id=$1`,
+		id,
+	)
+	return err
+}
+
 func getEndDate(startDate time.Time, rng string) time.Time {
 	switch rng {
 	case "DAY":
diff --git a/hw12_13_14_15_calendar/internal/storage/store.go b/hw12_13_14_15_calendar/pkg/storage/store.go
similarity index 80%
rename from hw12_13_14_15_calendar/internal/storage/store.go
rename to hw12_13_14_15_calendar/pkg/storage/store.go
index 741b651..642c595 100644
--- a/hw12_13_14_15_calendar/internal/storage/store.go
+++ b/hw12_13_14_15_calendar/pkg/storage/store.go
@@ -3,9 +3,9 @@ package store
 import (
 	"time"
 
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
-	memorystorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/memory"
-	sqlstorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/sql"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	memorystorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/memory"
+	sqlstorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/sql"
 )
 
 type Config struct {
@@ -24,6 +24,8 @@ type StorageInterface interface {
 	List() (map[event.ID]event.Event, error)
 	GetByID(event.ID) (event.Event, bool)
 	GetByDate(time.Time, string) (map[event.ID]event.Event, error)
+	GetNotifications() (map[event.ID]event.Event, error)
+	SetNotified(event.ID) error
 }
 
 func NewStore(conf Config) StorageInterface {

From 63c008f963f6add39e05ab372235f4d9ad3d75fb Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 23 Nov 2020 17:18:30 +0300
Subject: [PATCH 02/20] HW14 Completed

---
 .../api/private/grpcserver.proto              |   8 +
 .../internal/api/private/grpcserver.pb.go     | 160 +++++++++++++++---
 .../internal/api/private/handlers.go          |   5 +
 .../pkg/storage/memory/memory.go              |  13 ++
 hw12_13_14_15_calendar/pkg/storage/sql/sql.go |  11 ++
 hw12_13_14_15_calendar/pkg/storage/store.go   |   1 +
 6 files changed, 178 insertions(+), 20 deletions(-)

diff --git a/hw12_13_14_15_calendar/api/private/grpcserver.proto b/hw12_13_14_15_calendar/api/private/grpcserver.proto
index 8db4a9e..226ff27 100644
--- a/hw12_13_14_15_calendar/api/private/grpcserver.proto
+++ b/hw12_13_14_15_calendar/api/private/grpcserver.proto
@@ -11,6 +11,7 @@ import "google/protobuf/empty.proto";
 service grpc {
   rpc GetNotifications(google.protobuf.Empty) returns (GetRsp) {}
   rpc SetNotified(SetReq) returns (google.protobuf.Empty) {}
+  rpc PurgeOldEvents(PurgeReq) returns (PurgeResp) {}
 }
 
 message GetRsp {
@@ -20,6 +21,13 @@ message GetRsp {
 message SetReq {
   int64 ID  = 1;
 }
+message PurgeReq {
+  int64 OlderThenDays = 1;
+}
+
+message PurgeResp {
+  int64 Qty = 1;
+}
 
 message Event {
   int64 ID  = 1;
diff --git a/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go b/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
index cb6e1ba..bcaad71 100644
--- a/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
+++ b/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
@@ -104,6 +104,84 @@ func (m *SetReq) GetID() int64 {
 	return 0
 }
 
+type PurgeReq struct {
+	OlderThenDays        int64    `protobuf:"varint,1,opt,name=OlderThenDays,proto3" json:"OlderThenDays,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *PurgeReq) Reset()         { *m = PurgeReq{} }
+func (m *PurgeReq) String() string { return proto.CompactTextString(m) }
+func (*PurgeReq) ProtoMessage()    {}
+func (*PurgeReq) Descriptor() ([]byte, []int) {
+	return fileDescriptor_afa6debe97205904, []int{2}
+}
+
+func (m *PurgeReq) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_PurgeReq.Unmarshal(m, b)
+}
+func (m *PurgeReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_PurgeReq.Marshal(b, m, deterministic)
+}
+func (m *PurgeReq) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_PurgeReq.Merge(m, src)
+}
+func (m *PurgeReq) XXX_Size() int {
+	return xxx_messageInfo_PurgeReq.Size(m)
+}
+func (m *PurgeReq) XXX_DiscardUnknown() {
+	xxx_messageInfo_PurgeReq.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_PurgeReq proto.InternalMessageInfo
+
+func (m *PurgeReq) GetOlderThenDays() int64 {
+	if m != nil {
+		return m.OlderThenDays
+	}
+	return 0
+}
+
+type PurgeResp struct {
+	Qty                  int64    `protobuf:"varint,1,opt,name=Qty,proto3" json:"Qty,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *PurgeResp) Reset()         { *m = PurgeResp{} }
+func (m *PurgeResp) String() string { return proto.CompactTextString(m) }
+func (*PurgeResp) ProtoMessage()    {}
+func (*PurgeResp) Descriptor() ([]byte, []int) {
+	return fileDescriptor_afa6debe97205904, []int{3}
+}
+
+func (m *PurgeResp) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_PurgeResp.Unmarshal(m, b)
+}
+func (m *PurgeResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_PurgeResp.Marshal(b, m, deterministic)
+}
+func (m *PurgeResp) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_PurgeResp.Merge(m, src)
+}
+func (m *PurgeResp) XXX_Size() int {
+	return xxx_messageInfo_PurgeResp.Size(m)
+}
+func (m *PurgeResp) XXX_DiscardUnknown() {
+	xxx_messageInfo_PurgeResp.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_PurgeResp proto.InternalMessageInfo
+
+func (m *PurgeResp) GetQty() int64 {
+	if m != nil {
+		return m.Qty
+	}
+	return 0
+}
+
 type Event struct {
 	ID                   int64                `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
 	Title                string               `protobuf:"bytes,2,opt,name=Title,proto3" json:"Title,omitempty"`
@@ -118,7 +196,7 @@ func (m *Event) Reset()         { *m = Event{} }
 func (m *Event) String() string { return proto.CompactTextString(m) }
 func (*Event) ProtoMessage()    {}
 func (*Event) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{2}
+	return fileDescriptor_afa6debe97205904, []int{4}
 }
 
 func (m *Event) XXX_Unmarshal(b []byte) error {
@@ -170,31 +248,37 @@ func (m *Event) GetUserID() int64 {
 func init() {
 	proto.RegisterType((*GetRsp)(nil), "private.GetRsp")
 	proto.RegisterType((*SetReq)(nil), "private.SetReq")
+	proto.RegisterType((*PurgeReq)(nil), "private.PurgeReq")
+	proto.RegisterType((*PurgeResp)(nil), "private.PurgeResp")
 	proto.RegisterType((*Event)(nil), "private.Event")
 }
 
 func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
 
 var fileDescriptor_afa6debe97205904 = []byte{
-	// 286 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4f, 0x6b, 0x32, 0x31,
-	0x10, 0x87, 0x5d, 0xff, 0xec, 0x8b, 0x23, 0xf8, 0x4a, 0x28, 0x12, 0xb6, 0x87, 0x2e, 0x7b, 0x28,
-	0x7b, 0x8a, 0xc5, 0x5e, 0x7a, 0xe9, 0xa5, 0xac, 0x88, 0x97, 0x1e, 0xa2, 0xbd, 0xf4, 0xb6, 0xda,
-	0x51, 0x02, 0x6a, 0xd2, 0x64, 0x5c, 0xe8, 0xa9, 0x5f, 0xbd, 0x98, 0xec, 0xb6, 0x60, 0xe9, 0x71,
-	0xe6, 0xf7, 0x64, 0x32, 0x4f, 0x02, 0xa3, 0x9d, 0x35, 0x1b, 0x87, 0xb6, 0x42, 0x2b, 0x8c, 0xd5,
-	0xa4, 0xd9, 0x3f, 0x63, 0x55, 0x55, 0x12, 0x26, 0x37, 0x3b, 0xad, 0x77, 0x7b, 0x9c, 0xf8, 0xf6,
-	0xfa, 0xb4, 0x9d, 0x90, 0x3a, 0xa0, 0xa3, 0xf2, 0x60, 0x02, 0x99, 0x5c, 0x5f, 0x02, 0x78, 0x30,
-	0xf4, 0x11, 0xc2, 0xec, 0x0e, 0xe2, 0x39, 0x92, 0x74, 0x86, 0xdd, 0x42, 0x3c, 0xab, 0xf0, 0x48,
-	0x8e, 0x47, 0x69, 0x27, 0x1f, 0x4c, 0x87, 0xa2, 0xbe, 0x41, 0xf8, 0xb6, 0xac, 0xd3, 0x8c, 0x43,
-	0xbc, 0x44, 0x92, 0xf8, 0xce, 0x86, 0xd0, 0x5e, 0x14, 0x3c, 0x4a, 0xa3, 0xbc, 0x23, 0xdb, 0x8b,
-	0x22, 0x3b, 0x41, 0xcf, 0x33, 0x97, 0x01, 0xbb, 0x82, 0xde, 0x4a, 0xd1, 0x1e, 0x79, 0x3b, 0x8d,
-	0xf2, 0xbe, 0x0c, 0x05, 0x13, 0xd0, 0x2d, 0x4a, 0x42, 0xde, 0x49, 0xa3, 0x7c, 0x30, 0x4d, 0x44,
-	0x58, 0x53, 0x34, 0x6b, 0x8a, 0x55, 0xe3, 0x21, 0x3d, 0xc7, 0xc6, 0x10, 0xbf, 0x38, 0xb4, 0x8b,
-	0x82, 0x77, 0xfd, 0xe4, 0xba, 0x9a, 0x7e, 0x42, 0xf7, 0xfc, 0x3a, 0xec, 0x11, 0x46, 0x73, 0xa4,
-	0x67, 0x4d, 0x6a, 0xab, 0x36, 0x25, 0x29, 0x7d, 0x74, 0x6c, 0xfc, 0x6b, 0xea, 0xec, 0x2c, 0x9f,
-	0xfc, 0xff, 0x96, 0x0b, 0xf6, 0x59, 0x8b, 0x3d, 0xc0, 0x60, 0xd9, 0x1c, 0xc7, 0x37, 0xf6, 0x43,
-	0x04, 0xdb, 0xe4, 0x8f, 0x51, 0x59, 0xeb, 0xa9, 0xff, 0xda, 0x7c, 0xc6, 0x3a, 0xf6, 0xe1, 0xfd,
-	0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x5f, 0x05, 0xc6, 0xb0, 0x01, 0x00, 0x00,
+	// 351 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x6b, 0xea, 0x50,
+	0x10, 0x85, 0x8d, 0xd1, 0xbc, 0xe7, 0xc8, 0xf3, 0xf9, 0x86, 0x87, 0x84, 0x94, 0xd2, 0x10, 0x4a,
+	0xc9, 0x2a, 0x8a, 0xdd, 0xb4, 0x8b, 0x6e, 0x4a, 0x44, 0xdc, 0xd4, 0x36, 0xda, 0x4d, 0x77, 0x51,
+	0xc7, 0x34, 0x10, 0x4d, 0x7a, 0xef, 0x28, 0xf8, 0xd7, 0xfa, 0xeb, 0x4a, 0x72, 0x13, 0x4b, 0x2d,
+	0xdd, 0xe5, 0x9e, 0x39, 0x73, 0x0e, 0xf3, 0x11, 0xe8, 0x46, 0x22, 0x5b, 0x4a, 0x12, 0x7b, 0x12,
+	0x5e, 0x26, 0x52, 0x4e, 0xf1, 0x57, 0x26, 0xe2, 0x7d, 0xc8, 0x64, 0x5d, 0x44, 0x69, 0x1a, 0x25,
+	0xd4, 0x2f, 0xe4, 0xc5, 0x6e, 0xdd, 0xe7, 0x78, 0x43, 0x92, 0xc3, 0x4d, 0xa6, 0x9c, 0xd6, 0xd9,
+	0xa9, 0x81, 0x36, 0x19, 0x1f, 0xd4, 0xd0, 0x19, 0x80, 0x31, 0x26, 0x0e, 0x64, 0x86, 0x57, 0x60,
+	0x8c, 0xf6, 0xb4, 0x65, 0x69, 0x6a, 0xb6, 0xee, 0xb6, 0x87, 0x1d, 0xaf, 0x6c, 0xf0, 0x0a, 0x39,
+	0x28, 0xa7, 0x8e, 0x09, 0xc6, 0x8c, 0x38, 0xa0, 0x37, 0xec, 0x40, 0x7d, 0xe2, 0x9b, 0x9a, 0xad,
+	0xb9, 0x7a, 0x50, 0x9f, 0xf8, 0xce, 0x00, 0x7e, 0x3f, 0xee, 0x44, 0x44, 0xf9, 0xec, 0x12, 0xfe,
+	0x4c, 0x93, 0x15, 0x89, 0xf9, 0x2b, 0x6d, 0xfd, 0xf0, 0x20, 0x4b, 0xdb, 0x57, 0xd1, 0x39, 0x87,
+	0x56, 0xb9, 0x21, 0x33, 0xec, 0x82, 0xfe, 0xc4, 0x87, 0xd2, 0x98, 0x7f, 0x3a, 0x3b, 0x68, 0x16,
+	0xa5, 0xa7, 0x4d, 0xf8, 0x1f, 0x9a, 0xf3, 0x98, 0x13, 0x32, 0xeb, 0xb6, 0xe6, 0xb6, 0x02, 0xf5,
+	0x40, 0x0f, 0x1a, 0x7e, 0xc8, 0x64, 0xea, 0xb6, 0xe6, 0xb6, 0x87, 0x96, 0xa7, 0xee, 0xf6, 0xaa,
+	0xbb, 0xbd, 0x79, 0x05, 0x26, 0x28, 0x7c, 0xd8, 0x03, 0xe3, 0x59, 0x92, 0x98, 0xf8, 0x66, 0xa3,
+	0x48, 0x2e, 0x5f, 0xc3, 0x77, 0x0d, 0x1a, 0x39, 0x6f, 0xbc, 0x83, 0xee, 0x98, 0xf8, 0x21, 0xe5,
+	0x78, 0x1d, 0x2f, 0x43, 0x8e, 0xd3, 0xad, 0xc4, 0xde, 0xb7, 0xd8, 0x51, 0x8e, 0xd3, 0xfa, 0x7b,
+	0xc4, 0xa5, 0x78, 0x3a, 0x35, 0xbc, 0x81, 0xf6, 0xac, 0x5a, 0xa7, 0x15, 0x7e, 0x3a, 0x14, 0x3f,
+	0xeb, 0x87, 0x28, 0xa7, 0x86, 0xb7, 0xd0, 0x29, 0xb8, 0x4c, 0x93, 0x95, 0xa2, 0x8e, 0xff, 0x8e,
+	0xcb, 0x15, 0x62, 0x0b, 0x4f, 0xa5, 0xbc, 0xf4, 0xbe, 0xf5, 0x52, 0xfd, 0x19, 0x0b, 0xa3, 0xc8,
+	0xbd, 0xfe, 0x08, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xac, 0x01, 0x89, 0x3d, 0x02, 0x00, 0x00,
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -211,6 +295,7 @@ const _ = grpc.SupportPackageIsVersion4
 type GrpcClient interface {
 	GetNotifications(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*GetRsp, error)
 	SetNotified(ctx context.Context, in *SetReq, opts ...grpc.CallOption) (*empty.Empty, error)
+	PurgeOldEvents(ctx context.Context, in *PurgeReq, opts ...grpc.CallOption) (*PurgeResp, error)
 }
 
 type grpcClient struct {
@@ -239,10 +324,20 @@ func (c *grpcClient) SetNotified(ctx context.Context, in *SetReq, opts ...grpc.C
 	return out, nil
 }
 
+func (c *grpcClient) PurgeOldEvents(ctx context.Context, in *PurgeReq, opts ...grpc.CallOption) (*PurgeResp, error) {
+	out := new(PurgeResp)
+	err := c.cc.Invoke(ctx, "/private.grpc/PurgeOldEvents", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // GrpcServer is the server API for Grpc service.
 type GrpcServer interface {
 	GetNotifications(context.Context, *empty.Empty) (*GetRsp, error)
 	SetNotified(context.Context, *SetReq) (*empty.Empty, error)
+	PurgeOldEvents(context.Context, *PurgeReq) (*PurgeResp, error)
 }
 
 // UnimplementedGrpcServer can be embedded to have forward compatible implementations.
@@ -255,6 +350,9 @@ func (*UnimplementedGrpcServer) GetNotifications(ctx context.Context, req *empty
 func (*UnimplementedGrpcServer) SetNotified(ctx context.Context, req *SetReq) (*empty.Empty, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method SetNotified not implemented")
 }
+func (*UnimplementedGrpcServer) PurgeOldEvents(ctx context.Context, req *PurgeReq) (*PurgeResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method PurgeOldEvents not implemented")
+}
 
 func RegisterGrpcServer(s *grpc.Server, srv GrpcServer) {
 	s.RegisterService(&_Grpc_serviceDesc, srv)
@@ -296,6 +394,24 @@ func _Grpc_SetNotified_Handler(srv interface{}, ctx context.Context, dec func(in
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Grpc_PurgeOldEvents_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(PurgeReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(GrpcServer).PurgeOldEvents(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/private.grpc/PurgeOldEvents",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(GrpcServer).PurgeOldEvents(ctx, req.(*PurgeReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 var _Grpc_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "private.grpc",
 	HandlerType: (*GrpcServer)(nil),
@@ -308,6 +424,10 @@ var _Grpc_serviceDesc = grpc.ServiceDesc{
 			MethodName: "SetNotified",
 			Handler:    _Grpc_SetNotified_Handler,
 		},
+		{
+			MethodName: "PurgeOldEvents",
+			Handler:    _Grpc_PurgeOldEvents_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "grpcserver.proto",
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers.go b/hw12_13_14_15_calendar/internal/api/private/handlers.go
index 21277af..308c7b1 100644
--- a/hw12_13_14_15_calendar/internal/api/private/handlers.go
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers.go
@@ -29,3 +29,8 @@ func (s Service) GetNotifications(ctx context.Context, e *empty.Empty) (*GetRsp,
 func (s Service) SetNotified(ctx context.Context, r *SetReq) (*empty.Empty, error) {
 	return nil, s.App.Storage.SetNotified(event.ID(r.ID))
 }
+
+func (s Service) PurgeOldEvents(ctx context.Context, r *PurgeReq) (*PurgeResp, error) {
+	q, err := s.App.Storage.PurgeOldEvents(r.OlderThenDays)
+	return &PurgeResp{Qty: q}, err
+}
diff --git a/hw12_13_14_15_calendar/pkg/storage/memory/memory.go b/hw12_13_14_15_calendar/pkg/storage/memory/memory.go
index 4ed0356..46eecf4 100644
--- a/hw12_13_14_15_calendar/pkg/storage/memory/memory.go
+++ b/hw12_13_14_15_calendar/pkg/storage/memory/memory.go
@@ -86,6 +86,19 @@ func (s *Storage) SetNotified(id event.ID) error {
 	return nil
 }
 
+func (s *Storage) PurgeOldEvents(days int64) (res int64, err error) {
+	s.Mu.Lock()
+	defer s.Mu.Unlock()
+	seconds := time.Duration(days * 24 * 60 * 60)
+	for k, v := range s.Events {
+		if v.Date.Before(time.Now().Add(-seconds)) {
+			delete(s.Events, k)
+			res++
+		}
+	}
+	return res, err
+}
+
 func getEndDate(startDate time.Time, rng string) time.Time {
 	switch rng {
 	case "DAY":
diff --git a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index 0aefdfc..f5884cc 100644
--- a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -201,6 +201,17 @@ func (s *Storage) SetNotified(id event.ID) error {
 	return err
 }
 
+func (s *Storage) PurgeOldEvents(days int64) (int64, error) {
+	r, err := s.db.Exec(
+		`DELETE from events where date<$1`,
+		time.Now().Add(-time.Duration(days*24*60*60)),
+	)
+	if err != nil {
+		return 0, err
+	}
+	return r.RowsAffected()
+}
+
 func getEndDate(startDate time.Time, rng string) time.Time {
 	switch rng {
 	case "DAY":
diff --git a/hw12_13_14_15_calendar/pkg/storage/store.go b/hw12_13_14_15_calendar/pkg/storage/store.go
index 642c595..05b8ac6 100644
--- a/hw12_13_14_15_calendar/pkg/storage/store.go
+++ b/hw12_13_14_15_calendar/pkg/storage/store.go
@@ -26,6 +26,7 @@ type StorageInterface interface {
 	GetByDate(time.Time, string) (map[event.ID]event.Event, error)
 	GetNotifications() (map[event.ID]event.Event, error)
 	SetNotified(event.ID) error
+	PurgeOldEvents(int64) (int64, error)
 }
 
 func NewStore(conf Config) StorageInterface {

From 04241cb809695f3cae168432aa3a2151366d4a28 Mon Sep 17 00:00:00 2001
From: tiburon <BGv255215S>
Date: Mon, 23 Nov 2020 17:25:21 +0300
Subject: [PATCH 03/20] HW14 Completed

---
 hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go | 2 +-
 hw12_13_14_15_calendar/internal/sheduler/scheduler.go     | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
index bb27d41..166f775 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
@@ -36,7 +36,7 @@ func New(conf Config) Scheduler {
 }
 
 func (s *Scheduler) Start(ctx context.Context) error {
-	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit) }, 1*time.Minute)
+	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit, s.Logger) }, 1*time.Minute)
 	go func() {
 		for {
 			select {
diff --git a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
index 6e99db8..8b309ee 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
@@ -37,7 +37,7 @@ func riseOnTick(ctx context.Context, log logger.Interface, fn func() interface{}
 	return valueStream
 }
 
-func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit) error {
+func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit, log logger.Interface) error {
 	cli, err := private.NewClient(calendarAPI.Address, calendarAPI.Port)
 	if err != nil {
 		return err
@@ -56,5 +56,10 @@ func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit) e
 			return err
 		}
 	}
+	resp2, err := cli.PurgeOldEvents(ctx, &private.PurgeReq{OlderThenDays: 365})
+	if err != nil {
+		return err
+	}
+	log.Infof("Scheduler successfully purges %s events from storage", resp2.Qty)
 	return nil
 }

From b9b297500e55fc8b79845df6798b4c4dfbbc5dc7 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Wed, 25 Nov 2020 15:39:22 +0300
Subject: [PATCH 04/20] HW15 WIP

---
 .golangci.yml                                 |   3 +-
 hw12_13_14_15_calendar/Makefile               |  14 ++-
 .../{grpcserver.proto => private.proto}       |   0
 .../public/{grpcserver.proto => public.proto} |   0
 .../cicd/calendar/Dockerfile                  |  28 +++++
 .../cicd/docker-compose.yml                   |  24 +++-
 .../cicd/scheduler/Dockerfile                 |  22 ++++
 hw12_13_14_15_calendar/cicd/sender/Dockerfile |  20 ++++
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  17 +--
 hw12_13_14_15_calendar/cmd/scheduler/main.go  |   2 +-
 hw12_13_14_15_calendar/configs/calendar.conf  |   6 +-
 hw12_13_14_15_calendar/go.mod                 |   3 +-
 hw12_13_14_15_calendar/go.sum                 |   2 +
 .../{grpcserver.pb.go => private.pb.go}       |  64 +++++-----
 .../internal/api/private/server.go            |   2 +-
 .../public/{grpcserver.pb.go => public.pb.go} | 109 +++++++++---------
 .../{grpcserver.pb.gw.go => public.pb.gw.go}  |   2 +-
 .../pkg/api/public/server.go                  |   2 +-
 hw12_13_14_15_calendar/pkg/config/config.go   |  57 ++++++++-
 .../pkg/config/config_test.go                 |  29 +++++
 hw12_13_14_15_calendar/pkg/logger/logger.go   |   1 +
 21 files changed, 293 insertions(+), 114 deletions(-)
 rename hw12_13_14_15_calendar/api/private/{grpcserver.proto => private.proto} (100%)
 rename hw12_13_14_15_calendar/api/public/{grpcserver.proto => public.proto} (100%)
 create mode 100644 hw12_13_14_15_calendar/cicd/calendar/Dockerfile
 create mode 100644 hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
 create mode 100644 hw12_13_14_15_calendar/cicd/sender/Dockerfile
 rename hw12_13_14_15_calendar/internal/api/private/{grpcserver.pb.go => private.pb.go} (82%)
 rename hw12_13_14_15_calendar/pkg/api/public/{grpcserver.pb.go => public.pb.go} (84%)
 rename hw12_13_14_15_calendar/pkg/api/public/{grpcserver.pb.gw.go => public.pb.gw.go} (99%)

diff --git a/.golangci.yml b/.golangci.yml
index edebcda..4e7fa91 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -16,4 +16,5 @@ linters:
     - gofumpt
     - gosec
     - nlreturn
-    - gocritic
\ No newline at end of file
+    - gocritic
+    - exhaustive
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 08daa51..c3df0b2 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -19,12 +19,16 @@ install-lint-deps:
 	(which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.30.0
 
 generate:
-	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public --grpc-gateway_out=logtostderr=true:./pkg/api/public ./api/public/grpcserver.proto
-	protoc  -I ./api/private  --go_out=plugins=grpc:./internal/api/private ./api/private/grpcserver.proto
+	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public --grpc-gateway_out=logtostderr=true:./pkg/api/public ./api/public/public.proto
+	protoc  -I ./api/private  --go_out=plugins=grpc:./internal/api/private ./api/private/private.proto
 
-rabbit-start:
-	sudo -S docker-compose -f ./cicd/docker-compose.yml up --build -d
-rabbit-stop:
+compose-build:
+	sudo -S docker-compose -f ./cicd/docker-compose.yml build
+
+compose-up:
+	sudo -S docker-compose -f ./cicd/docker-compose.yml up -d
+
+compose-down:
 	sudo -S docker-compose -f ./cicd/docker-compose.yml down
 
 calendar-start:
diff --git a/hw12_13_14_15_calendar/api/private/grpcserver.proto b/hw12_13_14_15_calendar/api/private/private.proto
similarity index 100%
rename from hw12_13_14_15_calendar/api/private/grpcserver.proto
rename to hw12_13_14_15_calendar/api/private/private.proto
diff --git a/hw12_13_14_15_calendar/api/public/grpcserver.proto b/hw12_13_14_15_calendar/api/public/public.proto
similarity index 100%
rename from hw12_13_14_15_calendar/api/public/grpcserver.proto
rename to hw12_13_14_15_calendar/api/public/public.proto
diff --git a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
new file mode 100644
index 0000000..c40664f
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
@@ -0,0 +1,28 @@
+FROM golang:1.14 as builder
+RUN mkdir -p /app
+WORKDIR /app
+COPY . .
+RUN go get -d ./cmd/calendar/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o calendar ./cmd/calendar/.
+
+FROM alpine:latest
+ENV APP_GRPC_ADDRESS=0.0.0.0
+ENV APP_GRPC_PORT=50051
+ENV APP_HTTP_ADDRESS=0.0.0.0
+ENV APP_HTTP_PORT=8888
+ENV APP_API_ADDRESS=0.0.0.0
+ENV APP_API_PORT=50053
+ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_LEVEL=INFO
+ENV APP_STORAGE_INMEMORY=true
+ENV APP_STORAGE_SQLHOST=psql
+ENV APP_STORAGE_SQLPORT=5432
+ENV APP_STORAGE_SQLDBASE=calendar
+ENV APP_STORAGE_SQLUSER=calendar
+ENV APP_STORAGE_SQLPASS=12345678
+WORKDIR /
+COPY --from=builder /app/calendar ./sbin
+EXPOSE ${APP_GRPC_PORT}
+EXPOSE ${APP_HTTP_PORT}
+EXPOSE ${APP_API_PORT}
+CMD ["calendar"]
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
index beb06ef..414b897 100644
--- a/hw12_13_14_15_calendar/cicd/docker-compose.yml
+++ b/hw12_13_14_15_calendar/cicd/docker-compose.yml
@@ -14,4 +14,26 @@ services:
       - "15672:15672"
     expose:
       - 5672
-      - 15672
\ No newline at end of file
+      - 15672
+  calendar:
+    build:
+      context: ..
+      dockerfile: ./cicd/calendar/Dockerfile
+    ports:
+      - 50051:50051
+      - 50053:50053
+      - 8888:8888
+    volumes:
+      - ../calendar.log:/calendar.log
+  scheduler:
+    build:
+      context: ..
+      dockerfile: ./cicd/scheduler/Dockerfile
+    volumes:
+      - ../calendar.log:/calendar.log
+  sender:
+    build:
+      context: ..
+      dockerfile: ./cicd/sender/Dockerfile
+    volumes:
+      - ../calendar.log:/calendar.log
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
new file mode 100644
index 0000000..a7a1c23
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
@@ -0,0 +1,22 @@
+FROM golang:1.14 as builder
+RUN mkdir -p /app
+WORKDIR /app
+COPY . .
+RUN go get -d ./cmd/scheduler/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o scheduler ./cmd/scheduler/.
+
+FROM alpine:latest
+ENV APP_RABBITMQ_ADDRESS=rabbitmq
+ENV APP_RABBITMQ_PORT=5672
+ENV APP_RABBITMQ_LOGIN=rabbit
+ENV APP_RABBITMQ_PASS=rabbit
+ENV APP_RABBITMQ_EXCHANGE=calendar
+ENV APP_RABBITMQ_QUEUE=notifications
+ENV APP_RABBITMQ_KEY=events
+ENV APP_API_ADDRESS=calendar
+ENV APP_API_PORT=50053
+ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_LEVEL=INFO
+WORKDIR /
+COPY --from=builder /app/scheduler ./sbin
+CMD ["scheduler"]
diff --git a/hw12_13_14_15_calendar/cicd/sender/Dockerfile b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
new file mode 100644
index 0000000..a4345ea
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
@@ -0,0 +1,20 @@
+FROM golang:1.14 as builder
+RUN mkdir -p /app
+WORKDIR /app
+COPY . .
+RUN go get -d ./cmd/sender/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o sender ./cmd/sender/.
+
+FROM alpine:latest
+ENV APP_RABBITMQ_ADDRESS=rabbitmq
+ENV APP_RABBITMQ_PORT=5672
+ENV APP_RABBITMQ_LOGIN=rabbit
+ENV APP_RABBITMQ_PASS=rabbit
+ENV APP_RABBITMQ_EXCHANGE=calendar
+ENV APP_RABBITMQ_QUEUE=notifications
+ENV APP_RABBITMQ_KEY=events
+ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_LEVEL=INFO
+WORKDIR /
+COPY --from=builder /app/sender ./sbin
+CMD ["sender"]
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index 182c864..c7fedd3 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -24,7 +24,7 @@ import (
 var configFile string
 
 func init() {
-	flag.StringVar(&configFile, "config", "/etc/calendar.conf", "Path to configuration file")
+	flag.StringVar(&configFile, "config", "", "Path to configuration file")
 	flag.Parse()
 }
 
@@ -34,19 +34,14 @@ func main() {
 	if err != nil {
 		oslog.Fatal("не удалось открыть файл конфигурации:", err.Error())
 	}
+	oslog.Printf("Переменная APP_GRPC_PORT: %#v", os.Getenv("APP_GRPC_PORT"))
+	oslog.Printf("Конфиг приложения: %#v", conf)
 	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
 		oslog.Fatal("не удалось запустить логер:", err.Error())
 	}
-	storeConf := store.Config{
-		InMemory: conf.Storage.InMemory,
-		SQLHost:  conf.Storage.SQLHost,
-		SQLPort:  conf.Storage.SQLPort,
-		SQLDbase: conf.Storage.SQLDbase,
-		SQLUser:  conf.Storage.SQLUser,
-		SQLPass:  conf.Storage.SQLPass,
-	}
-	st := store.NewStore(storeConf)
+
+	st := store.NewStore(store.Config(conf.Storage))
 
 	calendar := calendar.New(log, st)
 
@@ -83,7 +78,7 @@ func main() {
 	mux := http.NewServeMux()
 	mux.Handle("/", grpcGwRouter)
 	go func() {
-		log.Infof("start webAPI server")
+		log.Infof("webAPI server starting")
 		if err := http.ListenAndServe(net.JoinHostPort(conf.HTTP.Address, conf.HTTP.Port), mux); err != nil {
 			log.Errorf("failed to start webAPI server: " + err.Error())
 			os.Exit(1)
diff --git a/hw12_13_14_15_calendar/cmd/scheduler/main.go b/hw12_13_14_15_calendar/cmd/scheduler/main.go
index 5793fc3..bc9fae4 100644
--- a/hw12_13_14_15_calendar/cmd/scheduler/main.go
+++ b/hw12_13_14_15_calendar/cmd/scheduler/main.go
@@ -16,7 +16,7 @@ import (
 var configFile string
 
 func init() {
-	flag.StringVar(&configFile, "config", "/etc/scheduler.conf", "Path to configuration file")
+	flag.StringVar(&configFile, "config", "", "Path to configuration file")
 	flag.Parse()
 }
 
diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index e787d79..21dc460 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -1,13 +1,13 @@
 [Grpc]
-Address = "localhost"
+Address = "0.0.0.0"
 Port = "50051"
 
 [HTTP]
-Address = "localhost"
+Address = "0.0.0.0"
 Port = "50052"
 
 [API]
-Address = "localhost"
+Address = "0.0.0.0"
 Port = "50053"
 
 [Logger]
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index aa61bd3..d78efb5 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -9,8 +9,9 @@ require (
 	github.com/golang/protobuf v1.4.2
 	github.com/grpc-ecosystem/grpc-gateway v1.15.0
 	github.com/kr/text v0.2.0 // indirect
+	github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
-	github.com/pkg/errors v0.9.1 // indirect
+	github.com/pkg/errors v0.9.1
 	github.com/sirupsen/logrus v1.4.2 // indirect
 	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index 9358aa9..8061704 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -54,6 +54,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397 h1:fbcg7+DIrrjxSsS78ARgJu/qZOO928w4mCj1KBEO7xM=
+github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397/go.mod h1:BvJngicNxsNmAUzt7zXpaoWKwuBiyxnD7DxzxfrrPyY=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
diff --git a/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go b/hw12_13_14_15_calendar/internal/api/private/private.pb.go
similarity index 82%
rename from hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
rename to hw12_13_14_15_calendar/internal/api/private/private.pb.go
index bcaad71..601fedf 100644
--- a/hw12_13_14_15_calendar/internal/api/private/grpcserver.pb.go
+++ b/hw12_13_14_15_calendar/internal/api/private/private.pb.go
@@ -1,5 +1,5 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
-// source: grpcserver.proto
+// source: private.proto
 
 package private
 
@@ -37,7 +37,7 @@ func (m *GetRsp) Reset()         { *m = GetRsp{} }
 func (m *GetRsp) String() string { return proto.CompactTextString(m) }
 func (*GetRsp) ProtoMessage()    {}
 func (*GetRsp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{0}
+	return fileDescriptor_d2a91b51c7bdc125, []int{0}
 }
 
 func (m *GetRsp) XXX_Unmarshal(b []byte) error {
@@ -76,7 +76,7 @@ func (m *SetReq) Reset()         { *m = SetReq{} }
 func (m *SetReq) String() string { return proto.CompactTextString(m) }
 func (*SetReq) ProtoMessage()    {}
 func (*SetReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{1}
+	return fileDescriptor_d2a91b51c7bdc125, []int{1}
 }
 
 func (m *SetReq) XXX_Unmarshal(b []byte) error {
@@ -115,7 +115,7 @@ func (m *PurgeReq) Reset()         { *m = PurgeReq{} }
 func (m *PurgeReq) String() string { return proto.CompactTextString(m) }
 func (*PurgeReq) ProtoMessage()    {}
 func (*PurgeReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{2}
+	return fileDescriptor_d2a91b51c7bdc125, []int{2}
 }
 
 func (m *PurgeReq) XXX_Unmarshal(b []byte) error {
@@ -154,7 +154,7 @@ func (m *PurgeResp) Reset()         { *m = PurgeResp{} }
 func (m *PurgeResp) String() string { return proto.CompactTextString(m) }
 func (*PurgeResp) ProtoMessage()    {}
 func (*PurgeResp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{3}
+	return fileDescriptor_d2a91b51c7bdc125, []int{3}
 }
 
 func (m *PurgeResp) XXX_Unmarshal(b []byte) error {
@@ -196,7 +196,7 @@ func (m *Event) Reset()         { *m = Event{} }
 func (m *Event) String() string { return proto.CompactTextString(m) }
 func (*Event) ProtoMessage()    {}
 func (*Event) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{4}
+	return fileDescriptor_d2a91b51c7bdc125, []int{4}
 }
 
 func (m *Event) XXX_Unmarshal(b []byte) error {
@@ -253,32 +253,32 @@ func init() {
 	proto.RegisterType((*Event)(nil), "private.Event")
 }
 
-func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
+func init() { proto.RegisterFile("private.proto", fileDescriptor_d2a91b51c7bdc125) }
 
-var fileDescriptor_afa6debe97205904 = []byte{
-	// 351 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x6b, 0xea, 0x50,
-	0x10, 0x85, 0x8d, 0xd1, 0xbc, 0xe7, 0xc8, 0xf3, 0xf9, 0x86, 0x87, 0x84, 0x94, 0xd2, 0x10, 0x4a,
-	0xc9, 0x2a, 0x8a, 0xdd, 0xb4, 0x8b, 0x6e, 0x4a, 0x44, 0xdc, 0xd4, 0x36, 0xda, 0x4d, 0x77, 0x51,
-	0xc7, 0x34, 0x10, 0x4d, 0x7a, 0xef, 0x28, 0xf8, 0xd7, 0xfa, 0xeb, 0x4a, 0x72, 0x13, 0x4b, 0x2d,
-	0xdd, 0xe5, 0x9e, 0x39, 0x73, 0x0e, 0xf3, 0x11, 0xe8, 0x46, 0x22, 0x5b, 0x4a, 0x12, 0x7b, 0x12,
-	0x5e, 0x26, 0x52, 0x4e, 0xf1, 0x57, 0x26, 0xe2, 0x7d, 0xc8, 0x64, 0x5d, 0x44, 0x69, 0x1a, 0x25,
-	0xd4, 0x2f, 0xe4, 0xc5, 0x6e, 0xdd, 0xe7, 0x78, 0x43, 0x92, 0xc3, 0x4d, 0xa6, 0x9c, 0xd6, 0xd9,
-	0xa9, 0x81, 0x36, 0x19, 0x1f, 0xd4, 0xd0, 0x19, 0x80, 0x31, 0x26, 0x0e, 0x64, 0x86, 0x57, 0x60,
-	0x8c, 0xf6, 0xb4, 0x65, 0x69, 0x6a, 0xb6, 0xee, 0xb6, 0x87, 0x1d, 0xaf, 0x6c, 0xf0, 0x0a, 0x39,
-	0x28, 0xa7, 0x8e, 0x09, 0xc6, 0x8c, 0x38, 0xa0, 0x37, 0xec, 0x40, 0x7d, 0xe2, 0x9b, 0x9a, 0xad,
-	0xb9, 0x7a, 0x50, 0x9f, 0xf8, 0xce, 0x00, 0x7e, 0x3f, 0xee, 0x44, 0x44, 0xf9, 0xec, 0x12, 0xfe,
-	0x4c, 0x93, 0x15, 0x89, 0xf9, 0x2b, 0x6d, 0xfd, 0xf0, 0x20, 0x4b, 0xdb, 0x57, 0xd1, 0x39, 0x87,
-	0x56, 0xb9, 0x21, 0x33, 0xec, 0x82, 0xfe, 0xc4, 0x87, 0xd2, 0x98, 0x7f, 0x3a, 0x3b, 0x68, 0x16,
-	0xa5, 0xa7, 0x4d, 0xf8, 0x1f, 0x9a, 0xf3, 0x98, 0x13, 0x32, 0xeb, 0xb6, 0xe6, 0xb6, 0x02, 0xf5,
-	0x40, 0x0f, 0x1a, 0x7e, 0xc8, 0x64, 0xea, 0xb6, 0xe6, 0xb6, 0x87, 0x96, 0xa7, 0xee, 0xf6, 0xaa,
-	0xbb, 0xbd, 0x79, 0x05, 0x26, 0x28, 0x7c, 0xd8, 0x03, 0xe3, 0x59, 0x92, 0x98, 0xf8, 0x66, 0xa3,
-	0x48, 0x2e, 0x5f, 0xc3, 0x77, 0x0d, 0x1a, 0x39, 0x6f, 0xbc, 0x83, 0xee, 0x98, 0xf8, 0x21, 0xe5,
-	0x78, 0x1d, 0x2f, 0x43, 0x8e, 0xd3, 0xad, 0xc4, 0xde, 0xb7, 0xd8, 0x51, 0x8e, 0xd3, 0xfa, 0x7b,
-	0xc4, 0xa5, 0x78, 0x3a, 0x35, 0xbc, 0x81, 0xf6, 0xac, 0x5a, 0xa7, 0x15, 0x7e, 0x3a, 0x14, 0x3f,
-	0xeb, 0x87, 0x28, 0xa7, 0x86, 0xb7, 0xd0, 0x29, 0xb8, 0x4c, 0x93, 0x95, 0xa2, 0x8e, 0xff, 0x8e,
-	0xcb, 0x15, 0x62, 0x0b, 0x4f, 0xa5, 0xbc, 0xf4, 0xbe, 0xf5, 0x52, 0xfd, 0x19, 0x0b, 0xa3, 0xc8,
-	0xbd, 0xfe, 0x08, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xac, 0x01, 0x89, 0x3d, 0x02, 0x00, 0x00,
+var fileDescriptor_d2a91b51c7bdc125 = []byte{
+	// 343 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x4f, 0xc2, 0x50,
+	0x10, 0x84, 0x29, 0x85, 0x2a, 0x4b, 0x40, 0xdc, 0x18, 0xd2, 0xd4, 0x18, 0x9b, 0xc6, 0x98, 0x9e,
+	0x0a, 0xc1, 0x8b, 0x1e, 0xbc, 0x98, 0x12, 0xc2, 0x45, 0xb4, 0xe0, 0xc5, 0x5b, 0x81, 0xa5, 0x36,
+	0x29, 0xb4, 0xb6, 0x0b, 0x09, 0x7f, 0xcd, 0x5f, 0x67, 0xfa, 0x5e, 0x8b, 0x11, 0xe3, 0xad, 0x3b,
+	0x3b, 0x3b, 0x93, 0xf7, 0xa5, 0xd0, 0x4a, 0xd2, 0x70, 0xe7, 0x33, 0x39, 0x49, 0x1a, 0x73, 0x8c,
+	0x27, 0xc5, 0x68, 0x5c, 0x07, 0x71, 0x1c, 0x44, 0xd4, 0x13, 0xf2, 0x7c, 0xbb, 0xea, 0x71, 0xb8,
+	0xa6, 0x8c, 0xfd, 0x75, 0x22, 0x9d, 0xc6, 0xe5, 0xb1, 0x81, 0xd6, 0x09, 0xef, 0xe5, 0xd2, 0xea,
+	0x83, 0x36, 0x22, 0xf6, 0xb2, 0x04, 0x6f, 0x41, 0x1b, 0xee, 0x68, 0xc3, 0x99, 0xae, 0x98, 0xaa,
+	0xdd, 0x1c, 0xb4, 0x9d, 0xb2, 0x50, 0xc8, 0x5e, 0xb1, 0xb5, 0x74, 0xd0, 0xa6, 0xc4, 0x1e, 0x7d,
+	0x62, 0x1b, 0xaa, 0x63, 0x57, 0x57, 0x4c, 0xc5, 0x56, 0xbd, 0xea, 0xd8, 0xb5, 0xfa, 0x70, 0xfa,
+	0xb2, 0x4d, 0x03, 0xca, 0x77, 0x37, 0xd0, 0x9a, 0x44, 0x4b, 0x4a, 0x67, 0x1f, 0xb4, 0x71, 0xfd,
+	0x7d, 0x56, 0xd8, 0x7e, 0x8b, 0xd6, 0x15, 0x34, 0x8a, 0x8b, 0x2c, 0xc1, 0x0e, 0xa8, 0xaf, 0xbc,
+	0x2f, 0x8c, 0xf9, 0xa7, 0xb5, 0x85, 0xba, 0x28, 0x3d, 0x6e, 0xc2, 0x0b, 0xa8, 0xcf, 0x42, 0x8e,
+	0x48, 0xaf, 0x9a, 0x8a, 0xdd, 0xf0, 0xe4, 0x80, 0x0e, 0xd4, 0x5c, 0x9f, 0x49, 0x57, 0x4d, 0xc5,
+	0x6e, 0x0e, 0x0c, 0x47, 0xbe, 0xdb, 0x29, 0xdf, 0xed, 0xcc, 0x4a, 0x30, 0x9e, 0xf0, 0x61, 0x17,
+	0xb4, 0xb7, 0x8c, 0xd2, 0xb1, 0xab, 0xd7, 0x44, 0x72, 0x31, 0x0d, 0xbe, 0x14, 0xa8, 0x05, 0x69,
+	0xb2, 0xc0, 0x47, 0xe8, 0x8c, 0x88, 0x9f, 0x63, 0x0e, 0x57, 0xe1, 0xc2, 0xe7, 0x30, 0xde, 0x64,
+	0xd8, 0xfd, 0x13, 0x3b, 0xcc, 0x71, 0x1a, 0x67, 0x07, 0x5c, 0x92, 0xa7, 0x55, 0xc1, 0x7b, 0x68,
+	0x4e, 0xcb, 0x73, 0x5a, 0xe2, 0x8f, 0x43, 0xf2, 0x33, 0xfe, 0x89, 0xb2, 0x2a, 0xf8, 0x00, 0x6d,
+	0xc1, 0x65, 0x12, 0x2d, 0x25, 0x75, 0x3c, 0x3f, 0x1c, 0x97, 0x88, 0x0d, 0x3c, 0x96, 0xf2, 0xd2,
+	0xa7, 0xc6, 0x7b, 0xf9, 0x67, 0xcc, 0x35, 0x91, 0x7b, 0xf7, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x2d,
+	0x9f, 0xdc, 0xae, 0x3a, 0x02, 0x00, 0x00,
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -430,5 +430,5 @@ var _Grpc_serviceDesc = grpc.ServiceDesc{
 		},
 	},
 	Streams:  []grpc.StreamDesc{},
-	Metadata: "grpcserver.proto",
+	Metadata: "private.proto",
 }
diff --git a/hw12_13_14_15_calendar/internal/api/private/server.go b/hw12_13_14_15_calendar/internal/api/private/server.go
index 1c857f6..6a0a2ba 100644
--- a/hw12_13_14_15_calendar/internal/api/private/server.go
+++ b/hw12_13_14_15_calendar/internal/api/private/server.go
@@ -22,7 +22,7 @@ func New(app *calendar.App) Server {
 }
 
 func (s *Server) Start(conf Config) error {
-	s.app.Logger.Infof("GRPC server starting")
+	s.app.Logger.Infof("private GRPC server starting")
 	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Address, conf.Port))
 	RegisterGrpcServer(s.s, &Service{})
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
similarity index 84%
rename from hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go
rename to hw12_13_14_15_calendar/pkg/api/public/public.pb.go
index b595e75..e9ecd62 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
@@ -1,5 +1,5 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
-// source: grpcserver.proto
+// source: public.proto
 
 package public
 
@@ -53,7 +53,7 @@ func (x QueryRange) String() string {
 }
 
 func (QueryRange) EnumDescriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{0}
+	return fileDescriptor_413a91106d7bcce8, []int{0}
 }
 
 type Event struct {
@@ -73,7 +73,7 @@ func (m *Event) Reset()         { *m = Event{} }
 func (m *Event) String() string { return proto.CompactTextString(m) }
 func (*Event) ProtoMessage()    {}
 func (*Event) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{0}
+	return fileDescriptor_413a91106d7bcce8, []int{0}
 }
 
 func (m *Event) XXX_Unmarshal(b []byte) error {
@@ -159,7 +159,7 @@ func (m *CreateReq) Reset()         { *m = CreateReq{} }
 func (m *CreateReq) String() string { return proto.CompactTextString(m) }
 func (*CreateReq) ProtoMessage()    {}
 func (*CreateReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{1}
+	return fileDescriptor_413a91106d7bcce8, []int{1}
 }
 
 func (m *CreateReq) XXX_Unmarshal(b []byte) error {
@@ -233,7 +233,7 @@ func (m *CreateRsp) Reset()         { *m = CreateRsp{} }
 func (m *CreateRsp) String() string { return proto.CompactTextString(m) }
 func (*CreateRsp) ProtoMessage()    {}
 func (*CreateRsp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{2}
+	return fileDescriptor_413a91106d7bcce8, []int{2}
 }
 
 func (m *CreateRsp) XXX_Unmarshal(b []byte) error {
@@ -273,7 +273,7 @@ func (m *UpdateReq) Reset()         { *m = UpdateReq{} }
 func (m *UpdateReq) String() string { return proto.CompactTextString(m) }
 func (*UpdateReq) ProtoMessage()    {}
 func (*UpdateReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{3}
+	return fileDescriptor_413a91106d7bcce8, []int{3}
 }
 
 func (m *UpdateReq) XXX_Unmarshal(b []byte) error {
@@ -319,7 +319,7 @@ func (m *DeleteReq) Reset()         { *m = DeleteReq{} }
 func (m *DeleteReq) String() string { return proto.CompactTextString(m) }
 func (*DeleteReq) ProtoMessage()    {}
 func (*DeleteReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{4}
+	return fileDescriptor_413a91106d7bcce8, []int{4}
 }
 
 func (m *DeleteReq) XXX_Unmarshal(b []byte) error {
@@ -358,7 +358,7 @@ func (m *ListResp) Reset()         { *m = ListResp{} }
 func (m *ListResp) String() string { return proto.CompactTextString(m) }
 func (*ListResp) ProtoMessage()    {}
 func (*ListResp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{5}
+	return fileDescriptor_413a91106d7bcce8, []int{5}
 }
 
 func (m *ListResp) XXX_Unmarshal(b []byte) error {
@@ -397,7 +397,7 @@ func (m *GetByIDReq) Reset()         { *m = GetByIDReq{} }
 func (m *GetByIDReq) String() string { return proto.CompactTextString(m) }
 func (*GetByIDReq) ProtoMessage()    {}
 func (*GetByIDReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{6}
+	return fileDescriptor_413a91106d7bcce8, []int{6}
 }
 
 func (m *GetByIDReq) XXX_Unmarshal(b []byte) error {
@@ -436,7 +436,7 @@ func (m *GetByIDResp) Reset()         { *m = GetByIDResp{} }
 func (m *GetByIDResp) String() string { return proto.CompactTextString(m) }
 func (*GetByIDResp) ProtoMessage()    {}
 func (*GetByIDResp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{7}
+	return fileDescriptor_413a91106d7bcce8, []int{7}
 }
 
 func (m *GetByIDResp) XXX_Unmarshal(b []byte) error {
@@ -476,7 +476,7 @@ func (m *GetByDateReq) Reset()         { *m = GetByDateReq{} }
 func (m *GetByDateReq) String() string { return proto.CompactTextString(m) }
 func (*GetByDateReq) ProtoMessage()    {}
 func (*GetByDateReq) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{8}
+	return fileDescriptor_413a91106d7bcce8, []int{8}
 }
 
 func (m *GetByDateReq) XXX_Unmarshal(b []byte) error {
@@ -522,7 +522,7 @@ func (m *GetByDateResp) Reset()         { *m = GetByDateResp{} }
 func (m *GetByDateResp) String() string { return proto.CompactTextString(m) }
 func (*GetByDateResp) ProtoMessage()    {}
 func (*GetByDateResp) Descriptor() ([]byte, []int) {
-	return fileDescriptor_afa6debe97205904, []int{9}
+	return fileDescriptor_413a91106d7bcce8, []int{9}
 }
 
 func (m *GetByDateResp) XXX_Unmarshal(b []byte) error {
@@ -564,49 +564,48 @@ func init() {
 	proto.RegisterType((*GetByDateResp)(nil), "public.GetByDateResp")
 }
 
-func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
+func init() { proto.RegisterFile("public.proto", fileDescriptor_413a91106d7bcce8) }
 
-var fileDescriptor_afa6debe97205904 = []byte{
-	// 613 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0xcb, 0x6e, 0xd3, 0x5c,
-	0x10, 0xc7, 0x3f, 0x27, 0x8e, 0x53, 0x4f, 0x2f, 0x5f, 0x3a, 0x94, 0x62, 0xdc, 0xaa, 0x44, 0x07,
-	0x21, 0x45, 0x59, 0xd8, 0x22, 0x45, 0x48, 0xb0, 0xa2, 0xc5, 0x11, 0xb5, 0x28, 0x45, 0x58, 0xa9,
-	0xb8, 0xec, 0x9c, 0xf4, 0x34, 0x58, 0x4a, 0xec, 0x83, 0x7d, 0x52, 0x29, 0xaa, 0xb2, 0xe1, 0x15,
-	0x78, 0x2b, 0xb6, 0xbc, 0x02, 0x5b, 0x1e, 0x80, 0x1d, 0xf2, 0xf1, 0xb1, 0xd3, 0x5c, 0x2a, 0xb2,
-	0x67, 0x17, 0xcf, 0x7f, 0xe6, 0x37, 0x33, 0x9e, 0xbf, 0x1c, 0xa8, 0xf5, 0x63, 0xd6, 0x4b, 0x68,
-	0x7c, 0x45, 0x63, 0x8b, 0xc5, 0x11, 0x8f, 0x50, 0x63, 0xa3, 0xee, 0x20, 0xe8, 0x99, 0x0f, 0xfa,
-	0x51, 0xd4, 0x1f, 0x50, 0x5b, 0x44, 0xbb, 0xa3, 0x4b, 0x9b, 0x07, 0x43, 0x9a, 0x70, 0x7f, 0xc8,
-	0xb2, 0x44, 0xf3, 0x60, 0x3e, 0xe1, 0x62, 0x14, 0xfb, 0x3c, 0x88, 0x42, 0xa9, 0xef, 0xcd, 0xeb,
-	0x74, 0xc8, 0xf8, 0x58, 0x8a, 0xfb, 0x52, 0xf4, 0x59, 0x60, 0xfb, 0x61, 0x18, 0x71, 0x51, 0x99,
-	0x64, 0x2a, 0xf9, 0xad, 0x40, 0xa5, 0x7d, 0x45, 0x43, 0x8e, 0x5b, 0x50, 0x72, 0x1d, 0x43, 0xa9,
-	0x2b, 0x8d, 0xb2, 0x57, 0x72, 0x1d, 0xdc, 0x81, 0x4a, 0x27, 0xe0, 0x03, 0x6a, 0x94, 0xea, 0x4a,
-	0x43, 0xf7, 0xb2, 0x07, 0xb4, 0x40, 0x75, 0x7c, 0x4e, 0x8d, 0x72, 0x5d, 0x69, 0xac, 0xb7, 0x4c,
-	0x2b, 0x83, 0x5b, 0x79, 0x67, 0xab, 0x93, 0x8f, 0xee, 0x89, 0x3c, 0x3c, 0x84, 0xea, 0xa9, 0xcf,
-	0x69, 0xd8, 0x1b, 0x1b, 0xaa, 0x28, 0xb9, 0xbf, 0x50, 0xe2, 0xc8, 0x65, 0xbc, 0x3c, 0x13, 0x11,
-	0xd4, 0xb3, 0x88, 0x53, 0xa3, 0x22, 0x3a, 0x8b, 0xdf, 0xb8, 0x0b, 0xda, 0x79, 0x42, 0x63, 0xd7,
-	0x31, 0x34, 0x31, 0xa2, 0x7c, 0xc2, 0x67, 0x00, 0x67, 0x11, 0x0f, 0x2e, 0xc7, 0x69, 0x67, 0xa3,
-	0xfa, 0xb7, 0x1e, 0x37, 0x92, 0xc9, 0x2f, 0x05, 0xf4, 0x97, 0x31, 0xf5, 0x39, 0xf5, 0xe8, 0x97,
-	0x7f, 0x60, 0xdf, 0xbd, 0x62, 0xdd, 0x84, 0xcd, 0x9f, 0x9b, 0xbc, 0x00, 0xfd, 0x9c, 0x5d, 0xc8,
-	0x77, 0x31, 0xef, 0x85, 0x87, 0xd2, 0x24, 0xe2, 0xdd, 0xac, 0xb7, 0x36, 0xad, 0xcc, 0xb9, 0x96,
-	0x08, 0x7a, 0x99, 0x96, 0xe2, 0x1d, 0x3a, 0xa0, 0x4b, 0x09, 0xe4, 0x31, 0xac, 0x9d, 0x06, 0x09,
-	0xf7, 0x68, 0xc2, 0xf0, 0x11, 0x68, 0xa2, 0x22, 0x31, 0x94, 0x7a, 0x79, 0x11, 0x27, 0x45, 0xb2,
-	0x0f, 0xf0, 0x8a, 0xf2, 0xe3, 0xb1, 0xeb, 0x2c, 0x03, 0x3e, 0x81, 0xf5, 0x42, 0x5d, 0x9d, 0xf9,
-	0x19, 0x36, 0x44, 0x95, 0x23, 0x17, 0xcd, 0xcf, 0xab, 0xac, 0x78, 0xde, 0x06, 0x54, 0x3c, 0x3f,
-	0xec, 0x67, 0x26, 0xd9, 0x6a, 0x61, 0xde, 0xe5, 0xdd, 0x88, 0xc6, 0x63, 0xa1, 0x78, 0x59, 0x02,
-	0x79, 0x0a, 0x9b, 0x37, 0x3a, 0xad, 0x3c, 0x61, 0xb3, 0x09, 0x30, 0x85, 0x61, 0x15, 0xca, 0xce,
-	0xd1, 0xc7, 0xda, 0x7f, 0xb8, 0x06, 0xea, 0xfb, 0x76, 0xfb, 0x75, 0x4d, 0x41, 0x1d, 0x2a, 0x6f,
-	0xde, 0x9e, 0x75, 0x4e, 0x6a, 0xa5, 0xd6, 0xf7, 0x32, 0xa8, 0xe9, 0x57, 0x05, 0x8f, 0x41, 0xcb,
-	0x2e, 0x8b, 0xdb, 0x39, 0xb5, 0x30, 0xb6, 0x39, 0x1f, 0x4a, 0x18, 0xc1, 0xaf, 0x3f, 0x7e, 0x7e,
-	0x2b, 0x6d, 0x90, 0xaa, 0x4d, 0x45, 0xd7, 0xe7, 0x4a, 0x13, 0x4f, 0x41, 0xcb, 0x0c, 0x30, 0x65,
-	0x14, 0x86, 0x30, 0x77, 0x17, 0xde, 0x4c, 0x3b, 0xfd, 0xc4, 0x90, 0x7b, 0x02, 0xb4, 0x6d, 0x6e,
-	0x48, 0x90, 0x7d, 0xed, 0x3a, 0x93, 0x94, 0xe6, 0x82, 0x96, 0x99, 0x61, 0x4a, 0x2b, 0xcc, 0x71,
-	0x2b, 0x6d, 0x47, 0xd0, 0xb6, 0x9a, 0x33, 0x34, 0x3c, 0x02, 0x35, 0xb5, 0x0e, 0xde, 0x52, 0x65,
-	0xd6, 0xf2, 0x06, 0xb9, 0xc1, 0xc8, 0xff, 0x82, 0xa3, 0x63, 0xbe, 0x1e, 0x9e, 0x40, 0x55, 0x9a,
-	0x05, 0x8b, 0x93, 0x4d, 0xbd, 0x65, 0xde, 0x59, 0x88, 0x25, 0x2c, 0x1f, 0x06, 0x67, 0x87, 0xf9,
-	0x00, 0x7a, 0x71, 0x56, 0xdc, 0x99, 0xa9, 0x93, 0x9e, 0x32, 0xef, 0x2e, 0x89, 0x26, 0x8c, 0x1c,
-	0x08, 0x9e, 0x41, 0x76, 0x0b, 0x9e, 0x38, 0xf1, 0xc4, 0xbe, 0x4e, 0x53, 0x26, 0xc7, 0x6b, 0x9f,
-	0xe4, 0xff, 0x41, 0x57, 0x13, 0x0b, 0x1e, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0x88, 0xff, 0xa1,
-	0x0a, 0x32, 0x06, 0x00, 0x00,
+var fileDescriptor_413a91106d7bcce8 = []byte{
+	// 606 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0xcd, 0x6e, 0xd3, 0x40,
+	0x10, 0xc7, 0x71, 0xe2, 0x38, 0xf5, 0x34, 0x2d, 0xe9, 0x50, 0x8a, 0x71, 0xab, 0x12, 0x2d, 0x42,
+	0x8a, 0x72, 0xb0, 0x45, 0x8a, 0x90, 0xe0, 0x44, 0x8b, 0x23, 0x6a, 0x51, 0x8a, 0xb0, 0x5a, 0xf1,
+	0x71, 0x73, 0xd2, 0x6d, 0xb0, 0x94, 0xd8, 0x8b, 0xbd, 0x41, 0x8a, 0xaa, 0x5c, 0x78, 0x05, 0xde,
+	0x8a, 0x2b, 0xaf, 0xc0, 0x95, 0x07, 0xe0, 0x86, 0xbc, 0x5e, 0x3b, 0xcd, 0x47, 0x45, 0xee, 0xdc,
+	0xb2, 0xfb, 0x9f, 0xf9, 0xcd, 0xcc, 0xce, 0x5f, 0x31, 0xd4, 0xd8, 0xa8, 0x3b, 0x08, 0x7a, 0x16,
+	0x8b, 0x23, 0x1e, 0xa1, 0x96, 0x9d, 0xcc, 0x07, 0xfd, 0x28, 0xea, 0x0f, 0xa8, 0x2d, 0x6e, 0xbb,
+	0xa3, 0x4b, 0x9b, 0x07, 0x43, 0x9a, 0x70, 0x7f, 0xc8, 0xb2, 0x40, 0x73, 0x7f, 0x3e, 0xe0, 0x62,
+	0x14, 0xfb, 0x3c, 0x88, 0x42, 0xa9, 0xef, 0xce, 0xeb, 0x74, 0xc8, 0xf8, 0x58, 0x8a, 0x7b, 0x52,
+	0xf4, 0x59, 0x60, 0xfb, 0x61, 0x18, 0x71, 0x91, 0x99, 0x64, 0x2a, 0xf9, 0xa3, 0x40, 0xa5, 0xf3,
+	0x95, 0x86, 0x1c, 0x37, 0xa1, 0xe4, 0x3a, 0x86, 0xd2, 0x50, 0x9a, 0x65, 0xaf, 0xe4, 0x3a, 0xb8,
+	0x0d, 0x95, 0xb3, 0x80, 0x0f, 0xa8, 0x51, 0x6a, 0x28, 0x4d, 0xdd, 0xcb, 0x0e, 0x68, 0x81, 0xea,
+	0xf8, 0x9c, 0x1a, 0xe5, 0x86, 0xd2, 0x5c, 0x6f, 0x9b, 0x56, 0x06, 0xb7, 0xf2, 0xca, 0xd6, 0x59,
+	0xde, 0xba, 0x27, 0xe2, 0xf0, 0x00, 0xaa, 0x27, 0x3e, 0xa7, 0x61, 0x6f, 0x6c, 0xa8, 0x22, 0xe5,
+	0xfe, 0x42, 0x8a, 0x23, 0x87, 0xf1, 0xf2, 0x48, 0x44, 0x50, 0x4f, 0x23, 0x4e, 0x8d, 0x8a, 0xa8,
+	0x2c, 0x7e, 0xe3, 0x0e, 0x68, 0xe7, 0x09, 0x8d, 0x5d, 0xc7, 0xd0, 0x44, 0x8b, 0xf2, 0x84, 0xcf,
+	0x00, 0x4e, 0x23, 0x1e, 0x5c, 0x8e, 0xd3, 0xca, 0x46, 0xf5, 0x5f, 0x35, 0xae, 0x05, 0x93, 0xdf,
+	0x0a, 0xe8, 0x2f, 0x63, 0xea, 0x73, 0xea, 0xd1, 0x2f, 0xff, 0xc1, 0xbc, 0xbb, 0xc5, 0xb8, 0x09,
+	0x9b, 0x5f, 0x37, 0x79, 0x01, 0xfa, 0x39, 0xbb, 0x90, 0x6f, 0x31, 0xef, 0x85, 0x87, 0xd2, 0x24,
+	0xe2, 0x6d, 0xd6, 0xdb, 0x1b, 0x96, 0xf4, 0xb1, 0xb8, 0xf4, 0x32, 0x2d, 0xc5, 0x3b, 0x74, 0x40,
+	0x97, 0x12, 0xc8, 0x63, 0x58, 0x3b, 0x09, 0x12, 0xee, 0xd1, 0x84, 0xe1, 0x23, 0xd0, 0x44, 0x46,
+	0x62, 0x28, 0x8d, 0xf2, 0x22, 0x4e, 0x8a, 0x64, 0x0f, 0xe0, 0x15, 0xe5, 0x47, 0x63, 0xd7, 0x59,
+	0x06, 0x7c, 0x02, 0xeb, 0x85, 0xba, 0x3a, 0xf3, 0x33, 0xd4, 0x44, 0x96, 0x23, 0x07, 0xcd, 0xd7,
+	0xab, 0xac, 0xb8, 0xde, 0x26, 0x54, 0x3c, 0x3f, 0xec, 0x67, 0x26, 0xd9, 0x6c, 0x63, 0x5e, 0xe5,
+	0xdd, 0x88, 0xc6, 0x63, 0xa1, 0x78, 0x59, 0x00, 0x79, 0x0a, 0x1b, 0xd7, 0x2a, 0xad, 0xdc, 0x61,
+	0xab, 0x05, 0x30, 0x85, 0x61, 0x15, 0xca, 0xce, 0xe1, 0xc7, 0xfa, 0x2d, 0x5c, 0x03, 0xf5, 0x7d,
+	0xa7, 0xf3, 0xba, 0xae, 0xa0, 0x0e, 0x95, 0x37, 0x6f, 0x4f, 0xcf, 0x8e, 0xeb, 0xa5, 0xf6, 0x8f,
+	0x32, 0xa8, 0xfd, 0x98, 0xf5, 0xf0, 0x08, 0xb4, 0x6c, 0xb3, 0xb8, 0x95, 0x53, 0x0b, 0x63, 0x9b,
+	0xf3, 0x57, 0x09, 0x23, 0xf8, 0xed, 0xe7, 0xaf, 0xef, 0xa5, 0x1a, 0xa9, 0xda, 0x54, 0x54, 0x7d,
+	0xae, 0xb4, 0xf0, 0x04, 0xb4, 0xcc, 0x00, 0x53, 0x46, 0x61, 0x08, 0x73, 0x67, 0xe1, 0x65, 0x3a,
+	0xe9, 0x5f, 0x0c, 0xb9, 0x27, 0x40, 0x5b, 0x66, 0x4d, 0x82, 0xec, 0x2b, 0xd7, 0x99, 0xa4, 0x34,
+	0x17, 0xb4, 0xcc, 0x0c, 0x53, 0x5a, 0x61, 0x8e, 0x1b, 0x69, 0xdb, 0x82, 0xb6, 0xd9, 0x9a, 0xa1,
+	0xe1, 0x21, 0xa8, 0xa9, 0x75, 0xf0, 0x86, 0x2c, 0xb3, 0x9e, 0x17, 0xc8, 0x0d, 0x46, 0x6e, 0x0b,
+	0x8e, 0x8e, 0xf9, 0x78, 0x78, 0x0c, 0x55, 0x69, 0x16, 0x2c, 0x56, 0x36, 0xf5, 0x96, 0x79, 0x67,
+	0xe1, 0x2e, 0x61, 0x79, 0x33, 0x38, 0xdb, 0xcc, 0x07, 0xd0, 0x8b, 0xb5, 0xe2, 0xf6, 0x4c, 0x9e,
+	0xf4, 0x94, 0x79, 0x77, 0xc9, 0x6d, 0xc2, 0xc8, 0xbe, 0xe0, 0x19, 0x64, 0xa7, 0xe0, 0x89, 0x15,
+	0x4f, 0xec, 0xab, 0x34, 0x64, 0x72, 0xb4, 0xf6, 0x49, 0x7e, 0x0f, 0xba, 0x9a, 0x18, 0xf0, 0xe0,
+	0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x37, 0x8b, 0x96, 0x2e, 0x06, 0x00, 0x00,
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -866,5 +865,5 @@ var _Grpc_serviceDesc = grpc.ServiceDesc{
 		},
 	},
 	Streams:  []grpc.StreamDesc{},
-	Metadata: "grpcserver.proto",
+	Metadata: "public.proto",
 }
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
similarity index 99%
rename from hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go
rename to hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
index a86236c..281320c 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/grpcserver.pb.gw.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
@@ -1,5 +1,5 @@
 // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
-// source: grpcserver.proto
+// source: public.proto
 
 /*
 Package public is a reverse proxy.
diff --git a/hw12_13_14_15_calendar/pkg/api/public/server.go b/hw12_13_14_15_calendar/pkg/api/public/server.go
index 1d88db1..c0b8cc2 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/server.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/server.go
@@ -18,7 +18,7 @@ func New(app *calendar.App) Server {
 }
 
 func (s *Server) Start(conf config.Calendar) error {
-	s.app.Logger.Infof("GRPC server starting")
+	s.app.Logger.Infof("public GRPC server starting")
 	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.GRPC.Address, conf.GRPC.Port))
 	RegisterGrpcServer(s.s, &Service{})
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/pkg/config/config.go b/hw12_13_14_15_calendar/pkg/config/config.go
index 4945f71..67e0894 100644
--- a/hw12_13_14_15_calendar/pkg/config/config.go
+++ b/hw12_13_14_15_calendar/pkg/config/config.go
@@ -3,11 +3,18 @@ package config
 import (
 	"io/ioutil"
 	"os"
+	"reflect"
+	"strconv"
+	"strings"
 
 	"github.com/BurntSushi/toml"
+	"github.com/pkg/errors"
 )
 
 func New(configFile string, str interface{}) error {
+	if configFile == "" {
+		return ApplyEnvVars(str, "APP")
+	}
 	f, err := os.Open(configFile)
 	if err != nil {
 		return err
@@ -18,5 +25,53 @@ func New(configFile string, str interface{}) error {
 		return err
 	}
 	_, err = toml.Decode(string(s), str)
-	return err
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Пришлось немного модифицировать пакет github.com/mxschmitt/golang-env-struct. В исходной реализации используется поиск по тегам, а у моих структур тегов быть не должно. Пришлось переделать функцию, чтобы она искала по именам полей.
+// Тест дополнен проверкой заполнения структуры из переменных окружения.
+func ApplyEnvVars(c interface{}, prefix string) error {
+	return applyEnvVar(reflect.ValueOf(c), reflect.TypeOf(c), -1, prefix)
+}
+
+func applyEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) error {
+	if v.Kind() != reflect.Ptr {
+		return errors.New("not a pointer value")
+	}
+	f := reflect.StructField{}
+	if counter != -1 {
+		f = t.Field(counter)
+	}
+	v = reflect.Indirect(v)
+	fName := strings.ToUpper(f.Name)
+	env := os.Getenv(prefix + fName)
+	if env != "" {
+		switch v.Kind() {
+		case reflect.Int:
+			envI, err := strconv.Atoi(env)
+			if err != nil {
+				return errors.Wrap(err, "could not parse to int")
+			}
+			v.SetInt(int64(envI))
+		case reflect.String:
+			v.SetString(env)
+		case reflect.Bool:
+			envB, err := strconv.ParseBool(env)
+			if err != nil {
+				return errors.Wrap(err, "could not parse bool")
+			}
+			v.SetBool(envB)
+		}
+	}
+	if v.Kind() == reflect.Struct {
+		for i := 0; i < v.NumField(); i++ {
+			if err := applyEnvVar(v.Field(i).Addr(), v.Type(), i, prefix+fName+"_"); err != nil {
+				return errors.Wrap(err, "could not apply env var")
+			}
+		}
+	}
+	return nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/config/config_test.go b/hw12_13_14_15_calendar/pkg/config/config_test.go
index cff5012..ff2acba 100644
--- a/hw12_13_14_15_calendar/pkg/config/config_test.go
+++ b/hw12_13_14_15_calendar/pkg/config/config_test.go
@@ -58,4 +58,33 @@ SQLHost = "localhost"`)
 		require.NoError(t, e)
 	})
 
+	t.Run("ENV reading", func(t *testing.T) {
+		for k, v := range map[string]string{"APP_STRUCT1_VAR1": "val1", "APP_STRUCT1_VAR2": "val2", "APP_STRUCT2_VAR1": "val3", "APP_STRUCT2_VAR2": "val4", "APP_STRUCT3_VAR1": "val5", "APP_STRUCT3_VAR2": "val6"} {
+			require.NoError(t, os.Setenv(k, v))
+		}
+		var str struct {
+			Struct1 struct {
+				Var1 string
+				Var2 string
+			}
+			Struct2 struct {
+				Var1 string
+				Var2 string
+			}
+			Struct3 struct {
+				Var1 string
+				Var2 string
+			}
+		}
+
+		err := New("", &str)
+		require.NoError(t, err)
+		require.Equal(t, "val1", str.Struct1.Var1)
+		require.Equal(t, "val2", str.Struct1.Var2)
+		require.Equal(t, "val3", str.Struct2.Var1)
+		require.Equal(t, "val4", str.Struct2.Var2)
+		require.Equal(t, "val5", str.Struct3.Var1)
+		require.Equal(t, "val6", str.Struct3.Var2)
+	})
+
 }
diff --git a/hw12_13_14_15_calendar/pkg/logger/logger.go b/hw12_13_14_15_calendar/pkg/logger/logger.go
index c9fdfca..7cb4da9 100644
--- a/hw12_13_14_15_calendar/pkg/logger/logger.go
+++ b/hw12_13_14_15_calendar/pkg/logger/logger.go
@@ -48,6 +48,7 @@ func New(conf Config) (Interface, error) {
 		log.Fatalf("Could not instantiate log %s", err.Error())
 	}
 	l := amitralog.WithFields(amitralog.Fields{"hw": "12"})
+	l.Infof("logger start successful")
 	return l, nil
 }
 

From cdf7bf9441993e288b2aa317692614a48760589e Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Thu, 26 Nov 2020 19:42:29 +0300
Subject: [PATCH 05/20] HW15 WIP

---
 .golangci.yml                                 |  1 -
 hw12_13_14_15_calendar/Makefile               |  6 +-
 .../cicd/calendar/Dockerfile                  |  2 +-
 .../cicd/docker-compose.yml                   | 52 +++++-----
 .../cicd/scheduler/Dockerfile                 |  2 +-
 hw12_13_14_15_calendar/cicd/sender/Dockerfile |  2 +-
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  8 +-
 .../cmd/calendar/main_test.go                 | 95 +++++++++++++++++++
 hw12_13_14_15_calendar/cmd/scheduler/main.go  |  9 +-
 hw12_13_14_15_calendar/cmd/sender/main.go     | 11 +--
 hw12_13_14_15_calendar/go.mod                 |  4 +
 hw12_13_14_15_calendar/go.sum                 |  8 ++
 .../internal/api/private/handlers.go          | 26 +++++
 .../internal/api/private/server.go            | 36 -------
 .../internal/sender/app_sender.go             |  9 +-
 .../internal/sheduler/app_scheduler.go        |  9 +-
 .../internal/sheduler/scheduler.go            | 11 ++-
 .../pkg/api/public/grpcclient.go              | 16 ++++
 .../api/public/{handlers.go => handler.go}    | 22 +++++
 .../pkg/api/public/public.pb.go               |  4 +-
 .../pkg/api/public/server.go                  | 32 -------
 21 files changed, 235 insertions(+), 130 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/cmd/calendar/main_test.go
 delete mode 100644 hw12_13_14_15_calendar/internal/api/private/server.go
 create mode 100644 hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
 rename hw12_13_14_15_calendar/pkg/api/public/{handlers.go => handler.go} (82%)
 delete mode 100644 hw12_13_14_15_calendar/pkg/api/public/server.go

diff --git a/.golangci.yml b/.golangci.yml
index 4e7fa91..aee85c0 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -16,5 +16,4 @@ linters:
     - gofumpt
     - gosec
     - nlreturn
-    - gocritic
     - exhaustive
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index c3df0b2..ad498fa 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -9,8 +9,11 @@ start: build-all rabbit-start calendar-start scheduler-start sender-start
 
 stop: scheduler-stop sender-stop calendar-stop rabbit-stop
 
+integration:
+	go test -v -race ./cmd/calendar/...
+
 test:
-	go test -race ./internal/... ./pkg/... --tags calendar
+	go test -race ./internal/... ./pkg/...
 
 lint: install-lint-deps
 	golangci-lint run .cmd/... ./internal/...  ./pkg/...
@@ -48,5 +51,4 @@ sender-stop:
 
 
 
-
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
index c40664f..290f3f3 100644
--- a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/calendar/.
-RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o calendar ./cmd/calendar/.
+RUN GOOS=linux GOARCH=amd64 go build -a -o calendar ./cmd/calendar/.
 
 FROM alpine:latest
 ENV APP_GRPC_ADDRESS=0.0.0.0
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
index 414b897..7a67bcd 100644
--- a/hw12_13_14_15_calendar/cicd/docker-compose.yml
+++ b/hw12_13_14_15_calendar/cicd/docker-compose.yml
@@ -1,4 +1,4 @@
-version: '2.0'
+version: '3'
 services:
   rabbitmq:
     image: rabbitmq:3-management-alpine
@@ -12,28 +12,28 @@ services:
     ports:
       - "5672:5672"
       - "15672:15672"
-    expose:
-      - 5672
-      - 15672
-  calendar:
-    build:
-      context: ..
-      dockerfile: ./cicd/calendar/Dockerfile
-    ports:
-      - 50051:50051
-      - 50053:50053
-      - 8888:8888
-    volumes:
-      - ../calendar.log:/calendar.log
-  scheduler:
-    build:
-      context: ..
-      dockerfile: ./cicd/scheduler/Dockerfile
-    volumes:
-      - ../calendar.log:/calendar.log
-  sender:
-    build:
-      context: ..
-      dockerfile: ./cicd/sender/Dockerfile
-    volumes:
-      - ../calendar.log:/calendar.log
\ No newline at end of file
+  #calendar:
+  #  build:
+  #    context: ..
+  #    dockerfile: ./cicd/calendar/Dockerfile
+  #  ports:
+  #    - "8888:8888"
+  #  volumes:
+  #    - ../calendar.log:/calendar.log
+  #scheduler:
+  #  build:
+  #    context: ..
+  #    dockerfile: ./cicd/scheduler/Dockerfile
+  #  volumes:
+  #    - ../calendar.log:/calendar.log
+  #  depends_on:
+  #    - rabbitmq
+  #    - calendar
+  #sender:
+  #  build:
+  #    context: ..
+  #    dockerfile: ./cicd/sender/Dockerfile
+  #  volumes:
+  #    - ../calendar.log:/calendar.log
+  #  depends_on:
+  #    - rabbitmq
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
index a7a1c23..69fa4c4 100644
--- a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/scheduler/.
-RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o scheduler ./cmd/scheduler/.
+RUN GOOS=linux GOARCH=amd64 go build -a -o scheduler ./cmd/scheduler/.
 
 FROM alpine:latest
 ENV APP_RABBITMQ_ADDRESS=rabbitmq
diff --git a/hw12_13_14_15_calendar/cicd/sender/Dockerfile b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
index a4345ea..f97bc8a 100644
--- a/hw12_13_14_15_calendar/cicd/sender/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/sender/.
-RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o sender ./cmd/sender/.
+RUN GOOS=linux GOARCH=amd64 go build -a -o sender ./cmd/sender/.
 
 FROM alpine:latest
 ENV APP_RABBITMQ_ADDRESS=rabbitmq
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index c7fedd3..778873b 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -32,7 +32,7 @@ func main() {
 	var conf config.Calendar
 	err := config.New(configFile, &conf)
 	if err != nil {
-		oslog.Fatal("не удалось открыть файл конфигурации:", err.Error())
+		oslog.Fatal("can't get config:", err.Error())
 	}
 	oslog.Printf("Переменная APP_GRPC_PORT: %#v", os.Getenv("APP_GRPC_PORT"))
 	oslog.Printf("Конфиг приложения: %#v", conf)
@@ -69,8 +69,8 @@ func main() {
 	defer grpcDiler.Close()
 
 	grpcGwRouter := runtime.NewServeMux()
-
-	if err = public.RegisterGrpcHandler(context.Background(), grpcGwRouter, grpcDiler); err != nil {
+	ctx, cancel := context.WithCancel(context.Background())
+	if err = public.RegisterGrpcHandler(ctx, grpcGwRouter, grpcDiler); err != nil {
 		log.Errorf("can't register handlers for grpc-gateway: " + err.Error())
 		os.Exit(1)
 	}
@@ -90,4 +90,6 @@ func main() {
 	<-signals
 	signal.Stop(signals)
 	serverGRPC.Stop()
+	serverAPI.Stop()
+	cancel()
 }
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main_test.go b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
new file mode 100644
index 0000000..50dfc20
--- /dev/null
+++ b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
@@ -0,0 +1,95 @@
+package main
+
+import (
+	"context"
+	"github.com/golang/protobuf/ptypes"
+	"github.com/golang/protobuf/ptypes/duration"
+	"github.com/golang/protobuf/ptypes/timestamp"
+	"github.com/stretchr/testify/require"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"log"
+	"sync"
+	"testing"
+	"time"
+)
+
+var _ = func() bool {
+	testing.Init()
+	return true
+}()
+
+const testPortBase = 3000
+
+var testEvent01 = public.CreateReq{
+	Title:      "Test event 01",
+	Date:       time2pbtimestamp(time.Now().Add(30 * time.Second)),
+	Latency:    dur2pbduration(24 * time.Hour),
+	Note:       "Note of test event 01",
+	NotifyTime: dur2pbduration(5 * time.Minute),
+	UserID:     1111,
+}
+
+var testEvent02 = public.CreateReq{
+	Title:      "Test event 02",
+	Date:       time2pbtimestamp(time.Now().Add(60 * time.Second)),
+	Latency:    dur2pbduration(2 * 24 * time.Hour),
+	Note:       "Note of test event 02",
+	NotifyTime: dur2pbduration(5 * time.Minute),
+	UserID:     2222,
+}
+
+func TestSimple(t *testing.T) {
+	wg := sync.WaitGroup{}
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
+	go func(ctx context.Context) {
+		main()
+	}(ctx)
+	publicAPI, err := public.NewClient("localhost", "50051")
+	require.NoError(t, err)
+
+	wg.Add(2)
+	// Реализовать тесты логики приложения:
+	t.Run("test public GRPC.Create with GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Update with GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
+	})
+	wg.Wait()
+}
+
+func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
+	r, err := ptypes.TimestampProto(t)
+	if err != nil {
+		log.Fatalf("cant convert Time to Timestamp: %s", err.Error())
+	}
+	return r
+}
+
+func dur2pbduration(t time.Duration) *duration.Duration {
+	return ptypes.DurationProto(t)
+}
diff --git a/hw12_13_14_15_calendar/cmd/scheduler/main.go b/hw12_13_14_15_calendar/cmd/scheduler/main.go
index bc9fae4..7093f26 100644
--- a/hw12_13_14_15_calendar/cmd/scheduler/main.go
+++ b/hw12_13_14_15_calendar/cmd/scheduler/main.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"context"
 	"flag"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sheduler"
 	"log"
@@ -24,12 +23,11 @@ func main() {
 	var conf sheduler.Config
 	err := config.New(configFile, &conf)
 	if err != nil {
-		log.Fatal("не удалось открыть файл конфигурации:", err.Error())
+		log.Fatal("can't get config:", err.Error())
 	}
 	app := sheduler.New(conf)
 
-	ctx, cancel := context.WithCancel(context.Background())
-	if err = app.Start(ctx); err != nil {
+	if err = app.Start(); err != nil {
 		app.Logger.Errorf("failed to start scheduler: ", err.Error())
 		os.Exit(1)
 	}
@@ -38,5 +36,6 @@ func main() {
 	signal.Notify(signals, syscall.SIGINT)
 	<-signals
 	signal.Stop(signals)
-	app.Stop(cancel)
+	app.Stop()
+	log.Println("scheduler shutdown gracefully")
 }
diff --git a/hw12_13_14_15_calendar/cmd/sender/main.go b/hw12_13_14_15_calendar/cmd/sender/main.go
index ede4a82..62cafba 100644
--- a/hw12_13_14_15_calendar/cmd/sender/main.go
+++ b/hw12_13_14_15_calendar/cmd/sender/main.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"context"
 	"flag"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sender"
 	"log"
@@ -16,7 +15,7 @@ import (
 var configFile string
 
 func init() {
-	flag.StringVar(&configFile, "config", "/etc/sender.conf", "Path to configuration file")
+	flag.StringVar(&configFile, "config", "", "Path to configuration file")
 	flag.Parse()
 }
 
@@ -24,12 +23,11 @@ func main() {
 	var conf sender.Config
 	err := config.New(configFile, &conf)
 	if err != nil {
-		log.Fatal("не удалось открыть файл конфигурации:", err.Error())
+		log.Fatal("can't get config:", err.Error())
 	}
 	app := sender.New(conf)
 
-	ctx, cancel := context.WithCancel(context.Background())
-	if err = app.Start(ctx); err != nil {
+	if err = app.Start(); err != nil {
 		app.Logger.Errorf("failed to start sender: ", err.Error())
 		os.Exit(1)
 	}
@@ -38,5 +36,6 @@ func main() {
 	signal.Notify(signals, syscall.SIGINT)
 	<-signals
 	signal.Stop(signals)
-	app.Stop(cancel)
+	app.Stop()
+	log.Println("sender shutdown gracefully")
 }
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index d78efb5..c5c0f37 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -9,12 +9,16 @@ require (
 	github.com/golang/protobuf v1.4.2
 	github.com/grpc-ecosystem/grpc-gateway v1.15.0
 	github.com/kr/text v0.2.0 // indirect
+	github.com/lib/pq v1.8.0 // indirect
+	github.com/mattn/go-sqlite3 v1.14.5 // indirect
 	github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
 	github.com/pkg/errors v0.9.1
+	github.com/pressly/goose v2.6.0+incompatible // indirect
 	github.com/sirupsen/logrus v1.4.2 // indirect
 	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
+	github.com/ziutek/mymysql v1.5.4 // indirect
 	go.uber.org/zap v1.15.0 // indirect
 	golang.org/x/net v0.0.0-20200625001655-4c5254603344
 	golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index 8061704..f175e33 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -54,6 +54,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
+github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
+github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
 github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397 h1:fbcg7+DIrrjxSsS78ARgJu/qZOO928w4mCj1KBEO7xM=
 github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397/go.mod h1:BvJngicNxsNmAUzt7zXpaoWKwuBiyxnD7DxzxfrrPyY=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
@@ -64,6 +68,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k=
+github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
@@ -84,6 +90,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
+github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
 go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers.go b/hw12_13_14_15_calendar/internal/api/private/handlers.go
index 308c7b1..dbd78b4 100644
--- a/hw12_13_14_15_calendar/internal/api/private/handlers.go
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers.go
@@ -2,18 +2,44 @@ package private
 
 import (
 	"context"
+	"net"
 
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	googrpc "google.golang.org/grpc"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
 
 type Service struct {
+	S   *googrpc.Server
 	App calendar.App
 }
 
+type Config struct {
+	Address string
+	Port    string
+}
+
+func New(app *calendar.App) Service {
+	return Service{S: googrpc.NewServer(), App: *app}
+}
+
+func (s *Service) Start(conf Config) error {
+	s.App.Logger.Infof("private GRPC server starting")
+	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Address, conf.Port))
+	RegisterGrpcServer(s.S, s)
+	if err != nil {
+		return err
+	}
+	return s.S.Serve(listnGrpc)
+}
+
+func (s *Service) Stop() {
+	s.S.GracefulStop()
+}
+
 func (s Service) GetNotifications(ctx context.Context, e *empty.Empty) (*GetRsp, error) {
 	tmp, err := s.App.Storage.GetNotifications()
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/internal/api/private/server.go b/hw12_13_14_15_calendar/internal/api/private/server.go
deleted file mode 100644
index 6a0a2ba..0000000
--- a/hw12_13_14_15_calendar/internal/api/private/server.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package private
-
-import (
-	"net"
-
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
-	googrpc "google.golang.org/grpc"
-)
-
-type Server struct {
-	s   *googrpc.Server
-	app calendar.App
-}
-
-type Config struct {
-	Address string
-	Port    string
-}
-
-func New(app *calendar.App) Server {
-	return Server{s: googrpc.NewServer(), app: *app}
-}
-
-func (s *Server) Start(conf Config) error {
-	s.app.Logger.Infof("private GRPC server starting")
-	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Address, conf.Port))
-	RegisterGrpcServer(s.s, &Service{})
-	if err != nil {
-		return err
-	}
-	return s.s.Serve(listnGrpc)
-}
-
-func (s *Server) Stop() {
-	s.s.GracefulStop()
-}
diff --git a/hw12_13_14_15_calendar/internal/sender/app_sender.go b/hw12_13_14_15_calendar/internal/sender/app_sender.go
index 778d10b..741b529 100644
--- a/hw12_13_14_15_calendar/internal/sender/app_sender.go
+++ b/hw12_13_14_15_calendar/internal/sender/app_sender.go
@@ -15,6 +15,7 @@ type Sender struct {
 	Logger logger.Interface
 	Rabbit *rabbit.Rabbit
 	Queue  string
+	Stop   context.CancelFunc
 }
 
 type Config struct {
@@ -34,7 +35,9 @@ func New(conf Config) Sender {
 	return Sender{Logger: log, Rabbit: rb, Queue: conf.Rabbitmq.Queue}
 }
 
-func (s *Sender) Start(ctx context.Context) error {
+func (s *Sender) Start() error {
+	ctx, cancel := context.WithCancel(context.Background())
+	s.Stop = cancel
 	msg, err := s.Rabbit.Consume(ctx, s.Queue)
 	if err != nil {
 		return err
@@ -59,7 +62,3 @@ func (s *Sender) Start(ctx context.Context) error {
 	}()
 	return nil
 }
-
-func (s *Sender) Stop(cancel context.CancelFunc) {
-	cancel()
-}
diff --git a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
index 166f775..c08e0fc 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
@@ -14,6 +14,7 @@ type Scheduler struct {
 	CalendarAPI config.Server
 	Logger      logger.Interface
 	Rabbit      *rabbit.Rabbit
+	Stop        context.CancelFunc
 }
 
 type Config struct {
@@ -35,7 +36,9 @@ func New(conf Config) Scheduler {
 	return Scheduler{CalendarAPI: conf.CalendarAPI, Logger: log, Rabbit: rb}
 }
 
-func (s *Scheduler) Start(ctx context.Context) error {
+func (s *Scheduler) Start() error {
+	ctx, cancel := context.WithCancel(context.Background())
+	s.Stop = cancel
 	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit, s.Logger) }, 1*time.Minute)
 	go func() {
 		for {
@@ -52,7 +55,3 @@ func (s *Scheduler) Start(ctx context.Context) error {
 	}()
 	return nil
 }
-
-func (s *Scheduler) Stop(cancel context.CancelFunc) {
-	cancel()
-}
diff --git a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
index 8b309ee..75850a7 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
@@ -3,6 +3,7 @@ package sheduler
 import (
 	"context"
 	"encoding/json"
+	"fmt"
 	"time"
 
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
@@ -40,25 +41,25 @@ func riseOnTick(ctx context.Context, log logger.Interface, fn func() interface{}
 func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit, log logger.Interface) error {
 	cli, err := private.NewClient(calendarAPI.Address, calendarAPI.Port)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't get GRPC client: %w", err)
 	}
 	resp, err := cli.GetNotifications(ctx, nil)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't get events from GRPC endpoint: %w", err)
 	}
 	for event := range resp.Events {
 		b, err := json.Marshal(event)
 		if err != nil {
-			return err
+			return fmt.Errorf("can't marshal events into JSON: %w", err)
 		}
 		err = rb.Publish(string(b))
 		if err != nil {
-			return err
+			return fmt.Errorf("can't publish serialized data to RabbitMQ: %w", err)
 		}
 	}
 	resp2, err := cli.PurgeOldEvents(ctx, &private.PurgeReq{OlderThenDays: 365})
 	if err != nil {
-		return err
+		return fmt.Errorf("can't purge old events: %w", err)
 	}
 	log.Infof("Scheduler successfully purges %s events from storage", resp2.Qty)
 	return nil
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
new file mode 100644
index 0000000..ad7a4f5
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
@@ -0,0 +1,16 @@
+package public
+
+import (
+	"net"
+
+	"google.golang.org/grpc"
+)
+
+func NewClient(addr, port string) (GrpcClient, error) {
+	conn, err := grpc.Dial(net.JoinHostPort(addr, port), grpc.WithInsecure())
+	if err != nil {
+		return nil, err
+	}
+	client := NewGrpcClient(conn)
+	return client, nil
+}
diff --git a/hw12_13_14_15_calendar/pkg/api/public/handlers.go b/hw12_13_14_15_calendar/pkg/api/public/handler.go
similarity index 82%
rename from hw12_13_14_15_calendar/pkg/api/public/handlers.go
rename to hw12_13_14_15_calendar/pkg/api/public/handler.go
index 44894e6..4766ccc 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/handlers.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handler.go
@@ -2,18 +2,40 @@ package public
 
 import (
 	"context"
+	"net"
 
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	googrpc "google.golang.org/grpc"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
 
 type Service struct {
+	S   *googrpc.Server
 	App calendar.App
 }
 
+func New(app *calendar.App) Service {
+	return Service{S: googrpc.NewServer(), App: *app}
+}
+
+func (s *Service) Start(conf config.Calendar) error {
+	s.App.Logger.Infof("public GRPC server starting")
+	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.GRPC.Address, conf.GRPC.Port))
+	if err != nil {
+		return err
+	}
+	RegisterGrpcServer(s.S, s)
+	return s.S.Serve(listnGrpc)
+}
+
+func (s *Service) Stop() {
+	s.S.GracefulStop()
+}
+
 func (s Service) Create(ctx context.Context, e *CreateReq) (*CreateRsp, error) {
 	var res CreateRsp
 	ce, err := s.buildStorageEvent(e)
diff --git a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
index e9ecd62..eb1cc62 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
@@ -733,7 +733,9 @@ func _Grpc_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa
 		return nil, err
 	}
 	if interceptor == nil {
-		return srv.(GrpcServer).Create(ctx, in)
+		sss := srv.(GrpcServer)
+		rrrrr, err := sss.Create(ctx, in)
+		return rrrrr, err
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
diff --git a/hw12_13_14_15_calendar/pkg/api/public/server.go b/hw12_13_14_15_calendar/pkg/api/public/server.go
deleted file mode 100644
index c0b8cc2..0000000
--- a/hw12_13_14_15_calendar/pkg/api/public/server.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package public
-
-import (
-	"net"
-
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
-	googrpc "google.golang.org/grpc"
-)
-
-type Server struct {
-	s   *googrpc.Server
-	app calendar.App
-}
-
-func New(app *calendar.App) Server {
-	return Server{s: googrpc.NewServer(), app: *app}
-}
-
-func (s *Server) Start(conf config.Calendar) error {
-	s.app.Logger.Infof("public GRPC server starting")
-	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.GRPC.Address, conf.GRPC.Port))
-	RegisterGrpcServer(s.s, &Service{})
-	if err != nil {
-		return err
-	}
-	return s.s.Serve(listnGrpc)
-}
-
-func (s *Server) Stop() {
-	s.s.GracefulStop()
-}

From b7db72ceb4e54b2314aa313f51d0905e8202d6d4 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Fri, 27 Nov 2020 17:20:41 +0300
Subject: [PATCH 06/20] HW15 WIP

---
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  4 +-
 .../internal/api/private/converters.go        |  4 +-
 .../internal/api/private/grpcclient.go        |  3 +-
 .../internal/api/private/handlers.go          |  8 ++-
 .../internal/sender/app_sender.go             |  7 ++-
 .../internal/sheduler/app_scheduler.go        |  2 +-
 .../pkg/api/public/converters.go              | 20 ++++---
 .../pkg/api/public/grpcclient.go              |  3 +-
 .../pkg/api/public/handler.go                 | 14 ++++-
 hw12_13_14_15_calendar/pkg/config/config.go   | 22 +++++---
 hw12_13_14_15_calendar/pkg/logger/logger.go   |  2 +-
 hw12_13_14_15_calendar/pkg/rabbit/producer.go |  5 +-
 hw12_13_14_15_calendar/pkg/rabbit/rabbit.go   | 20 ++++---
 hw12_13_14_15_calendar/pkg/storage/sql/sql.go | 55 ++++++++++++-------
 14 files changed, 109 insertions(+), 60 deletions(-)

diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index 778873b..96ff0f7 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -34,11 +34,9 @@ func main() {
 	if err != nil {
 		oslog.Fatal("can't get config:", err.Error())
 	}
-	oslog.Printf("Переменная APP_GRPC_PORT: %#v", os.Getenv("APP_GRPC_PORT"))
-	oslog.Printf("Конфиг приложения: %#v", conf)
 	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
-		oslog.Fatal("не удалось запустить логер:", err.Error())
+		oslog.Fatal("can't start logger:", err.Error())
 	}
 
 	st := store.NewStore(store.Config(conf.Storage))
diff --git a/hw12_13_14_15_calendar/internal/api/private/converters.go b/hw12_13_14_15_calendar/internal/api/private/converters.go
index 23c6831..63ffdc2 100644
--- a/hw12_13_14_15_calendar/internal/api/private/converters.go
+++ b/hw12_13_14_15_calendar/internal/api/private/converters.go
@@ -1,6 +1,8 @@
 package private
 
 import (
+	"fmt"
+
 	"github.com/golang/protobuf/ptypes"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
@@ -13,7 +15,7 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		evt := Event{ID: int64(k), Title: v.Title, UserID: v.UserID}
 		evt.Date, err = ptypes.TimestampProto(v.Date)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't convert date: %w", err)
 		}
 		events[i] = &evt
 		i++
diff --git a/hw12_13_14_15_calendar/internal/api/private/grpcclient.go b/hw12_13_14_15_calendar/internal/api/private/grpcclient.go
index 29d9baf..edf95a1 100644
--- a/hw12_13_14_15_calendar/internal/api/private/grpcclient.go
+++ b/hw12_13_14_15_calendar/internal/api/private/grpcclient.go
@@ -1,6 +1,7 @@
 package private
 
 import (
+	"fmt"
 	"net"
 
 	"google.golang.org/grpc"
@@ -9,7 +10,7 @@ import (
 func NewClient(addr, port string) (GrpcClient, error) {
 	conn, err := grpc.Dial(net.JoinHostPort(addr, port), grpc.WithInsecure())
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't dial GRPC server: %w", err)
 	}
 	client := NewGrpcClient(conn)
 	return client, nil
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers.go b/hw12_13_14_15_calendar/internal/api/private/handlers.go
index dbd78b4..da8a4e2 100644
--- a/hw12_13_14_15_calendar/internal/api/private/handlers.go
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers.go
@@ -2,6 +2,7 @@ package private
 
 import (
 	"context"
+	"fmt"
 	"net"
 
 	"github.com/golang/protobuf/ptypes/empty"
@@ -43,10 +44,12 @@ func (s *Service) Stop() {
 func (s Service) GetNotifications(ctx context.Context, e *empty.Empty) (*GetRsp, error) {
 	tmp, err := s.App.Storage.GetNotifications()
 	if err != nil {
+		s.App.Logger.Errorf("storage error: can't get list of events: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
 	}
 	l, err := s.buildEventList(tmp)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	return &GetRsp{Events: l}, nil
@@ -58,5 +61,8 @@ func (s Service) SetNotified(ctx context.Context, r *SetReq) (*empty.Empty, erro
 
 func (s Service) PurgeOldEvents(ctx context.Context, r *PurgeReq) (*PurgeResp, error) {
 	q, err := s.App.Storage.PurgeOldEvents(r.OlderThenDays)
-	return &PurgeResp{Qty: q}, err
+	if err != nil {
+		return &PurgeResp{}, fmt.Errorf("can't purge old events from storage: %w", err)
+	}
+	return &PurgeResp{Qty: q}, nil
 }
diff --git a/hw12_13_14_15_calendar/internal/sender/app_sender.go b/hw12_13_14_15_calendar/internal/sender/app_sender.go
index 741b529..6117811 100644
--- a/hw12_13_14_15_calendar/internal/sender/app_sender.go
+++ b/hw12_13_14_15_calendar/internal/sender/app_sender.go
@@ -3,6 +3,7 @@ package sender
 import (
 	"context"
 	"encoding/json"
+	"fmt"
 	oslog "log"
 
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
@@ -26,7 +27,7 @@ type Config struct {
 func New(conf Config) Sender {
 	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
-		oslog.Fatal("не удалось запустить логер:", err.Error())
+		oslog.Fatal("can't start logger:", err.Error())
 	}
 	rb, err := rabbit.Attach(rabbit.Config(conf.Rabbitmq))
 	if err != nil {
@@ -40,7 +41,7 @@ func (s *Sender) Start() error {
 	s.Stop = cancel
 	msg, err := s.Rabbit.Consume(ctx, s.Queue)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't consume RabbitMQ queue: %w", err)
 	}
 
 	go func() {
@@ -50,7 +51,7 @@ func (s *Sender) Start() error {
 				var data []private.Event
 				err := json.Unmarshal(m.Data, &data)
 				if err != nil {
-					s.Logger.Errorf("can`t unmarshal data", err)
+					s.Logger.Errorf("can`t unmarshal data %w", err)
 				}
 				for _, v := range data {
 					s.Logger.Infof("User %s notified about event %s", v.UserID, v.ID)
diff --git a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
index c08e0fc..8932b72 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
@@ -27,7 +27,7 @@ type Config struct {
 func New(conf Config) Scheduler {
 	log, err := logger.New(logger.Config(conf.Logger))
 	if err != nil {
-		oslog.Fatal("не удалось запустить логер:", err.Error())
+		oslog.Fatal("can't start logger:", err.Error())
 	}
 	rb, err := rabbit.New(rabbit.Config(conf.Rabbitmq))
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/pkg/api/public/converters.go b/hw12_13_14_15_calendar/pkg/api/public/converters.go
index 1bdcade..4ff845c 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/converters.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/converters.go
@@ -1,6 +1,7 @@
 package public
 
 import (
+	"fmt"
 	"time"
 
 	"github.com/golang/protobuf/ptypes"
@@ -11,15 +12,15 @@ func (s Service) buildStorageEvent(pbe *CreateReq) (res event.Event, err error)
 	res = event.Event{Title: pbe.Title, Note: pbe.Note, UserID: pbe.UserID}
 	res.Date, err = ptypes.Timestamp(pbe.Date)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can't convert date: %w", err)
 	}
 	res.Latency, err = ptypes.Duration(pbe.Latency)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can't convert duration: %w", err)
 	}
 	res.NotifyTime, err = ptypes.Duration(pbe.NotifyTime)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can't convert duration: %w", err)
 	}
 	return res, nil
 }
@@ -28,15 +29,15 @@ func (s Service) buildStorageEventAndID(pbe *UpdateReq) (id event.ID, evt event.
 	evt = event.Event{Title: pbe.Event.Title, Note: pbe.Event.Note, UserID: pbe.Event.UserID}
 	evt.Date, err = ptypes.Timestamp(pbe.Event.Date)
 	if err != nil {
-		return 0, event.Event{}, err
+		return 0, event.Event{}, fmt.Errorf("can't convert time: %w", err)
 	}
 	evt.Latency, err = ptypes.Duration(pbe.Event.Latency)
 	if err != nil {
-		return 0, event.Event{}, err
+		return 0, event.Event{}, fmt.Errorf("can't convert duration: %w", err)
 	}
 	evt.NotifyTime, err = ptypes.Duration(pbe.Event.NotifyTime)
 	if err != nil {
-		return 0, event.Event{}, err
+		return 0, event.Event{}, fmt.Errorf("can't convert duration: %w", err)
 	}
 	return event.ID(pbe.ID), evt, nil
 }
@@ -49,7 +50,7 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		evt := Event{ID: int64(k), Title: v.Title, Latency: ptypes.DurationProto(v.Latency), Note: v.Note, UserID: v.UserID, NotifyTime: ptypes.DurationProto(v.NotifyTime)}
 		evt.Date, err = ptypes.TimestampProto(v.Date)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't convert date: %w", err)
 		}
 		events[i] = &evt
 		i++
@@ -59,5 +60,8 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 
 func (s Service) buildTimeAndRange(e *GetByDateReq) (start time.Time, qrange string, err error) {
 	date, err := ptypes.Timestamp(e.Date)
-	return date, e.Range.String(), err
+	if err != nil {
+		return time.Time{}, "", fmt.Errorf("can't convert date: %w", err)
+	}
+	return date, e.Range.String(), nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
index ad7a4f5..42523d8 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
@@ -1,6 +1,7 @@
 package public
 
 import (
+	"fmt"
 	"net"
 
 	"google.golang.org/grpc"
@@ -9,7 +10,7 @@ import (
 func NewClient(addr, port string) (GrpcClient, error) {
 	conn, err := grpc.Dial(net.JoinHostPort(addr, port), grpc.WithInsecure())
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't dial GRPC server: %w", err)
 	}
 	client := NewGrpcClient(conn)
 	return client, nil
diff --git a/hw12_13_14_15_calendar/pkg/api/public/handler.go b/hw12_13_14_15_calendar/pkg/api/public/handler.go
index 4766ccc..82c2af7 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/handler.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handler.go
@@ -40,10 +40,12 @@ func (s Service) Create(ctx context.Context, e *CreateReq) (*CreateRsp, error) {
 	var res CreateRsp
 	ce, err := s.buildStorageEvent(e)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible event: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	t, err := s.App.Storage.Create(ce)
 	if err != nil {
+		s.App.Logger.Errorf("can't create event in storage: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't create event")
 	}
 	res.ID = int64(t)
@@ -53,16 +55,19 @@ func (s Service) Create(ctx context.Context, e *CreateReq) (*CreateRsp, error) {
 func (s Service) Update(ctx context.Context, e *UpdateReq) (*empty.Empty, error) {
 	cid, ce, err := s.buildStorageEventAndID(e)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible event: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	if s.App.Storage.Update(cid, ce) != nil {
+		s.App.Logger.Errorf("can't update event in storage: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't update event")
 	}
 	return nil, nil
 }
 
 func (s Service) Delete(ctx context.Context, e *DeleteReq) (*empty.Empty, error) {
-	if s.App.Storage.Delete(event.ID(e.ID)) != nil {
+	if err := s.App.Storage.Delete(event.ID(e.ID)); err != nil {
+		s.App.Logger.Errorf("can't update event in storage: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't update event")
 	}
 	return nil, nil
@@ -71,10 +76,12 @@ func (s Service) Delete(ctx context.Context, e *DeleteReq) (*empty.Empty, error)
 func (s Service) List(ctx context.Context, e *empty.Empty) (*ListResp, error) {
 	tmp, err := s.App.Storage.List()
 	if err != nil {
+		s.App.Logger.Errorf("can't get list of events from storage: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
 	}
 	l, err := s.buildEventList(tmp)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible list of events: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	return &ListResp{Events: l}, nil
@@ -83,10 +90,12 @@ func (s Service) List(ctx context.Context, e *empty.Empty) (*ListResp, error) {
 func (s Service) GetByID(ctx context.Context, e *GetByIDReq) (*GetByIDResp, error) {
 	tmp, ok := s.App.Storage.GetByID(event.ID(e.ID))
 	if !ok {
+		s.App.Logger.Errorf("event with ID %s not found in storage", e.ID)
 		return nil, status.Errorf(codes.NotFound, "event not found")
 	}
 	l, err := s.buildEventList(map[event.ID]event.Event{event.ID(e.ID): tmp})
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible list of events: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	return &GetByIDResp{Events: l}, nil
@@ -95,14 +104,17 @@ func (s Service) GetByID(ctx context.Context, e *GetByIDReq) (*GetByIDResp, erro
 func (s Service) GetByDate(ctx context.Context, e *GetByDateReq) (*GetByDateResp, error) {
 	d, r, err := s.buildTimeAndRange(e)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible time range: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	tmp, err := s.App.Storage.GetByDate(d, r)
 	if err != nil {
+		s.App.Logger.Errorf("can't get list of events from storage: %w", err)
 		return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
 	}
 	l, err := s.buildEventList(tmp)
 	if err != nil {
+		s.App.Logger.Errorf("inconvertible list of events: %w", err)
 		return nil, status.Errorf(codes.Internal, "inconvertible")
 	}
 	return &GetByDateResp{Events: l}, nil
diff --git a/hw12_13_14_15_calendar/pkg/config/config.go b/hw12_13_14_15_calendar/pkg/config/config.go
index 67e0894..0e95a83 100644
--- a/hw12_13_14_15_calendar/pkg/config/config.go
+++ b/hw12_13_14_15_calendar/pkg/config/config.go
@@ -1,6 +1,7 @@
 package config
 
 import (
+	"fmt"
 	"io/ioutil"
 	"os"
 	"reflect"
@@ -8,25 +9,28 @@ import (
 	"strings"
 
 	"github.com/BurntSushi/toml"
-	"github.com/pkg/errors"
 )
 
 func New(configFile string, str interface{}) error {
 	if configFile == "" {
-		return ApplyEnvVars(str, "APP")
+		err := ApplyEnvVars(str, "APP")
+		if err != nil {
+			return fmt.Errorf("can't apply envvars to config :%w", err)
+		}
+		return nil
 	}
 	f, err := os.Open(configFile)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't open config file: %w", err)
 	}
 	defer f.Close()
 	s, err := ioutil.ReadAll(f)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't read content of the config file : %w", err)
 	}
 	_, err = toml.Decode(string(s), str)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't parce config file : %w", err)
 	}
 	return nil
 }
@@ -39,7 +43,7 @@ func ApplyEnvVars(c interface{}, prefix string) error {
 
 func applyEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) error {
 	if v.Kind() != reflect.Ptr {
-		return errors.New("not a pointer value")
+		return fmt.Errorf("not a pointer value")
 	}
 	f := reflect.StructField{}
 	if counter != -1 {
@@ -53,7 +57,7 @@ func applyEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) er
 		case reflect.Int:
 			envI, err := strconv.Atoi(env)
 			if err != nil {
-				return errors.Wrap(err, "could not parse to int")
+				return fmt.Errorf("could not parse to int: %w", err)
 			}
 			v.SetInt(int64(envI))
 		case reflect.String:
@@ -61,7 +65,7 @@ func applyEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) er
 		case reflect.Bool:
 			envB, err := strconv.ParseBool(env)
 			if err != nil {
-				return errors.Wrap(err, "could not parse bool")
+				return fmt.Errorf("could not parse bool: %w", err)
 			}
 			v.SetBool(envB)
 		}
@@ -69,7 +73,7 @@ func applyEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) er
 	if v.Kind() == reflect.Struct {
 		for i := 0; i < v.NumField(); i++ {
 			if err := applyEnvVar(v.Field(i).Addr(), v.Type(), i, prefix+fName+"_"); err != nil {
-				return errors.Wrap(err, "could not apply env var")
+				return fmt.Errorf("could not apply env var: %w", err)
 			}
 		}
 	}
diff --git a/hw12_13_14_15_calendar/pkg/logger/logger.go b/hw12_13_14_15_calendar/pkg/logger/logger.go
index 7cb4da9..d6ef10d 100644
--- a/hw12_13_14_15_calendar/pkg/logger/logger.go
+++ b/hw12_13_14_15_calendar/pkg/logger/logger.go
@@ -47,7 +47,7 @@ func New(conf Config) (Interface, error) {
 	if err := amitralog.NewLogger(c, amitralog.InstanceZapLogger); err != nil {
 		log.Fatalf("Could not instantiate log %s", err.Error())
 	}
-	l := amitralog.WithFields(amitralog.Fields{"hw": "12"})
+	l := amitralog.WithFields(amitralog.Fields{"hw": "15"})
 	l.Infof("logger start successful")
 	return l, nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/producer.go b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
index b1c9b59..708bd63 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/producer.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
@@ -2,6 +2,7 @@ package rabbit
 
 import (
 	"encoding/json"
+	"fmt"
 
 	"github.com/streadway/amqp"
 )
@@ -9,7 +10,7 @@ import (
 func (r *Rabbit) Publish(body string) error {
 	b, err := json.Marshal([]byte(body))
 	if err != nil {
-		return err
+		return fmt.Errorf("can't marshal message body into JSON: %w", err)
 	}
 	err = r.Channel.Publish(
 		r.Exchange, // exchange
@@ -21,7 +22,7 @@ func (r *Rabbit) Publish(body string) error {
 			Body:        b,
 		})
 	if err != nil {
-		return err
+		return fmt.Errorf("can't publish message into RabbitMQ exchange: %w", err)
 	}
 	return nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
index a5a76d4..b893dc6 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
@@ -1,6 +1,8 @@
 package rabbit
 
 import (
+	"fmt"
+
 	"github.com/streadway/amqp"
 )
 
@@ -25,11 +27,11 @@ type Config struct {
 func New(conf Config) (*Rabbit, error) {
 	conn, err := amqp.Dial("amqp://" + conf.Login + ":" + conf.Pass + "@" + conf.Address + ":" + conf.Port + "/")
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't dial RabbitMQ over AMQP: %w", err)
 	}
 	ch, err := conn.Channel()
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't get channel from AMQP connection: %w", err)
 	}
 	err = ch.ExchangeDeclare(
 		conf.Exchange, // name
@@ -41,7 +43,7 @@ func New(conf Config) (*Rabbit, error) {
 		nil,           // arguments
 	)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't (re)declare exchange in RabbitMQ: %w", err)
 	}
 	q, err := ch.QueueDeclare(
 		conf.Queue,
@@ -52,11 +54,11 @@ func New(conf Config) (*Rabbit, error) {
 		nil,
 	)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't (re)create queue in RabbitMQ: %w", err)
 	}
 	err = ch.QueueBind(q.Name, conf.Key, conf.Exchange, false, nil)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't bind Queue on Exchange in RabbitMQ: %w", err)
 	}
 	return &Rabbit{Connection: conn, Channel: ch}, nil
 }
@@ -64,21 +66,21 @@ func New(conf Config) (*Rabbit, error) {
 func Attach(conf Config) (*Rabbit, error) {
 	conn, err := amqp.Dial("amqp://" + conf.Login + ":" + conf.Pass + "@" + conf.Address + ":" + conf.Port + "/")
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't dial RabbitMQ over AMQP: %w", err)
 	}
 	ch, err := conn.Channel()
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't get channel from AMQP connection: %w", err)
 	}
 	return &Rabbit{Connection: conn, Channel: ch, Exchange: conf.Exchange, Queue: conf.Queue, Key: conf.Key}, nil
 }
 
 func (r *Rabbit) Close() error {
 	if err := r.Channel.Close(); err != nil {
-		return err
+		return fmt.Errorf("can't close connection channel: %w", err)
 	}
 	if err := r.Connection.Close(); err != nil {
-		return err
+		return fmt.Errorf("can't close connection: %w", err)
 	}
 	return nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index f5884cc..4813232 100644
--- a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -2,6 +2,7 @@ package sql
 
 import (
 	"database/sql"
+	"fmt"
 	"time"
 
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
@@ -29,7 +30,7 @@ func (s *Storage) Connect(config Config) error {
 	var err error
 	s.db, err = sql.Open("mysql", config.User+":"+config.Pass+"@tcp("+config.Host+":"+config.Port+")/"+config.Dbase)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't connect to SQL server: %w", err)
 	}
 	return nil
 }
@@ -51,9 +52,12 @@ func (s *Storage) Create(ev event.Event) (event.ID, error) {
 		ev.NotifyTime,
 	)
 	if err != nil {
-		return -1, err
+		return -1, fmt.Errorf("can't create event in SQL DB: %w", err)
 	}
 	idint64, err := res.LastInsertId()
+	if err != nil {
+		return -1, fmt.Errorf("can't get LastInsertId from SQL DB: %w", err)
+	}
 	return event.ID(idint64), err
 }
 
@@ -70,7 +74,10 @@ func (s *Storage) Update(id event.ID, event event.Event) error {
 		event.NotifyTime,
 		id,
 	)
-	return err
+	if err != nil {
+		return fmt.Errorf("can't update event in SQL DB: %w", err)
+	}
+	return nil
 }
 
 func (s *Storage) Delete(id event.ID) error {
@@ -78,14 +85,17 @@ func (s *Storage) Delete(id event.ID) error {
 		`DELETE from events where id=$1`,
 		id,
 	)
-	return err
+	if err != nil {
+		return fmt.Errorf("can't delete event from SQL DB: %w", err)
+	}
+	return nil
 }
 
 func (s *Storage) List() (map[event.ID]event.Event, error) {
 	res := make(map[event.ID]event.Event)
 	results, err := s.db.Query(`SELECT (id,title,date,latency,note,userID,notifyTime) from events ORDER BY id`)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
 	defer results.Close()
 	for results.Next() {
@@ -94,16 +104,16 @@ func (s *Storage) List() (map[event.ID]event.Event, error) {
 		var dateRaw string
 		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce list of events getted from SQL DB: %w", err)
 		}
 		evt.Date, err = time.Parse(dateTimeLayout, dateRaw)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce Date getted from SQL DB: %w", err)
 		}
 		res[id] = evt
 	}
 	if results.Err() != nil {
-		return nil, results.Err()
+		return nil, fmt.Errorf("something happens while we try to parce lines getted from SQL DB: %w", results.Err())
 	}
 	return res, nil
 }
@@ -136,7 +146,7 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 		startDate,
 		getEndDate(startDate, rng))
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
 	defer results.Close()
 	for results.Next() {
@@ -145,16 +155,16 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 		var dateRaw string
 		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce list of events getted from SQL DB: %w", err)
 		}
 		evt.Date, err = time.Parse(dateTimeLayout, dateRaw)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce Date getted from SQL DB: %w", err)
 		}
 		res[id] = evt
 	}
 	if results.Err() != nil {
-		return nil, results.Err()
+		return nil, fmt.Errorf("something happens while we try to parce lines getted from SQL DB: %w", results.Err())
 	}
 	return res, nil
 }
@@ -168,7 +178,7 @@ func (s *Storage) GetNotifications() (map[event.ID]event.Event, error) {
 				ORDER BY id`,
 		time.Now())
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
 	defer results.Close()
 	for results.Next() {
@@ -177,16 +187,16 @@ func (s *Storage) GetNotifications() (map[event.ID]event.Event, error) {
 		var dateRaw string
 		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce list of events getted from SQL DB: %w", err)
 		}
 		evt.Date, err = time.Parse(dateTimeLayout, dateRaw)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("can't parce Date getted from SQL DB: %w", err)
 		}
 		res[id] = evt
 	}
 	if results.Err() != nil {
-		return nil, results.Err()
+		return nil, fmt.Errorf("something happens while we try to parce lines getted from SQL DB: %w", results.Err())
 	}
 	return res, nil
 }
@@ -198,7 +208,10 @@ func (s *Storage) SetNotified(id event.ID) error {
 		where id=$1`,
 		id,
 	)
-	return err
+	if err != nil {
+		return fmt.Errorf("can't set event as notified in SQL DB: %w", err)
+	}
+	return nil
 }
 
 func (s *Storage) PurgeOldEvents(days int64) (int64, error) {
@@ -207,9 +220,13 @@ func (s *Storage) PurgeOldEvents(days int64) (int64, error) {
 		time.Now().Add(-time.Duration(days*24*60*60)),
 	)
 	if err != nil {
-		return 0, err
+		return 0, fmt.Errorf("can't delete old events from SQL DB: %w", err)
 	}
-	return r.RowsAffected()
+	l, err := r.RowsAffected()
+	if err != nil {
+		return 0, fmt.Errorf("can't run RowAffected on SQL DB query: %w", err)
+	}
+	return l, nil
 }
 
 func getEndDate(startDate time.Time, rng string) time.Time {

From 1131e2644f34b2abab744f277f522ca7bb7e90c3 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 30 Nov 2020 16:12:13 +0300
Subject: [PATCH 07/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile               |   4 +-
 .../cmd/calendar/main_test.go                 | 177 ++++++++++++-
 .../cmd/integration/calendar.go               | 250 ++++++++++++++++++
 hw12_13_14_15_calendar/configs/calendar.conf  |   6 +-
 .../pkg/api/public/grpcclient.go              |   8 +-
 .../pkg/api/public/handler.go                 |  10 +-
 6 files changed, 433 insertions(+), 22 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/cmd/integration/calendar.go

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index ad498fa..d8038d2 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -9,8 +9,8 @@ start: build-all rabbit-start calendar-start scheduler-start sender-start
 
 stop: scheduler-stop sender-stop calendar-stop rabbit-stop
 
-integration:
-	go test -v -race ./cmd/calendar/...
+integration-test:
+	go test -count 10 -race ./cmd/calendar/... --config ./../../configs/calendar.conf
 
 test:
 	go test -race ./internal/... ./pkg/...
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main_test.go b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
index 50dfc20..9828b81 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main_test.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"github.com/golang/protobuf/ptypes"
 	"github.com/golang/protobuf/ptypes/duration"
+	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/golang/protobuf/ptypes/timestamp"
 	"github.com/stretchr/testify/require"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
@@ -11,6 +12,7 @@ import (
 	"sync"
 	"testing"
 	"time"
+	"os"
 )
 
 var _ = func() bool {
@@ -37,24 +39,34 @@ var testEvent02 = public.CreateReq{
 	NotifyTime: dur2pbduration(5 * time.Minute),
 	UserID:     2222,
 }
-
-func TestSimple(t *testing.T) {
-	wg := sync.WaitGroup{}
+func TestMain(m *testing.M) {
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
-	defer cancel()
 	go func(ctx context.Context) {
 		main()
 	}(ctx)
-	publicAPI, err := public.NewClient("localhost", "50051")
+	time.Sleep(1*time.Second)
+
+	c := m.Run()
+
+	cancel()
+	os.Exit(c)
+}
+
+func TestPublicGRPCEndpoint(t *testing.T) {
+	wg := sync.WaitGroup{}
+	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+	defer cancel()
+	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
 	require.NoError(t, err)
 
-	wg.Add(2)
+	wg.Add(5)
 	// Реализовать тесты логики приложения:
-	t.Run("test public GRPC.Create with GRPC.GetById", func(t *testing.T) {
+	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
 		require.Greater(t, resp1.ID, int64(0))
+
 		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
 		require.NoError(t, err)
 		require.Equal(t, 1, len(resp2.Events))
@@ -64,7 +76,7 @@ func TestSimple(t *testing.T) {
 		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
 	})
 
-	t.Run("test public GRPC.Update with GRPC.GetById", func(t *testing.T) {
+	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
@@ -79,9 +91,158 @@ func TestSimple(t *testing.T) {
 		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
 		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
 	})
+
+	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.Error(t, err)
+		require.Nil(t, resp2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		resp2, err := publicAPI.Create(ctx, &testEvent02)
+		require.NoError(t, err)
+		require.NotEqual(t, resp1.ID, resp2.ID)
+
+		list, err := publicAPI.List(ctx, &empty.Empty{})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1, e2 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+			if v.ID==resp2.ID {
+				e2=true
+			}
+		}
+		require.True(t, e1)
+		require.True(t, e2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+		}
+		require.True(t, e1)
+	})
+
 	wg.Wait()
 }
 
+func TestPublicAPIEndpoint(t *testing.T) {
+	wg := sync.WaitGroup{}
+	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+	defer cancel()
+	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
+	require.NoError(t, err)
+
+	wg.Add(5)
+	// Реализовать тесты логики приложения:
+	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.Error(t, err)
+		require.Nil(t, resp2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		resp2, err := publicAPI.Create(ctx, &testEvent02)
+		require.NoError(t, err)
+		require.NotEqual(t, resp1.ID, resp2.ID)
+
+		list, err := publicAPI.List(ctx, &empty.Empty{})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1, e2 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+			if v.ID==resp2.ID {
+				e2=true
+			}
+		}
+		require.True(t, e1)
+		require.True(t, e2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+		}
+		require.True(t, e1)
+	})
+
+	wg.Wait()
+}
+
+
 func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
 	r, err := ptypes.TimestampProto(t)
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/cmd/integration/calendar.go b/hw12_13_14_15_calendar/cmd/integration/calendar.go
new file mode 100644
index 0000000..5be34ea
--- /dev/null
+++ b/hw12_13_14_15_calendar/cmd/integration/calendar.go
@@ -0,0 +1,250 @@
+package main
+
+import (
+	"context"
+	"fmt"
+	"github.com/golang/protobuf/ptypes"
+	"github.com/golang/protobuf/ptypes/duration"
+	"github.com/golang/protobuf/ptypes/empty"
+	"github.com/golang/protobuf/ptypes/timestamp"
+	"github.com/stretchr/testify/require"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"log"
+	"sync"
+	"testing"
+	"time"
+)
+
+var testEvent01 = public.CreateReq{
+	Title:      "Test event 01",
+	Date:       time2pbtimestamp(time.Now().Add(30 * time.Second)),
+	Latency:    dur2pbduration(24 * time.Hour),
+	Note:       "Note of test event 01",
+	NotifyTime: dur2pbduration(5 * time.Minute),
+	UserID:     1111,
+}
+
+var testEvent02 = public.CreateReq{
+	Title:      "Test event 02",
+	Date:       time2pbtimestamp(time.Now().Add(60 * time.Second)),
+	Latency:    dur2pbduration(2 * 24 * time.Hour),
+	Note:       "Note of test event 02",
+	NotifyTime: dur2pbduration(5 * time.Minute),
+	UserID:     2222,
+}
+
+func main() {
+	if err := TestPublicAPIEndpoint(); err != nil {
+		log.Fatalf("TestPublicAPIEndpoint FAIL: %w",err)
+	}
+
+	if err := TestPublicGRPCEndpoint(); err != nil {
+		log.Fatalf("TestPublicGRPCEndpoint FAIL: %w",err)
+	}
+
+}
+
+func TestPublicGRPCEndpoint() error {
+	wg := sync.WaitGroup{}
+	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+	defer cancel()
+	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
+	if err != nil {
+		return err
+	}
+
+	wg.Add(5)
+	// Реализовать тесты логики приложения:
+	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.Error(t, err)
+		require.Nil(t, resp2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		resp2, err := publicAPI.Create(ctx, &testEvent02)
+		require.NoError(t, err)
+		require.NotEqual(t, resp1.ID, resp2.ID)
+
+		list, err := publicAPI.List(ctx, &empty.Empty{})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1, e2 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+			if v.ID==resp2.ID {
+				e2=true
+			}
+		}
+		require.True(t, e1)
+		require.True(t, e2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+		}
+		require.True(t, e1)
+	})
+
+	wg.Wait()
+}
+
+func TestPublicAPIEndpoint() error {
+	wg := sync.WaitGroup{}
+	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+	defer cancel()
+	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
+	require.NoError(t, err)
+
+	wg.Add(5)
+	// Реализовать тесты логики приложения:
+	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.NoError(t, err)
+		require.Equal(t, 1, len(resp2.Events))
+		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
+		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
+		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
+		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
+	})
+
+	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		require.Greater(t, resp1.ID, int64(0))
+		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
+		require.NoError(t, err)
+		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
+		require.Error(t, err)
+		require.Nil(t, resp2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		resp2, err := publicAPI.Create(ctx, &testEvent02)
+		require.NoError(t, err)
+		require.NotEqual(t, resp1.ID, resp2.ID)
+
+		list, err := publicAPI.List(ctx, &empty.Empty{})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1, e2 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+			if v.ID==resp2.ID {
+				e2=true
+			}
+		}
+		require.True(t, e1)
+		require.True(t, e2)
+	})
+
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+		defer wg.Done()
+		resp1, err := publicAPI.Create(ctx, &testEvent01)
+		require.NoError(t, err)
+		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		require.NoError(t, err)
+		require.GreaterOrEqual(t, len(list.Events), 2)
+		var e1 bool
+		for _,v := range list.Events {
+			if v.ID==resp1.ID {
+				e1=true
+			}
+		}
+		require.True(t, e1)
+	})
+
+	wg.Wait()
+}
+
+
+func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
+	r, err := ptypes.TimestampProto(t)
+	if err != nil {
+		log.Fatalf("cant convert Time to Timestamp: %s", err.Error())
+	}
+	return r
+}
+
+func dur2pbduration(t time.Duration) *duration.Duration {
+	return ptypes.DurationProto(t)
+}
diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index 21dc460..e787d79 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -1,13 +1,13 @@
 [Grpc]
-Address = "0.0.0.0"
+Address = "localhost"
 Port = "50051"
 
 [HTTP]
-Address = "0.0.0.0"
+Address = "localhost"
 Port = "50052"
 
 [API]
-Address = "0.0.0.0"
+Address = "localhost"
 Port = "50053"
 
 [Logger]
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
index 42523d8..a81ecc9 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
@@ -1,14 +1,14 @@
 package public
 
 import (
+	"context"
 	"fmt"
-	"net"
-
 	"google.golang.org/grpc"
+	"net"
 )
 
-func NewClient(addr, port string) (GrpcClient, error) {
-	conn, err := grpc.Dial(net.JoinHostPort(addr, port), grpc.WithInsecure())
+func NewClient(ctx context.Context, addr, port string) (GrpcClient, error) {
+	conn, err := grpc.DialContext(ctx, net.JoinHostPort(addr, port), grpc.WithInsecure())
 	if err != nil {
 		return nil, fmt.Errorf("can't dial GRPC server: %w", err)
 	}
diff --git a/hw12_13_14_15_calendar/pkg/api/public/handler.go b/hw12_13_14_15_calendar/pkg/api/public/handler.go
index 82c2af7..ff718c2 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/handler.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handler.go
@@ -56,21 +56,21 @@ func (s Service) Update(ctx context.Context, e *UpdateReq) (*empty.Empty, error)
 	cid, ce, err := s.buildStorageEventAndID(e)
 	if err != nil {
 		s.App.Logger.Errorf("inconvertible event: %w", err)
-		return nil, status.Errorf(codes.Internal, "inconvertible")
+		return &empty.Empty{}, status.Errorf(codes.Internal, "inconvertible")
 	}
 	if s.App.Storage.Update(cid, ce) != nil {
 		s.App.Logger.Errorf("can't update event in storage: %w", err)
-		return nil, status.Errorf(codes.Internal, "storage error: can't update event")
+		return &empty.Empty{}, status.Errorf(codes.Internal, "storage error: can't update event")
 	}
-	return nil, nil
+	return &empty.Empty{}, nil
 }
 
 func (s Service) Delete(ctx context.Context, e *DeleteReq) (*empty.Empty, error) {
 	if err := s.App.Storage.Delete(event.ID(e.ID)); err != nil {
 		s.App.Logger.Errorf("can't update event in storage: %w", err)
-		return nil, status.Errorf(codes.Internal, "storage error: can't update event")
+		return &empty.Empty{}, status.Errorf(codes.Internal, "storage error: can't update event")
 	}
-	return nil, nil
+	return &empty.Empty{}, nil
 }
 
 func (s Service) List(ctx context.Context, e *empty.Empty) (*ListResp, error) {

From e8e738ee78685c7adc52a214990faf8a3ee355b8 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Wed, 2 Dec 2020 15:55:35 +0300
Subject: [PATCH 08/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile               |  6 +-
 .../cicd/calendar/Dockerfile                  |  6 +-
 .../cicd/docker-compose.yml                   | 91 ++++++++++++++-----
 hw12_13_14_15_calendar/cicd/goose/Dockerfile  |  5 +
 .../cicd/scheduler/Dockerfile                 |  4 +-
 hw12_13_14_15_calendar/cicd/sender/Dockerfile |  4 +-
 .../cmd/calendar/main_test.go                 | 46 +++++-----
 hw12_13_14_15_calendar/cmd/scheduler/main.go  |  5 +-
 hw12_13_14_15_calendar/cmd/sender/main.go     |  5 +-
 .../migrations/20200924000000_init.sql        | 15 ++-
 .../pkg/api/public/grpcclient.go              |  3 +-
 .../integration/calendar.go => test/main.go}  | 50 +++++-----
 12 files changed, 139 insertions(+), 101 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/cicd/goose/Dockerfile
 rename hw12_13_14_15_calendar/{cmd/integration/calendar.go => test/main.go} (91%)

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index d8038d2..a5cfb81 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -28,10 +28,10 @@ generate:
 compose-build:
 	sudo -S docker-compose -f ./cicd/docker-compose.yml build
 
-compose-up:
-	sudo -S docker-compose -f ./cicd/docker-compose.yml up -d
+up:
+	sudo -S docker-compose -f ./cicd/docker-compose.yml up -d --build
 
-compose-down:
+down:
 	sudo -S docker-compose -f ./cicd/docker-compose.yml down
 
 calendar-start:
diff --git a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
index 290f3f3..1c4afea 100644
--- a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/calendar/.
-RUN GOOS=linux GOARCH=amd64 go build -a -o calendar ./cmd/calendar/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o calendar ./cmd/calendar/.
 
 FROM alpine:latest
 ENV APP_GRPC_ADDRESS=0.0.0.0
@@ -14,7 +14,7 @@ ENV APP_API_ADDRESS=0.0.0.0
 ENV APP_API_PORT=50053
 ENV APP_LOGGER_FILE=/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
-ENV APP_STORAGE_INMEMORY=true
+ENV APP_STORAGE_INMEMORY=false
 ENV APP_STORAGE_SQLHOST=psql
 ENV APP_STORAGE_SQLPORT=5432
 ENV APP_STORAGE_SQLDBASE=calendar
@@ -25,4 +25,4 @@ COPY --from=builder /app/calendar ./sbin
 EXPOSE ${APP_GRPC_PORT}
 EXPOSE ${APP_HTTP_PORT}
 EXPOSE ${APP_API_PORT}
-CMD ["calendar"]
+ENTRYPOINT ["calendar"]
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
index 7a67bcd..924ba16 100644
--- a/hw12_13_14_15_calendar/cicd/docker-compose.yml
+++ b/hw12_13_14_15_calendar/cicd/docker-compose.yml
@@ -1,5 +1,68 @@
 version: '3'
 services:
+  calendar:
+    build:
+      context: ..
+      dockerfile: ./cicd/calendar/Dockerfile
+    volumes:
+      - ../calendar.log:/calendar.log
+    ports:
+      - "8888:8888"
+      - "50051:50051"
+      - "50053:50053"
+    expose:
+      - 8888
+      - 50051
+      - 50053
+    depends_on:
+     - psql
+     - goose
+
+  scheduler:
+    build:
+      context: ..
+      dockerfile: ./cicd/scheduler/Dockerfile
+    volumes:
+     - ../calendar.log:/calendar.log
+    depends_on:
+      - rabbitmq
+      - calendar
+    restart: on-failure
+
+  sender:
+    build:
+      context: ..
+      dockerfile: ./cicd/sender/Dockerfile
+    volumes:
+      - ../calendar.log:/calendar.log
+    depends_on:
+     - rabbitmq
+    restart: on-failure
+
+  goose:
+    build:
+      context: ..
+      dockerfile: ./cicd/goose/Dockerfile
+    environment:
+      GOOSE_DRIVER: "postgres"
+      GOOSE_DBSTRING: "host=psql port=5432 user=calendar password=12345678 dbname=calendar sslmode=disable"
+    depends_on:
+      - psql
+    restart: on-failure
+
+  psql:
+    image: postgres:11-alpine
+    hostname: "psql"
+    container_name: psql
+    environment:
+      POSTGRES_USER: calendar
+      POSTGRES_PASSWORD: 12345678
+      POSTGRES_DB: calendar
+    ports:
+      - "5432:5432"
+    expose:
+      - 5432
+
   rabbitmq:
     image: rabbitmq:3-management-alpine
     hostname: "rabbitmq"
@@ -12,28 +75,6 @@ services:
     ports:
       - "5672:5672"
       - "15672:15672"
-  #calendar:
-  #  build:
-  #    context: ..
-  #    dockerfile: ./cicd/calendar/Dockerfile
-  #  ports:
-  #    - "8888:8888"
-  #  volumes:
-  #    - ../calendar.log:/calendar.log
-  #scheduler:
-  #  build:
-  #    context: ..
-  #    dockerfile: ./cicd/scheduler/Dockerfile
-  #  volumes:
-  #    - ../calendar.log:/calendar.log
-  #  depends_on:
-  #    - rabbitmq
-  #    - calendar
-  #sender:
-  #  build:
-  #    context: ..
-  #    dockerfile: ./cicd/sender/Dockerfile
-  #  volumes:
-  #    - ../calendar.log:/calendar.log
-  #  depends_on:
-  #    - rabbitmq
\ No newline at end of file
+    expose:
+      - 15672
+      - 5672
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/goose/Dockerfile b/hw12_13_14_15_calendar/cicd/goose/Dockerfile
new file mode 100644
index 0000000..13f1d89
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/goose/Dockerfile
@@ -0,0 +1,5 @@
+FROM golang:1.14
+WORKDIR /
+RUN go get -u github.com/pressly/goose/cmd/goose
+COPY . .
+ENTRYPOINT ["/go/bin/goose", "-dir", "migrations", "up"]
diff --git a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
index 69fa4c4..170b415 100644
--- a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/scheduler/.
-RUN GOOS=linux GOARCH=amd64 go build -a -o scheduler ./cmd/scheduler/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o scheduler ./cmd/scheduler/.
 
 FROM alpine:latest
 ENV APP_RABBITMQ_ADDRESS=rabbitmq
@@ -19,4 +19,4 @@ ENV APP_LOGGER_FILE=/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/scheduler ./sbin
-CMD ["scheduler"]
+ENTRYPOINT ["scheduler"]
diff --git a/hw12_13_14_15_calendar/cicd/sender/Dockerfile b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
index f97bc8a..4b8cb5d 100644
--- a/hw12_13_14_15_calendar/cicd/sender/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
@@ -3,7 +3,7 @@ RUN mkdir -p /app
 WORKDIR /app
 COPY . .
 RUN go get -d ./cmd/sender/.
-RUN GOOS=linux GOARCH=amd64 go build -a -o sender ./cmd/sender/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o sender ./cmd/sender/.
 
 FROM alpine:latest
 ENV APP_RABBITMQ_ADDRESS=rabbitmq
@@ -17,4 +17,4 @@ ENV APP_LOGGER_FILE=/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/sender ./sbin
-CMD ["sender"]
+ENTRYPOINT ["sender"]
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main_test.go b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
index 9828b81..baf13bc 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main_test.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
@@ -9,10 +9,10 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"log"
+	"os"
 	"sync"
 	"testing"
 	"time"
-	"os"
 )
 
 var _ = func() bool {
@@ -39,12 +39,13 @@ var testEvent02 = public.CreateReq{
 	NotifyTime: dur2pbduration(5 * time.Minute),
 	UserID:     2222,
 }
+
 func TestMain(m *testing.M) {
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	go func(ctx context.Context) {
 		main()
 	}(ctx)
-	time.Sleep(1*time.Second)
+	time.Sleep(1 * time.Second)
 
 	c := m.Run()
 
@@ -116,29 +117,29 @@ func TestPublicGRPCEndpoint(t *testing.T) {
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1, e2 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
-			if v.ID==resp2.ID {
-				e2=true
+			if v.ID == resp2.ID {
+				e2 = true
 			}
 		}
 		require.True(t, e1)
 		require.True(t, e2)
 	})
 
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
 		}
 		require.True(t, e1)
@@ -211,29 +212,29 @@ func TestPublicAPIEndpoint(t *testing.T) {
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1, e2 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
-			if v.ID==resp2.ID {
-				e2=true
+			if v.ID == resp2.ID {
+				e2 = true
 			}
 		}
 		require.True(t, e1)
 		require.True(t, e2)
 	})
 
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
 		}
 		require.True(t, e1)
@@ -242,7 +243,6 @@ func TestPublicAPIEndpoint(t *testing.T) {
 	wg.Wait()
 }
 
-
 func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
 	r, err := ptypes.TimestampProto(t)
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/cmd/scheduler/main.go b/hw12_13_14_15_calendar/cmd/scheduler/main.go
index 7093f26..b94c8d9 100644
--- a/hw12_13_14_15_calendar/cmd/scheduler/main.go
+++ b/hw12_13_14_15_calendar/cmd/scheduler/main.go
@@ -2,14 +2,13 @@ package main
 
 import (
 	"flag"
+	_ "github.com/go-sql-driver/mysql"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sheduler"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"log"
 	"os"
 	"os/signal"
 	"syscall"
-
-	_ "github.com/go-sql-driver/mysql"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 )
 
 var configFile string
diff --git a/hw12_13_14_15_calendar/cmd/sender/main.go b/hw12_13_14_15_calendar/cmd/sender/main.go
index 62cafba..1b89096 100644
--- a/hw12_13_14_15_calendar/cmd/sender/main.go
+++ b/hw12_13_14_15_calendar/cmd/sender/main.go
@@ -2,14 +2,13 @@ package main
 
 import (
 	"flag"
+	_ "github.com/go-sql-driver/mysql"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sender"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"log"
 	"os"
 	"os/signal"
 	"syscall"
-
-	_ "github.com/go-sql-driver/mysql"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 )
 
 var configFile string
diff --git a/hw12_13_14_15_calendar/migrations/20200924000000_init.sql b/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
index 5d48a9b..834aaae 100644
--- a/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
+++ b/hw12_13_14_15_calendar/migrations/20200924000000_init.sql
@@ -1,16 +1,15 @@
 -- +goose Up
 -- +goose StatementBegin
 CREATE TABLE events (
-	id int(16) NOT NULL AUTO_INCREMENT,
+	id serial NOT NULL,
 	title varchar(255) NOT NULL,
-	date datetime NOT NULL,
-	latency int(16) NOT NULL,
-	note text,
-	userID int(16),
-	notifyTime int(16),
+	date timestamptz NOT NULL,
+	latency int8 NOT NULL,
+	note text NULL,
+	userID int8 NOT NULL,
+	notifyTime timestamptz NULL,
 	notified bool
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;;
+);
 -- +goose StatementEnd
 
 -- +goose Down
diff --git a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
index a81ecc9..1a2a34b 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/grpcclient.go
@@ -3,8 +3,9 @@ package public
 import (
 	"context"
 	"fmt"
-	"google.golang.org/grpc"
 	"net"
+
+	"google.golang.org/grpc"
 )
 
 func NewClient(ctx context.Context, addr, port string) (GrpcClient, error) {
diff --git a/hw12_13_14_15_calendar/cmd/integration/calendar.go b/hw12_13_14_15_calendar/test/main.go
similarity index 91%
rename from hw12_13_14_15_calendar/cmd/integration/calendar.go
rename to hw12_13_14_15_calendar/test/main.go
index 5be34ea..6b52288 100644
--- a/hw12_13_14_15_calendar/cmd/integration/calendar.go
+++ b/hw12_13_14_15_calendar/test/main.go
@@ -35,11 +35,11 @@ var testEvent02 = public.CreateReq{
 
 func main() {
 	if err := TestPublicAPIEndpoint(); err != nil {
-		log.Fatalf("TestPublicAPIEndpoint FAIL: %w",err)
+		log.Fatalf("TestPublicAPIEndpoint FAIL: %w", err)
 	}
 
 	if err := TestPublicGRPCEndpoint(); err != nil {
-		log.Fatalf("TestPublicGRPCEndpoint FAIL: %w",err)
+		log.Fatalf("TestPublicGRPCEndpoint FAIL: %w", err)
 	}
 
 }
@@ -69,7 +69,6 @@ func TestPublicGRPCEndpoint() error {
 		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
 		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
 	})
-
 	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
@@ -85,7 +84,6 @@ func TestPublicGRPCEndpoint() error {
 		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
 		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
 	})
-
 	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
@@ -97,7 +95,6 @@ func TestPublicGRPCEndpoint() error {
 		require.Error(t, err)
 		require.Nil(t, resp2)
 	})
-
 	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
@@ -110,34 +107,32 @@ func TestPublicGRPCEndpoint() error {
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1, e2 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
-			if v.ID==resp2.ID {
-				e2=true
+			if v.ID == resp2.ID {
+				e2 = true
 			}
 		}
 		require.True(t, e1)
 		require.True(t, e2)
 	})
-
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
 		}
 		require.True(t, e1)
 	})
-
 	wg.Wait()
 }
 
@@ -205,29 +200,29 @@ func TestPublicAPIEndpoint() error {
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1, e2 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
-			if v.ID==resp2.ID {
-				e2=true
+			if v.ID == resp2.ID {
+				e2 = true
 			}
 		}
 		require.True(t, e1)
 		require.True(t, e2)
 	})
 
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T){
+	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
 		defer wg.Done()
 		resp1, err := publicAPI.Create(ctx, &testEvent01)
 		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx,&public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
+		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
 		require.NoError(t, err)
 		require.GreaterOrEqual(t, len(list.Events), 2)
 		var e1 bool
-		for _,v := range list.Events {
-			if v.ID==resp1.ID {
-				e1=true
+		for _, v := range list.Events {
+			if v.ID == resp1.ID {
+				e1 = true
 			}
 		}
 		require.True(t, e1)
@@ -236,7 +231,6 @@ func TestPublicAPIEndpoint() error {
 	wg.Wait()
 }
 
-
 func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
 	r, err := ptypes.TimestampProto(t)
 	if err != nil {

From 8680c3a85c56c8a685923041319a29443288cffe Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Thu, 3 Dec 2020 09:01:52 -0500
Subject: [PATCH 09/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile                            | 7 ++++++-
 hw12_13_14_15_calendar/cicd/calendar/Dockerfile            | 2 +-
 hw12_13_14_15_calendar/cicd/docker-compose.yml             | 6 +++---
 hw12_13_14_15_calendar/cicd/scheduler/Dockerfile           | 2 +-
 hw12_13_14_15_calendar/cicd/sender/Dockerfile              | 2 +-
 hw12_13_14_15_calendar/configs/calendar.conf               | 2 +-
 hw12_13_14_15_calendar/configs/scheduler.conf              | 2 +-
 hw12_13_14_15_calendar/configs/sender.conf                 | 2 +-
 .../{20200924000000_init.sql => 20201203000000_init.sql}   | 0
 9 files changed, 15 insertions(+), 10 deletions(-)
 rename hw12_13_14_15_calendar/migrations/{20200924000000_init.sql => 20201203000000_init.sql} (100%)

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index a5cfb81..bdc5ae9 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -31,9 +31,14 @@ compose-build:
 up:
 	sudo -S docker-compose -f ./cicd/docker-compose.yml up -d --build
 
-down:
+down: shutdown clean
+
+shutdown:
 	sudo -S docker-compose -f ./cicd/docker-compose.yml down
 
+clean:
+	sudo docker rmi $(sudo docker images | grep '<none>' | awk '{print $3}')
+
 calendar-start:
 	nohup  ./bin/calendar -config ./configs/calendar.conf > /dev/null 2>&1 &
 calendar-stop:
diff --git a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
index 1c4afea..7bed24d 100644
--- a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
@@ -12,7 +12,7 @@ ENV APP_HTTP_ADDRESS=0.0.0.0
 ENV APP_HTTP_PORT=8888
 ENV APP_API_ADDRESS=0.0.0.0
 ENV APP_API_PORT=50053
-ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_FILE=/logs/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
 ENV APP_STORAGE_INMEMORY=false
 ENV APP_STORAGE_SQLHOST=psql
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
index 924ba16..7dc2b00 100644
--- a/hw12_13_14_15_calendar/cicd/docker-compose.yml
+++ b/hw12_13_14_15_calendar/cicd/docker-compose.yml
@@ -5,7 +5,7 @@ services:
       context: ..
       dockerfile: ./cicd/calendar/Dockerfile
     volumes:
-      - ../calendar.log:/calendar.log
+      - ../logs:/logs
     ports:
       - "8888:8888"
       - "50051:50051"
@@ -23,7 +23,7 @@ services:
       context: ..
       dockerfile: ./cicd/scheduler/Dockerfile
     volumes:
-     - ../calendar.log:/calendar.log
+      - ../logs:/logs
     depends_on:
       - rabbitmq
       - calendar
@@ -34,7 +34,7 @@ services:
       context: ..
       dockerfile: ./cicd/sender/Dockerfile
     volumes:
-      - ../calendar.log:/calendar.log
+      - ../logs:/logs
     depends_on:
      - rabbitmq
     restart: on-failure
diff --git a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
index 170b415..c5366c9 100644
--- a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
@@ -15,7 +15,7 @@ ENV APP_RABBITMQ_QUEUE=notifications
 ENV APP_RABBITMQ_KEY=events
 ENV APP_API_ADDRESS=calendar
 ENV APP_API_PORT=50053
-ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_FILE=/logs/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/scheduler ./sbin
diff --git a/hw12_13_14_15_calendar/cicd/sender/Dockerfile b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
index 4b8cb5d..fa9d145 100644
--- a/hw12_13_14_15_calendar/cicd/sender/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
@@ -13,7 +13,7 @@ ENV APP_RABBITMQ_PASS=rabbit
 ENV APP_RABBITMQ_EXCHANGE=calendar
 ENV APP_RABBITMQ_QUEUE=notifications
 ENV APP_RABBITMQ_KEY=events
-ENV APP_LOGGER_FILE=/calendar.log
+ENV APP_LOGGER_FILE=/logs/calendar.log
 ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/sender ./sbin
diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index e787d79..3518edc 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -11,7 +11,7 @@ Address = "localhost"
 Port = "50053"
 
 [Logger]
-File = "./calendar.log"
+File = "./logs/calendar.log"
 Level = "INFO"
 
 [Storage]
diff --git a/hw12_13_14_15_calendar/configs/scheduler.conf b/hw12_13_14_15_calendar/configs/scheduler.conf
index 2ea7915..da6ef69 100644
--- a/hw12_13_14_15_calendar/configs/scheduler.conf
+++ b/hw12_13_14_15_calendar/configs/scheduler.conf
@@ -8,7 +8,7 @@ Queue = "notifications"
 Key = "events"
 
 [Logger]
-File = "./calendar.log"
+File = "./logs/calendar.log"
 Level = "INFO"
 
 [API]
diff --git a/hw12_13_14_15_calendar/configs/sender.conf b/hw12_13_14_15_calendar/configs/sender.conf
index cbfd27d..2e6ebcc 100644
--- a/hw12_13_14_15_calendar/configs/sender.conf
+++ b/hw12_13_14_15_calendar/configs/sender.conf
@@ -8,5 +8,5 @@ Queue = "notifications"
 Key = "events"
 
 [Logger]
-File = "./calendar.log"
+File = "./logs/calendar.log"
 Level = "INFO"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/migrations/20200924000000_init.sql b/hw12_13_14_15_calendar/migrations/20201203000000_init.sql
similarity index 100%
rename from hw12_13_14_15_calendar/migrations/20200924000000_init.sql
rename to hw12_13_14_15_calendar/migrations/20201203000000_init.sql

From a0b572be3a61d8437aadff6e0ff8fb88cfa04414 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Tue, 16 Mar 2021 15:47:50 -0400
Subject: [PATCH 10/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile               |  53 ++--
 .../cicd/calendar/Dockerfile                  |  17 +-
 hw12_13_14_15_calendar/cicd/dc_calendar.yml   |  29 +++
 hw12_13_14_15_calendar/cicd/dc_sender.yml     |  20 ++
 hw12_13_14_15_calendar/cicd/dc_sheduler.yml   |  22 ++
 hw12_13_14_15_calendar/cicd/dc_sup.yml        |  39 +++
 .../cicd/docker-compose.yml                   |  80 ------
 .../cicd/scheduler/Dockerfile                 |  11 -
 hw12_13_14_15_calendar/cicd/sender/Dockerfile |   9 -
 hw12_13_14_15_calendar/configs/calendar.conf  |   2 +-
 hw12_13_14_15_calendar/go.mod                 |   8 +-
 hw12_13_14_15_calendar/go.sum                 |  12 +-
 .../internal/calendar/app_calendar.go         |   5 -
 .../migrations/20201203000000_init.sql        |   4 +-
 hw12_13_14_15_calendar/pkg/storage/sql/sql.go |  49 ++--
 hw12_13_14_15_calendar/test/client/grpcapi.go |  97 +++++++
 hw12_13_14_15_calendar/test/client/httpapi.go | 150 +++++++++++
 hw12_13_14_15_calendar/test/client/iface.go   |  13 +
 hw12_13_14_15_calendar/test/main.go           | 236 +-----------------
 hw12_13_14_15_calendar/test/main_test.go      | 120 +++++++++
 hw12_13_14_15_calendar/test/misc/misc.go      |  40 +++
 21 files changed, 583 insertions(+), 433 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/cicd/dc_calendar.yml
 create mode 100644 hw12_13_14_15_calendar/cicd/dc_sender.yml
 create mode 100644 hw12_13_14_15_calendar/cicd/dc_sheduler.yml
 create mode 100644 hw12_13_14_15_calendar/cicd/dc_sup.yml
 delete mode 100644 hw12_13_14_15_calendar/cicd/docker-compose.yml
 create mode 100644 hw12_13_14_15_calendar/test/client/grpcapi.go
 create mode 100644 hw12_13_14_15_calendar/test/client/httpapi.go
 create mode 100644 hw12_13_14_15_calendar/test/client/iface.go
 create mode 100644 hw12_13_14_15_calendar/test/main_test.go
 create mode 100644 hw12_13_14_15_calendar/test/misc/misc.go

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index bdc5ae9..e92baca 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -1,14 +1,5 @@
 cdir = $(shell pwd)
 
-build-all:
-	go build -o ./bin/calendar ./cmd/calendar/main.go
-	go build -o ./bin/scheduler ./cmd/scheduler/main.go
-	go build -o ./bin/sender ./cmd/sender/main.go
-
-start: build-all rabbit-start calendar-start scheduler-start sender-start
-
-stop: scheduler-stop sender-stop calendar-stop rabbit-stop
-
 integration-test:
 	go test -count 10 -race ./cmd/calendar/... --config ./../../configs/calendar.conf
 
@@ -25,35 +16,31 @@ generate:
 	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public --grpc-gateway_out=logtostderr=true:./pkg/api/public ./api/public/public.proto
 	protoc  -I ./api/private  --go_out=plugins=grpc:./internal/api/private ./api/private/private.proto
 
-compose-build:
-	sudo -S docker-compose -f ./cicd/docker-compose.yml build
+up: sup-up calendar-up sender-up sheduler-up
 
-up:
-	sudo -S docker-compose -f ./cicd/docker-compose.yml up -d --build
+down: calendar-down sender-down sheduler-down sup-down clean
 
-down: shutdown clean
+calendar-up:
+	docker-compose -f ./cicd/dc_calendar.yml up -d --build
+calendar-down:
+	docker-compose -f ./cicd/dc_calendar.yml down
 
-shutdown:
-	sudo -S docker-compose -f ./cicd/docker-compose.yml down
+sender-up:
+	docker-compose -f ./cicd/dc_sender.yml up -d --build
+sender-down:
+	docker-compose -f ./cicd/dc_sender.yml down
+
+sheduler-up:
+	docker-compose -f ./cicd/dc_sheduler.yml up -d --build
+sheduler-down:
+	docker-compose -f ./cicd/dc_sheduler.yml down
+
+sup-up:
+	docker-compose -f ./cicd/dc_sup.yml up -d --build
+sup-down:
+	docker-compose -f ./cicd/dc_sup.yml down
 
 clean:
 	sudo docker rmi $(sudo docker images | grep '<none>' | awk '{print $3}')
 
-calendar-start:
-	nohup  ./bin/calendar -config ./configs/calendar.conf > /dev/null 2>&1 &
-calendar-stop:
-	kill -9 `pgrep calendar`
-
-scheduler-start:
-	nohup  ./bin/scheduler -config ./configs/scheduler.conf > /dev/null 2>&1 &
-scheduler-stop:
-	kill -9 `pgrep scheduler`
-
-sender-start:
-	nohup  ./bin/sender -config ./configs/sender.conf > /dev/null 2>&1 &
-sender-stop:
-	kill -9 `pgrep sender`
-
-
-
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
index 7bed24d..1349c97 100644
--- a/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/calendar/Dockerfile
@@ -6,20 +6,9 @@ RUN go get -d ./cmd/calendar/.
 RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o calendar ./cmd/calendar/.
 
 FROM alpine:latest
-ENV APP_GRPC_ADDRESS=0.0.0.0
-ENV APP_GRPC_PORT=50051
-ENV APP_HTTP_ADDRESS=0.0.0.0
-ENV APP_HTTP_PORT=8888
-ENV APP_API_ADDRESS=0.0.0.0
-ENV APP_API_PORT=50053
-ENV APP_LOGGER_FILE=/logs/calendar.log
-ENV APP_LOGGER_LEVEL=INFO
-ENV APP_STORAGE_INMEMORY=false
-ENV APP_STORAGE_SQLHOST=psql
-ENV APP_STORAGE_SQLPORT=5432
-ENV APP_STORAGE_SQLDBASE=calendar
-ENV APP_STORAGE_SQLUSER=calendar
-ENV APP_STORAGE_SQLPASS=12345678
+ENV APP_GRPC_PORT $APP_GRPC_PORT
+ENV APP_HTTP_PORT $APP_HTTP_PORT
+ENV APP_API_PORT $APP_API_PORT
 WORKDIR /
 COPY --from=builder /app/calendar ./sbin
 EXPOSE ${APP_GRPC_PORT}
diff --git a/hw12_13_14_15_calendar/cicd/dc_calendar.yml b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
new file mode 100644
index 0000000..90c9ab4
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
@@ -0,0 +1,29 @@
+version: '3'
+services:
+  calendar:
+    build:
+      context: ..
+      dockerfile: ./cicd/calendar/Dockerfile
+    volumes:
+      - ../logs:/logs
+    restart: on-failure
+    environment:
+      APP_GRPC_ADDRESS: 0.0.0.0
+      APP_GRPC_PORT: 50051
+      APP_HTTP_ADDRESS: 0.0.0.0
+      APP_HTTP_PORT: 8888
+      APP_API_ADDRESS: 0.0.0.0
+      APP_API_PORT: 50053
+      APP_LOGGER_FILE: /logs/calendar.log
+      APP_LOGGER_LEVEL: INFO
+      APP_STORAGE_INMEMORY: "false"
+      APP_STORAGE_SQLHOST: localhost
+      APP_STORAGE_SQLPORT: 5432
+      APP_STORAGE_SQLDBASE: calendar
+      APP_STORAGE_SQLUSER: calendar
+      APP_STORAGE_SQLPASS: 12345678
+    ports:
+      - 8888:8888
+      - 50051:50051
+      - 50053:50053
+    network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/dc_sender.yml b/hw12_13_14_15_calendar/cicd/dc_sender.yml
new file mode 100644
index 0000000..919eaa1
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/dc_sender.yml
@@ -0,0 +1,20 @@
+version: '3'
+services:
+  sender:
+    build:
+      context: ..
+      dockerfile: ./cicd/sender/Dockerfile
+    volumes:
+      - ../logs:/logs
+    restart: on-failure
+    environment:
+      APP_RABBITMQ_ADDRESS: localhost
+      APP_RABBITMQ_PORT: 5672
+      APP_RABBITMQ_LOGIN: rabbit
+      APP_RABBITMQ_PASS: rabbit
+      APP_RABBITMQ_EXCHANGE: calendar
+      APP_RABBITMQ_QUEUE: notifications
+      APP_RABBITMQ_KEY: events
+      APP_LOGGER_FILE: /logs/calendar.log
+      APP_LOGGER_LEVEL: INFO
+    network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/dc_sheduler.yml b/hw12_13_14_15_calendar/cicd/dc_sheduler.yml
new file mode 100644
index 0000000..725b149
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/dc_sheduler.yml
@@ -0,0 +1,22 @@
+version: '3'
+services:
+  scheduler:
+    build:
+      context: ..
+      dockerfile: ./cicd/scheduler/Dockerfile
+    volumes:
+      - ../logs:/logs
+    restart: on-failure
+    environment:
+      APP_RABBITMQ_ADDRESS: localhost
+      APP_RABBITMQ_PORT: 5672
+      APP_RABBITMQ_LOGIN: rabbit
+      APP_RABBITMQ_PASS: rabbit
+      APP_RABBITMQ_EXCHANGE: calendar
+      APP_RABBITMQ_QUEUE: notifications
+      APP_RABBITMQ_KEY: events
+      APP_API_ADDRESS: localhost
+      APP_API_PORT: 50053
+      APP_LOGGER_FILE: /logs/calendar.log
+      APP_LOGGER_LEVEL: INFO
+    network_mode: host
diff --git a/hw12_13_14_15_calendar/cicd/dc_sup.yml b/hw12_13_14_15_calendar/cicd/dc_sup.yml
new file mode 100644
index 0000000..c186ce3
--- /dev/null
+++ b/hw12_13_14_15_calendar/cicd/dc_sup.yml
@@ -0,0 +1,39 @@
+version: '3'
+services:
+  goose:
+    build:
+      context: ..
+      dockerfile: ./cicd/goose/Dockerfile
+    restart: on-failure
+    environment:
+      GOOSE_DRIVER: "postgres"
+      GOOSE_DBSTRING: "host=localhost port=5432 user=calendar password=12345678 dbname=calendar sslmode=disable"
+    depends_on:
+      - psql
+    network_mode: host
+
+  psql:
+    image: postgres:11-alpine
+    hostname: "psql"
+    container_name: psql
+    environment:
+      POSTGRES_USER: calendar
+      POSTGRES_PASSWORD: 12345678
+      POSTGRES_DB: calendar
+    ports:
+    - 5432:5432
+    network_mode: host
+
+  rabbitmq:
+    image: rabbitmq:3-management-alpine
+    hostname: "rabbitmq"
+    container_name: rabbitmq
+    environment:
+      RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
+      RABBITMQ_DEFAULT_USER: "rabbit"
+      RABBITMQ_DEFAULT_PASS: "rabbit"
+      RABBITMQ_DEFAULT_VHOST: "/"
+    ports:
+      - 15672:15672
+      - 5672:5672
+    network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/docker-compose.yml b/hw12_13_14_15_calendar/cicd/docker-compose.yml
deleted file mode 100644
index 7dc2b00..0000000
--- a/hw12_13_14_15_calendar/cicd/docker-compose.yml
+++ /dev/null
@@ -1,80 +0,0 @@
-version: '3'
-services:
-  calendar:
-    build:
-      context: ..
-      dockerfile: ./cicd/calendar/Dockerfile
-    volumes:
-      - ../logs:/logs
-    ports:
-      - "8888:8888"
-      - "50051:50051"
-      - "50053:50053"
-    expose:
-      - 8888
-      - 50051
-      - 50053
-    depends_on:
-     - psql
-     - goose
-
-  scheduler:
-    build:
-      context: ..
-      dockerfile: ./cicd/scheduler/Dockerfile
-    volumes:
-      - ../logs:/logs
-    depends_on:
-      - rabbitmq
-      - calendar
-    restart: on-failure
-
-  sender:
-    build:
-      context: ..
-      dockerfile: ./cicd/sender/Dockerfile
-    volumes:
-      - ../logs:/logs
-    depends_on:
-     - rabbitmq
-    restart: on-failure
-
-  goose:
-    build:
-      context: ..
-      dockerfile: ./cicd/goose/Dockerfile
-    environment:
-      GOOSE_DRIVER: "postgres"
-      GOOSE_DBSTRING: "host=psql port=5432 user=calendar password=12345678 dbname=calendar sslmode=disable"
-    depends_on:
-      - psql
-    restart: on-failure
-
-  psql:
-    image: postgres:11-alpine
-    hostname: "psql"
-    container_name: psql
-    environment:
-      POSTGRES_USER: calendar
-      POSTGRES_PASSWORD: 12345678
-      POSTGRES_DB: calendar
-    ports:
-      - "5432:5432"
-    expose:
-      - 5432
-
-  rabbitmq:
-    image: rabbitmq:3-management-alpine
-    hostname: "rabbitmq"
-    container_name: rabbitmq
-    environment:
-      RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
-      RABBITMQ_DEFAULT_USER: "rabbit"
-      RABBITMQ_DEFAULT_PASS: "rabbit"
-      RABBITMQ_DEFAULT_VHOST: "/"
-    ports:
-      - "5672:5672"
-      - "15672:15672"
-    expose:
-      - 15672
-      - 5672
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
index c5366c9..0da0f0b 100644
--- a/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/scheduler/Dockerfile
@@ -6,17 +6,6 @@ RUN go get -d ./cmd/scheduler/.
 RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o scheduler ./cmd/scheduler/.
 
 FROM alpine:latest
-ENV APP_RABBITMQ_ADDRESS=rabbitmq
-ENV APP_RABBITMQ_PORT=5672
-ENV APP_RABBITMQ_LOGIN=rabbit
-ENV APP_RABBITMQ_PASS=rabbit
-ENV APP_RABBITMQ_EXCHANGE=calendar
-ENV APP_RABBITMQ_QUEUE=notifications
-ENV APP_RABBITMQ_KEY=events
-ENV APP_API_ADDRESS=calendar
-ENV APP_API_PORT=50053
-ENV APP_LOGGER_FILE=/logs/calendar.log
-ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/scheduler ./sbin
 ENTRYPOINT ["scheduler"]
diff --git a/hw12_13_14_15_calendar/cicd/sender/Dockerfile b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
index fa9d145..747a078 100644
--- a/hw12_13_14_15_calendar/cicd/sender/Dockerfile
+++ b/hw12_13_14_15_calendar/cicd/sender/Dockerfile
@@ -6,15 +6,6 @@ RUN go get -d ./cmd/sender/.
 RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o sender ./cmd/sender/.
 
 FROM alpine:latest
-ENV APP_RABBITMQ_ADDRESS=rabbitmq
-ENV APP_RABBITMQ_PORT=5672
-ENV APP_RABBITMQ_LOGIN=rabbit
-ENV APP_RABBITMQ_PASS=rabbit
-ENV APP_RABBITMQ_EXCHANGE=calendar
-ENV APP_RABBITMQ_QUEUE=notifications
-ENV APP_RABBITMQ_KEY=events
-ENV APP_LOGGER_FILE=/logs/calendar.log
-ENV APP_LOGGER_LEVEL=INFO
 WORKDIR /
 COPY --from=builder /app/sender ./sbin
 ENTRYPOINT ["sender"]
diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index 3518edc..b1f3a9e 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -15,7 +15,7 @@ File = "./logs/calendar.log"
 Level = "INFO"
 
 [Storage]
-inMemory = true
+inMemory = false
 SQLHost = "localhost"
 SQLPort = "5432"
 SQLDbase = "calendar"
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index c5c0f37..c4abac5 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -9,16 +9,12 @@ require (
 	github.com/golang/protobuf v1.4.2
 	github.com/grpc-ecosystem/grpc-gateway v1.15.0
 	github.com/kr/text v0.2.0 // indirect
-	github.com/lib/pq v1.8.0 // indirect
-	github.com/mattn/go-sqlite3 v1.14.5 // indirect
-	github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397
+	github.com/lib/pq v1.10.0
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
-	github.com/pkg/errors v0.9.1
-	github.com/pressly/goose v2.6.0+incompatible // indirect
+	github.com/pkg/errors v0.9.1 // indirect
 	github.com/sirupsen/logrus v1.4.2 // indirect
 	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
-	github.com/ziutek/mymysql v1.5.4 // indirect
 	go.uber.org/zap v1.15.0 // indirect
 	golang.org/x/net v0.0.0-20200625001655-4c5254603344
 	golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index f175e33..a97abb3 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -54,12 +54,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
-github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
-github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
-github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
-github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
-github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397 h1:fbcg7+DIrrjxSsS78ARgJu/qZOO928w4mCj1KBEO7xM=
-github.com/mxschmitt/golang-env-struct v0.0.0-20181017075525-0c54aeca8397/go.mod h1:BvJngicNxsNmAUzt7zXpaoWKwuBiyxnD7DxzxfrrPyY=
+github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
+github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
@@ -68,8 +64,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k=
-github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
@@ -90,8 +84,6 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
-github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
-github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
 go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
diff --git a/hw12_13_14_15_calendar/internal/calendar/app_calendar.go b/hw12_13_14_15_calendar/internal/calendar/app_calendar.go
index c225eca..1ffeebc 100644
--- a/hw12_13_14_15_calendar/internal/calendar/app_calendar.go
+++ b/hw12_13_14_15_calendar/internal/calendar/app_calendar.go
@@ -24,11 +24,6 @@ func New(logger logger.Interface, storage store.StorageInterface) *App {
 	return &App{Logger: logger, Storage: storage}
 }
 
-func (a *App) Handler(w http.ResponseWriter, r *http.Request) {
-	w.WriteHeader(200)
-	_, _ = w.Write([]byte("Hello! I'm calendar app!"))
-}
-
 func (a *App) LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		start := time.Now()
diff --git a/hw12_13_14_15_calendar/migrations/20201203000000_init.sql b/hw12_13_14_15_calendar/migrations/20201203000000_init.sql
index 834aaae..ab9096b 100644
--- a/hw12_13_14_15_calendar/migrations/20201203000000_init.sql
+++ b/hw12_13_14_15_calendar/migrations/20201203000000_init.sql
@@ -3,11 +3,11 @@
 CREATE TABLE events (
 	id serial NOT NULL,
 	title varchar(255) NOT NULL,
-	date timestamptz NOT NULL,
+	date timestamp NOT NULL,
 	latency int8 NOT NULL,
 	note text NULL,
 	userID int8 NOT NULL,
-	notifyTime timestamptz NULL,
+	notifyTime int8 NULL,
 	notified bool
 );
 -- +goose StatementEnd
diff --git a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index 4813232..7549f67 100644
--- a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -3,12 +3,15 @@ package sql
 import (
 	"database/sql"
 	"fmt"
+	"log"
 	"time"
 
+	_ "github.com/lib/pq"
+
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
-const dateTimeLayout = "2006-01-02 15:04:00 -0700"
+const dateTimeLayout = "2006-01-02T15:04:00Z"
 
 type Config struct {
 	User  string
@@ -22,17 +25,12 @@ type Storage struct {
 	db *sql.DB
 }
 
-func New(conf Config) *Storage {
-	return &Storage{}
-}
-
-func (s *Storage) Connect(config Config) error {
-	var err error
-	s.db, err = sql.Open("mysql", config.User+":"+config.Pass+"@tcp("+config.Host+":"+config.Port+")/"+config.Dbase)
+func New(config Config) *Storage {
+	db, err := sql.Open("postgres", "user="+config.User+" password="+config.Pass+" host="+config.Host+" port="+config.Port+" dbname="+config.Dbase+" sslmode=disable")
 	if err != nil {
-		return fmt.Errorf("can't connect to SQL server: %w", err)
+		log.Fatalf("can't connect to db: %s",err.Error())
 	}
-	return nil
+	return &Storage{db: db}
 }
 
 func (s *Storage) Close() error {
@@ -40,25 +38,21 @@ func (s *Storage) Close() error {
 }
 
 func (s *Storage) Create(ev event.Event) (event.ID, error) {
-	res, err := s.db.Exec(
+	lastInsertId := -1
+	if err := s.db.QueryRow(
 		`INSERT INTO events 
 		(title, date, latency, note, userID, notifyTime) VALUES 
-		($1, $2, $3, $4, $5, $6)`,
+		($1, $2, $3, $4, $5, $6) RETURNING id`,
 		ev.Title,
 		ev.Date.Format(dateTimeLayout),
 		ev.Latency,
 		ev.Note,
 		ev.UserID,
 		ev.NotifyTime,
-	)
-	if err != nil {
+	).Scan(&lastInsertId); err != nil {
 		return -1, fmt.Errorf("can't create event in SQL DB: %w", err)
 	}
-	idint64, err := res.LastInsertId()
-	if err != nil {
-		return -1, fmt.Errorf("can't get LastInsertId from SQL DB: %w", err)
-	}
-	return event.ID(idint64), err
+	return event.ID(lastInsertId), nil
 }
 
 func (s *Storage) Update(id event.ID, event event.Event) error {
@@ -93,7 +87,7 @@ func (s *Storage) Delete(id event.ID) error {
 
 func (s *Storage) List() (map[event.ID]event.Event, error) {
 	res := make(map[event.ID]event.Event)
-	results, err := s.db.Query(`SELECT (id,title,date,latency,note,userID,notifyTime) from events ORDER BY id`)
+	results, err := s.db.Query(`SELECT id,title,date,latency,note,userID,notifyTime from events ORDER BY id`)
 	if err != nil {
 		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
@@ -122,7 +116,7 @@ func (s *Storage) GetByID(id event.ID) (event.Event, bool) {
 	var res event.Event
 	var dateRaw string
 	err := s.db.QueryRow(
-		`SELECT (id,title,date,latency,note,userID,notifyTime) from events where id=$1`, id).Scan(res.Title, dateRaw, res.Latency, res.Note, res.UserID, res.NotifyTime)
+		`SELECT title,date,latency,note,userID,notifyTime from events where id=$1`, id).Scan(&res.Title, &dateRaw, &res.Latency, &res.Note, &res.UserID, &res.NotifyTime)
 	if err != nil {
 		return res, false
 	}
@@ -136,15 +130,16 @@ func (s *Storage) GetByID(id event.ID) (event.Event, bool) {
 
 func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event.Event, error) {
 	res := make(map[event.ID]event.Event)
+	endDate := getEndDate(startDate, rng)
+
 	results, err := s.db.Query(
-		`SELECT (id,title,date,latency,note,userID,notifyTime)
+		`SELECT id,title,date,latency,note,userID,notifyTime
 				from events
-				where 	(date>$1 AND date<$2) OR
-						(date+latency>$1 AND date+latency<$2) OR
-						(date<$1 AND date+latency>$2)
+				where (date>=$1 AND date<=$2)
 				ORDER BY id`,
-		startDate,
-		getEndDate(startDate, rng))
+		startDate.Format(dateTimeLayout),
+		endDate.Format(dateTimeLayout))
+
 	if err != nil {
 		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
diff --git a/hw12_13_14_15_calendar/test/client/grpcapi.go b/hw12_13_14_15_calendar/test/client/grpcapi.go
new file mode 100644
index 0000000..e30befc
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/client/grpcapi.go
@@ -0,0 +1,97 @@
+package client
+
+import (
+	"context"
+	"github.com/golang/protobuf/ptypes/empty"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"time"
+)
+
+type GRPCAPI struct{
+	Name string
+	Ctx context.Context
+	Host string
+	Port string
+}
+
+func (h GRPCAPI) GetName() string {
+	return h.Name
+}
+
+func (h GRPCAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return nil, err
+	}
+	resp, err := cliGRPC.Create(ctx, req)
+	if err != nil{
+		return nil, err
+	}
+	return resp, nil
+}
+
+func (h GRPCAPI) Update(req *public.UpdateReq) error {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return err
+	}
+	_, err = cliGRPC.Update(ctx, req)
+	if err != nil{
+		return err
+	}
+	return nil
+}
+
+func (h GRPCAPI) Delete(req *public.DeleteReq) error {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return err
+	}
+	_, err = cliGRPC.Delete(ctx, req)
+	if err != nil{
+		return err
+	}
+	return nil
+}
+
+func (h GRPCAPI) GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error) {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return nil, err
+	}
+	resp, err := cliGRPC.GetByID(ctx, req)
+	if err != nil{
+		return nil, err
+	}
+	return resp, nil
+}
+
+func (h GRPCAPI) List() (*public.ListResp, error) {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return nil, err
+	}
+	resp, err := cliGRPC.List(ctx, &empty.Empty{})
+	if err != nil{
+		return nil, err
+	}
+	return resp, nil
+}
+
+func (h GRPCAPI) GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, error) {
+	ctx, cliGRPC, err := getCli(h)
+	if err != nil{
+		return nil, err
+	}
+	resp, err := cliGRPC.GetByDate(ctx, req)
+	if err != nil{
+		return nil, err
+	}
+	return resp, nil
+}
+
+func getCli(h GRPCAPI) (context.Context, public.GrpcClient, error) {
+	ctx,_ := context.WithTimeout(h.Ctx, 15*time.Second)
+	cliGRPC, err := public.NewClient(ctx,h.Host, h.Port)
+	return ctx, cliGRPC, err
+}
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/test/client/httpapi.go b/hw12_13_14_15_calendar/test/client/httpapi.go
new file mode 100644
index 0000000..d9f3a04
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/client/httpapi.go
@@ -0,0 +1,150 @@
+package client
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"io/ioutil"
+	"net"
+	"net/http"
+	"strconv"
+	"time"
+)
+
+type HTTPAPI struct{
+	Name string
+	BaseURL string
+}
+
+func (h HTTPAPI) GetName() string {
+	return h.Name
+}
+
+func (h HTTPAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
+	jreq,err:= json.Marshal(req)
+	if err != nil {
+		return &public.CreateRsp{}, err
+	}
+	res, body, err := apiCall("POST",h.BaseURL+"/events", jreq)
+	if err != nil {
+		return &public.CreateRsp{}, err
+	}
+	if res.StatusCode!=201 {
+		return &public.CreateRsp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	var createRsp public.CreateRsp
+	err = json.Unmarshal(body,&createRsp)
+	if err != nil {
+		return &public.CreateRsp{}, err
+	}
+	return &createRsp, nil
+}
+
+func (h HTTPAPI) Update(req *public.UpdateReq) error {
+	jreq, err:= json.Marshal(req)
+	if err != nil {
+		return err
+	}
+	res, _, err := apiCall("PUT",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	if err != nil {
+		return err
+	}
+	if res.StatusCode!=201 {
+		return fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	return nil
+}
+
+func (h HTTPAPI) Delete(req *public.DeleteReq) error {
+	jreq, err:= json.Marshal(req)
+	if err != nil {
+		return err
+	}
+	res, _, err := apiCall("DELETE",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	if err != nil {
+		return err
+	}
+	if res.StatusCode!=201 {
+		return fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	return nil
+}
+
+func (h HTTPAPI) GetByID(req *public.GetByIDReq) ( *public.GetByIDResp, error) {
+	jreq, err:= json.Marshal(req)
+	if err != nil {
+		return &public.GetByIDResp{}, err
+	}
+	res, body, err := apiCall("GET",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	if err != nil {
+		return &public.GetByIDResp{}, err
+	}
+	if res.StatusCode!=201 {
+		return &public.GetByIDResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	var getByIDResp public.GetByIDResp
+	err = json.Unmarshal(body,&getByIDResp)
+	if err != nil {
+		return &public.GetByIDResp{}, err
+	}
+	return &getByIDResp, nil
+}
+
+func (h HTTPAPI) List() ( *public.ListResp, error) {
+	res, body, err := apiCall("GET",h.BaseURL+"/events", nil)
+	if err != nil {
+		return &public.ListResp{}, err
+	}
+	if res.StatusCode!=200 {
+		return &public.ListResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	var listResp public.ListResp
+	err = json.Unmarshal(body,&listResp)
+	if err != nil {
+		return &public.ListResp{}, err
+	}
+	return &listResp, nil
+}
+
+func (h HTTPAPI) GetByDate(req *public.GetByDateReq) ( *public.GetByDateResp, error) {
+	jreq, err:= json.Marshal(req)
+	if err != nil {
+		return &public.GetByDateResp{}, err
+	}
+	res, body, err := apiCall("GET",h.BaseURL+"/events/"+string(req.Range)+"/"+req.Date.String(), jreq)
+	if err != nil {
+		return &public.GetByDateResp{}, err
+	}
+	if res.StatusCode!=201 {
+		return &public.GetByDateResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	}
+	var getByDateResp public.GetByDateResp
+	err = json.Unmarshal(body,&getByDateResp)
+	if err != nil {
+		return &public.GetByDateResp{}, err
+	}
+	return &getByDateResp, nil
+}
+
+func apiCall(method string, url string, payload []byte) (*http.Response, []byte, error) {
+	client := &http.Client{Transport: &http.Transport{ DialContext: (&net.Dialer{ Timeout: 15*time.Second}).DialContext }}
+	req, err := http.NewRequest(method, url, bytes.NewBuffer(payload))
+	if err != nil {
+		return nil, nil, err
+	}
+	req.Header.Add("Content-Type", "application/json")
+	req.Close = true
+	res, err := client.Do(req)
+	if err != nil {
+		return nil, nil, err
+	}
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		return nil, nil, err
+	}
+	if err = res.Body.Close(); err != nil {
+		return nil, nil, err
+	}
+	return res, body, nil
+}
diff --git a/hw12_13_14_15_calendar/test/client/iface.go b/hw12_13_14_15_calendar/test/client/iface.go
new file mode 100644
index 0000000..90efcd2
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/client/iface.go
@@ -0,0 +1,13 @@
+package client
+
+import "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+
+type Interface interface {
+	GetName() string
+	Create(req *public.CreateReq) (*public.CreateRsp, error)
+	Update(req *public.UpdateReq) error
+	Delete(req *public.DeleteReq) error
+	GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error)
+	List() (*public.ListResp, error)
+	GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, error)
+}
diff --git a/hw12_13_14_15_calendar/test/main.go b/hw12_13_14_15_calendar/test/main.go
index 6b52288..7dd8061 100644
--- a/hw12_13_14_15_calendar/test/main.go
+++ b/hw12_13_14_15_calendar/test/main.go
@@ -1,244 +1,10 @@
 package main
 
 import (
-	"context"
-	"fmt"
-	"github.com/golang/protobuf/ptypes"
-	"github.com/golang/protobuf/ptypes/duration"
-	"github.com/golang/protobuf/ptypes/empty"
-	"github.com/golang/protobuf/ptypes/timestamp"
-	"github.com/stretchr/testify/require"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"log"
-	"sync"
-	"testing"
-	"time"
 )
 
-var testEvent01 = public.CreateReq{
-	Title:      "Test event 01",
-	Date:       time2pbtimestamp(time.Now().Add(30 * time.Second)),
-	Latency:    dur2pbduration(24 * time.Hour),
-	Note:       "Note of test event 01",
-	NotifyTime: dur2pbduration(5 * time.Minute),
-	UserID:     1111,
-}
-
-var testEvent02 = public.CreateReq{
-	Title:      "Test event 02",
-	Date:       time2pbtimestamp(time.Now().Add(60 * time.Second)),
-	Latency:    dur2pbduration(2 * 24 * time.Hour),
-	Note:       "Note of test event 02",
-	NotifyTime: dur2pbduration(5 * time.Minute),
-	UserID:     2222,
-}
 
 func main() {
-	if err := TestPublicAPIEndpoint(); err != nil {
-		log.Fatalf("TestPublicAPIEndpoint FAIL: %w", err)
-	}
-
-	if err := TestPublicGRPCEndpoint(); err != nil {
-		log.Fatalf("TestPublicGRPCEndpoint FAIL: %w", err)
-	}
-
-}
-
-func TestPublicGRPCEndpoint() error {
-	wg := sync.WaitGroup{}
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
-	if err != nil {
-		return err
-	}
-
-	wg.Add(5)
-	// Реализовать тесты логики приложения:
-	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
-	})
-	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
-	})
-	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.Error(t, err)
-		require.Nil(t, resp2)
-	})
-	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		resp2, err := publicAPI.Create(ctx, &testEvent02)
-		require.NoError(t, err)
-		require.NotEqual(t, resp1.ID, resp2.ID)
-
-		list, err := publicAPI.List(ctx, &empty.Empty{})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1, e2 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-			if v.ID == resp2.ID {
-				e2 = true
-			}
-		}
-		require.True(t, e1)
-		require.True(t, e2)
-	})
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-		}
-		require.True(t, e1)
-	})
-	wg.Wait()
-}
-
-func TestPublicAPIEndpoint() error {
-	wg := sync.WaitGroup{}
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
-	require.NoError(t, err)
-
-	wg.Add(5)
-	// Реализовать тесты логики приложения:
-	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
-	})
-
-	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
-	})
-
-	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.Error(t, err)
-		require.Nil(t, resp2)
-	})
-
-	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		resp2, err := publicAPI.Create(ctx, &testEvent02)
-		require.NoError(t, err)
-		require.NotEqual(t, resp1.ID, resp2.ID)
-
-		list, err := publicAPI.List(ctx, &empty.Empty{})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1, e2 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-			if v.ID == resp2.ID {
-				e2 = true
-			}
-		}
-		require.True(t, e1)
-		require.True(t, e2)
-	})
-
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-		}
-		require.True(t, e1)
-	})
-
-	wg.Wait()
-}
-
-func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
-	r, err := ptypes.TimestampProto(t)
-	if err != nil {
-		log.Fatalf("cant convert Time to Timestamp: %s", err.Error())
-	}
-	return r
-}
-
-func dur2pbduration(t time.Duration) *duration.Duration {
-	return ptypes.DurationProto(t)
+	log.Fatalln("Nothing to do")
 }
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
new file mode 100644
index 0000000..b38f224
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -0,0 +1,120 @@
+package main
+
+import (
+	"context"
+	"github.com/stretchr/testify/require"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
+	"sync"
+	"testing"
+)
+
+func TestPublicAPIEndpoints(t *testing.T) {
+	cli := []client.Interface{
+		client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port:"50051", Name: "GRPC API"},
+		client.HTTPAPI{BaseURL: "http://localhost:50052", Name: "HTTP REST API"},
+	}
+	wg := sync.WaitGroup{}
+	wg.Add(len(cli)*5)
+
+	for _,c := range cli {
+		t.Run("test "+c.GetName()+" for Create and GetById", func(t *testing.T) {
+			defer wg.Done()
+
+			resp1, err := c.Create(&misc.TestEvent01)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+
+			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			require.NoError(t, err)
+			require.Equal(t,1, len(resp2.Events))
+			require.Equal(t, misc.TestEvent01.Title, resp2.Events[0].Title)
+			require.Equal(t, misc.TestEvent01.UserID, resp2.Events[0].UserID)
+			require.Equal(t, misc.TestEvent01.Note, resp2.Events[0].Note)
+		})
+
+		t.Run("test "+c.GetName()+" for Create, Update and GetById", func(t *testing.T) {
+			defer wg.Done()
+
+			resp1, err := c.Create(&misc.TestEvent01)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+
+			err = c.Update(&public.UpdateReq{ID:resp1.ID, Event: &public.Event{ ID: resp1.ID, Title: misc.TestEvent02.Title, Date: misc.TestEvent02.Date, Latency: misc.TestEvent02.Latency, Note: misc.TestEvent02.Note, UserID: misc.TestEvent02.UserID, NotifyTime: misc.TestEvent02.NotifyTime }})
+			require.NoError(t, err)
+
+			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			require.NoError(t, err)
+			require.Equal(t,1, len(resp2.Events))
+			require.Equal(t, misc.TestEvent02.Title, resp2.Events[0].Title)
+			require.Equal(t, misc.TestEvent02.UserID, resp2.Events[0].UserID)
+			require.Equal(t, misc.TestEvent02.Note, resp2.Events[0].Note)
+		})
+
+		t.Run("test "+c.GetName()+" for Create, Delete and GetById", func(t *testing.T) {
+			defer wg.Done()
+
+			resp1, err := c.Create(&misc.TestEvent01)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+
+			err = c.Delete(&public.DeleteReq{ ID: resp1.ID })
+			require.NoError(t, err)
+
+			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			require.Error(t, err)
+			require.Nil(t, resp2)
+		})
+
+		t.Run("test "+c.GetName()+" for Create and List", func(t *testing.T) {
+			defer wg.Done()
+
+			resp1, err := c.Create(&misc.TestEvent01)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+
+			resp2, err := c.Create(&misc.TestEvent02)
+			require.NoError(t, err)
+			require.Greater(t, resp2.ID, int64(0))
+
+			resp3, err := c.List()
+			require.NoError(t, err)
+			require.GreaterOrEqual(t, len(resp3.Events), 2)
+			var e1, e2 bool
+			for _, v := range resp3.Events {
+				if v.ID == resp1.ID {
+					e1 = true
+				}
+				if v.ID == resp2.ID {
+					e2 = true
+				}
+			}
+			require.True(t, e1)
+			require.True(t, e2)
+		})
+
+		t.Run("test "+c.GetName()+" for Create and GetByDate", func(t *testing.T) {
+			defer wg.Done()
+
+			resp1, err := c.Create(&misc.TestEvent01)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+
+			resp2, err := c.Create(&misc.TestEvent02)
+			require.NoError(t, err)
+			require.Greater(t, resp2.ID, int64(0))
+
+			resp3,err := c.GetByDate(&public.GetByDateReq{Date: misc.TestEvent01.Date, Range: public.QueryRange_DAY})
+			require.NoError(t, err)
+			require.GreaterOrEqual(t, len(resp3.Events), 1)
+			var e1 bool
+			for _, v := range resp3.Events {
+				if v.ID == resp1.ID {
+					e1 = true
+				}
+			}
+			require.True(t, e1)
+		})
+	}
+}
diff --git a/hw12_13_14_15_calendar/test/misc/misc.go b/hw12_13_14_15_calendar/test/misc/misc.go
new file mode 100644
index 0000000..61a8ccc
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/misc/misc.go
@@ -0,0 +1,40 @@
+package misc
+
+import (
+	"github.com/golang/protobuf/ptypes"
+	"github.com/golang/protobuf/ptypes/duration"
+	"github.com/golang/protobuf/ptypes/timestamp"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"log"
+	"time"
+)
+
+var TestEvent01 = public.CreateReq{
+	Title:      "Test event 01",
+	Date:       Time2pbtimestamp(time.Now().Add(30 * time.Second)),
+	Latency:    Dur2pbduration(24 * time.Hour),
+	Note:       "Note of test event 01",
+	NotifyTime: Dur2pbduration(5 * time.Minute),
+	UserID:     1111,
+}
+
+var TestEvent02 = public.CreateReq{
+	Title:      "Test event 02",
+	Date:       Time2pbtimestamp(time.Now().Add(60 * time.Second)),
+	Latency:    Dur2pbduration(2 * 24 * time.Hour),
+	Note:       "Note of test event 02",
+	NotifyTime: Dur2pbduration(5 * time.Minute),
+	UserID:     2222,
+}
+
+func Time2pbtimestamp(t time.Time) *timestamp.Timestamp {
+	r, err := ptypes.TimestampProto(t)
+	if err != nil {
+		log.Fatalf("cant convert Time to Timestamp: %s", err.Error())
+	}
+	return r
+}
+
+func Dur2pbduration(t time.Duration) *duration.Duration {
+	return ptypes.DurationProto(t)
+}

From ddb1205fd32609ceab11d8ca84275bd5f42801ec Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Fri, 19 Mar 2021 11:33:13 -0400
Subject: [PATCH 11/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile               |   2 +-
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  30 +-
 hw12_13_14_15_calendar/go.mod                 |   1 +
 hw12_13_14_15_calendar/go.sum                 |  27 +-
 .../pkg/api/public/public.pb.go               |   4 +-
 .../pkg/api/public/public.pb.gw.go            | 375 ------------------
 .../pkg/api/rest/converters.go                |  83 ++++
 .../pkg/api/rest/handlers.go                  | 146 +++++++
 hw12_13_14_15_calendar/test/client/httpapi.go |   8 +-
 hw12_13_14_15_calendar/test/main_test.go      |  95 +++--
 10 files changed, 321 insertions(+), 450 deletions(-)
 delete mode 100644 hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
 create mode 100644 hw12_13_14_15_calendar/pkg/api/rest/converters.go
 create mode 100644 hw12_13_14_15_calendar/pkg/api/rest/handlers.go

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index e92baca..1e2b9f6 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -13,7 +13,7 @@ install-lint-deps:
 	(which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.30.0
 
 generate:
-	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public --grpc-gateway_out=logtostderr=true:./pkg/api/public ./api/public/public.proto
+	protoc  -I ./api/public  --go_out=plugins=grpc:./pkg/api/public ./api/public/public.proto
 	protoc  -I ./api/private  --go_out=plugins=grpc:./internal/api/private ./api/private/private.proto
 
 up: sup-up calendar-up sender-up sheduler-up
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index 96ff0f7..8fff6fd 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -3,9 +3,8 @@ package main
 import (
 	"context"
 	"flag"
-	"github.com/grpc-ecosystem/grpc-gateway/runtime"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
-	"google.golang.org/grpc"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/rest"
 	oslog "log"
 	"net"
 	"net/http"
@@ -13,11 +12,11 @@ import (
 	"os/signal"
 	"syscall"
 
-	_ "github.com/go-sql-driver/mysql"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/gorilla/mux"
 	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
 )
 
@@ -59,25 +58,20 @@ func main() {
 		}
 	}()
 
-	grpcDiler, err := grpc.Dial(net.JoinHostPort(conf.HTTP.Address, conf.HTTP.Port), grpc.WithInsecure())
-	if err != nil {
-		log.Errorf("can't dial grpc server: " + err.Error())
-		os.Exit(1)
-	}
-	defer grpcDiler.Close()
 
-	grpcGwRouter := runtime.NewServeMux()
-	ctx, cancel := context.WithCancel(context.Background())
-	if err = public.RegisterGrpcHandler(ctx, grpcGwRouter, grpcDiler); err != nil {
-		log.Errorf("can't register handlers for grpc-gateway: " + err.Error())
-		os.Exit(1)
-	}
+	_, cancel := context.WithCancel(context.Background())
+	m := mux.NewRouter()
+
+	m.HandleFunc("/events", rest.FromRESTCreate(calendar)).Methods("POST")
+	m.HandleFunc("/events/{ID}", rest.FromRESTUpdate(calendar)).Methods("PUT")
+	m.HandleFunc("/events/{ID}", rest.FromRESTDelete(calendar)).Methods("DELETE")
+	m.HandleFunc("/events", rest.FromRESTList(calendar)).Methods("GET")
+	m.HandleFunc("/events/{ID}", rest.FromRESTGetByID(calendar)).Methods("GET")
+	m.HandleFunc("/events/{Range}/{Date}", rest.FromRESTGetByDate(calendar)).Methods("GET")
 
-	mux := http.NewServeMux()
-	mux.Handle("/", grpcGwRouter)
 	go func() {
 		log.Infof("webAPI server starting")
-		if err := http.ListenAndServe(net.JoinHostPort(conf.HTTP.Address, conf.HTTP.Port), mux); err != nil {
+		if err := http.ListenAndServe(net.JoinHostPort(conf.HTTP.Address, conf.HTTP.Port), m); err != nil {
 			log.Errorf("failed to start webAPI server: " + err.Error())
 			os.Exit(1)
 		}
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index c4abac5..249adf8 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -7,6 +7,7 @@ require (
 	github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/golang/protobuf v1.4.2
+	github.com/gorilla/mux v1.8.0
 	github.com/grpc-ecosystem/grpc-gateway v1.15.0
 	github.com/kr/text v0.2.0 // indirect
 	github.com/lib/pq v1.10.0
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index a97abb3..98f3379 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -38,19 +38,16 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
 github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
+github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
 github.com/grpc-ecosystem/grpc-gateway v1.15.0 h1:ntPNC9TD/6l2XDenJZe6T5lSMg95thpV9sGAqHX4WU8=
 github.com/grpc-ecosystem/grpc-gateway v1.15.0/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8=
-github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
@@ -58,7 +55,6 @@ github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
 github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
-github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -66,20 +62,16 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
-github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
-github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
 github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
 github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
 github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -97,10 +89,8 @@ go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
 go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 h1:iMGN4xG0cnqj3t+zOM8wUB0BiPKHEwSxEZCvzcbZuvk=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -108,7 +98,6 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
-golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e h1:JgcxKXxCjrA2tyDP/aNU9K0Ck5Czfk6C7e2tMw7+bSI=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
 golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -118,7 +107,6 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73r
 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
@@ -128,20 +116,16 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4Iltr
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -152,12 +136,10 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
 golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 h1:yaM5S0KcY0lIoZo7Fl+oi91b/DdlU2zuWpfHrpWbCS0=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
-golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
@@ -167,7 +149,6 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
 google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
-google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70 h1:wboULUXGF3c5qdUnKp+6gLAccE6PRpa/czkYvQ4UXv8=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
@@ -183,19 +164,15 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
 google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
 google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
 google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
-google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
 google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
diff --git a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
index eb1cc62..e9ecd62 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
@@ -733,9 +733,7 @@ func _Grpc_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa
 		return nil, err
 	}
 	if interceptor == nil {
-		sss := srv.(GrpcServer)
-		rrrrr, err := sss.Create(ctx, in)
-		return rrrrr, err
+		return srv.(GrpcServer).Create(ctx, in)
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
diff --git a/hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
deleted file mode 100644
index 281320c..0000000
--- a/hw12_13_14_15_calendar/pkg/api/public/public.pb.gw.go
+++ /dev/null
@@ -1,375 +0,0 @@
-// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
-// source: public.proto
-
-/*
-Package public is a reverse proxy.
-
-It translates gRPC into RESTful JSON APIs.
-*/
-package public
-
-import (
-	"io"
-	"net/http"
-
-	"github.com/golang/protobuf/proto"
-	"github.com/golang/protobuf/ptypes/empty"
-	"github.com/grpc-ecosystem/grpc-gateway/runtime"
-	"github.com/grpc-ecosystem/grpc-gateway/utilities"
-	"golang.org/x/net/context"
-	"google.golang.org/grpc"
-	"google.golang.org/grpc/codes"
-	"google.golang.org/grpc/grpclog"
-	"google.golang.org/grpc/status"
-)
-
-var _ codes.Code
-var _ io.Reader
-var _ status.Status
-var _ = runtime.String
-var _ = utilities.NewDoubleArray
-
-func request_Grpc_Create_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq CreateReq
-	var metadata runtime.ServerMetadata
-
-	newReader, berr := utilities.IOReaderFactory(req.Body)
-	if berr != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
-	}
-	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
-	}
-
-	msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-func request_Grpc_Update_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq UpdateReq
-	var metadata runtime.ServerMetadata
-
-	newReader, berr := utilities.IOReaderFactory(req.Body)
-	if berr != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
-	}
-	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
-	}
-
-	var (
-		val string
-		ok  bool
-		err error
-		_   = err
-	)
-
-	val, ok = pathParams["ID"]
-	if !ok {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
-	}
-
-	protoReq.ID, err = runtime.Int64(val)
-
-	if err != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
-	}
-
-	msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-func request_Grpc_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq DeleteReq
-	var metadata runtime.ServerMetadata
-
-	var (
-		val string
-		ok  bool
-		err error
-		_   = err
-	)
-
-	val, ok = pathParams["ID"]
-	if !ok {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
-	}
-
-	protoReq.ID, err = runtime.Int64(val)
-
-	if err != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
-	}
-
-	msg, err := client.Delete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-func request_Grpc_List_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq empty.Empty
-	var metadata runtime.ServerMetadata
-
-	msg, err := client.List(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-func request_Grpc_GetByID_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq GetByIDReq
-	var metadata runtime.ServerMetadata
-
-	var (
-		val string
-		ok  bool
-		err error
-		_   = err
-	)
-
-	val, ok = pathParams["ID"]
-	if !ok {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
-	}
-
-	protoReq.ID, err = runtime.Int64(val)
-
-	if err != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
-	}
-
-	msg, err := client.GetByID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-func request_Grpc_GetByDate_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
-	var protoReq GetByDateReq
-	var metadata runtime.ServerMetadata
-
-	var (
-		val string
-		e   int32
-		ok  bool
-		err error
-		_   = err
-	)
-
-	val, ok = pathParams["Range"]
-	if !ok {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "Range")
-	}
-
-	e, err = runtime.Enum(val, QueryRange_value)
-
-	if err != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "Range", err)
-	}
-
-	protoReq.Range = QueryRange(e)
-
-	val, ok = pathParams["Date"]
-	if !ok {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "Date")
-	}
-
-	protoReq.Date, err = runtime.Timestamp(val)
-
-	if err != nil {
-		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "Date", err)
-	}
-
-	msg, err := client.GetByDate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
-	return msg, metadata, err
-
-}
-
-// RegisterGrpcHandlerFromEndpoint is same as RegisterGrpcHandler but
-// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
-func RegisterGrpcHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
-	conn, err := grpc.Dial(endpoint, opts...)
-	if err != nil {
-		return err
-	}
-	defer func() {
-		if err != nil {
-			if cerr := conn.Close(); cerr != nil {
-				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
-			}
-			return
-		}
-		go func() {
-			<-ctx.Done()
-			if cerr := conn.Close(); cerr != nil {
-				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
-			}
-		}()
-	}()
-
-	return RegisterGrpcHandler(ctx, mux, conn)
-}
-
-// RegisterGrpcHandler registers the http handlers for service Grpc to "mux".
-// The handlers forward requests to the grpc endpoint over "conn".
-func RegisterGrpcHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
-	return RegisterGrpcHandlerClient(ctx, mux, NewGrpcClient(conn))
-}
-
-// RegisterGrpcHandlerClient registers the http handlers for service Grpc
-// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "GrpcClient".
-// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "GrpcClient"
-// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
-// "GrpcClient" to call the correct interceptors.
-func RegisterGrpcHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GrpcClient) error {
-
-	mux.Handle("POST", pattern_Grpc_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_Create_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_Create_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	mux.Handle("PUT", pattern_Grpc_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_Update_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_Update_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	mux.Handle("DELETE", pattern_Grpc_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_Delete_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_Delete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	mux.Handle("GET", pattern_Grpc_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_List_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_List_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	mux.Handle("GET", pattern_Grpc_GetByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_GetByID_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_GetByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	mux.Handle("POST", pattern_Grpc_GetByDate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
-		ctx, cancel := context.WithCancel(req.Context())
-		defer cancel()
-		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
-		rctx, err := runtime.AnnotateContext(ctx, mux, req)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-		resp, md, err := request_Grpc_GetByDate_0(rctx, inboundMarshaler, client, req, pathParams)
-		ctx = runtime.NewServerMetadataContext(ctx, md)
-		if err != nil {
-			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
-			return
-		}
-
-		forward_Grpc_GetByDate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
-	})
-
-	return nil
-}
-
-var (
-	pattern_Grpc_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"events"}, ""))
-
-	pattern_Grpc_Update_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
-
-	pattern_Grpc_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
-
-	pattern_Grpc_List_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"events"}, ""))
-
-	pattern_Grpc_GetByID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
-
-	pattern_Grpc_GetByDate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 1, 0, 4, 1, 5, 2}, []string{"events", "Range", "Date"}, ""))
-)
-
-var (
-	forward_Grpc_Create_0 = runtime.ForwardResponseMessage
-
-	forward_Grpc_Update_0 = runtime.ForwardResponseMessage
-
-	forward_Grpc_Delete_0 = runtime.ForwardResponseMessage
-
-	forward_Grpc_List_0 = runtime.ForwardResponseMessage
-
-	forward_Grpc_GetByID_0 = runtime.ForwardResponseMessage
-
-	forward_Grpc_GetByDate_0 = runtime.ForwardResponseMessage
-)
diff --git a/hw12_13_14_15_calendar/pkg/api/rest/converters.go b/hw12_13_14_15_calendar/pkg/api/rest/converters.go
new file mode 100644
index 0000000..9a2bbd0
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/api/rest/converters.go
@@ -0,0 +1,83 @@
+package rest
+
+import (
+	"github.com/golang/protobuf/ptypes"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+)
+
+func createReq2Event(e public.CreateReq) (res event.Event, err error) {
+	res = event.Event{
+		Title:      e.Title,
+		Note:       e.Note,
+		UserID:     e.UserID,
+	}
+	res.Date, err = ptypes.Timestamp(e.Date)
+	if err != nil {
+		return event.Event{}, err
+	}
+	res.Latency, err = ptypes.Duration(e.Latency)
+	if err != nil {
+		return event.Event{}, err
+	}
+	res.NotifyTime, err = ptypes.Duration(e.NotifyTime)
+	if err != nil {
+		return event.Event{}, err
+	}
+	return res, nil
+}
+
+func pubEvent2Event(e public.Event) (res event.Event, err error) {
+	res = event.Event{
+		Title:      e.Title,
+		Note:       e.Note,
+		UserID:     e.UserID,
+	}
+	res.Date, err = ptypes.Timestamp(e.Date)
+	if err != nil {
+		return event.Event{}, err
+	}
+	res.Latency, err = ptypes.Duration(e.Latency)
+	if err != nil {
+		return event.Event{}, err
+	}
+	res.NotifyTime, err = ptypes.Duration(e.NotifyTime)
+	if err != nil {
+		return event.Event{}, err
+	}
+	return res, nil
+}
+
+func event2pubEvent(e event.Event) (res public.Event, err error) {
+	res = public.Event{
+		Title:      e.Title,
+		Latency:	ptypes.DurationProto(e.Latency),
+		Note:       e.Note,
+		UserID:     e.UserID,
+		NotifyTime:	ptypes.DurationProto(e.NotifyTime),
+	}
+	res.Date, err = ptypes.TimestampProto(e.Date)
+	if err != nil {
+		return public.Event{}, err
+	}
+	return res, nil
+}
+
+func events2pubEvents(e map[event.ID]event.Event) (res []public.Event, err error) {
+	for id,ev := range e {
+		r := public.Event{
+			ID:                   int64(id),
+			Title:                ev.Title,
+			Latency:              ptypes.DurationProto(ev.Latency),
+			Note:                 ev.Note,
+			UserID:               ev.UserID,
+			NotifyTime:           ptypes.DurationProto(ev.NotifyTime),
+		}
+		r.Date, err = ptypes.TimestampProto(ev.Date)
+		if err != nil {
+			return []public.Event{}, err
+		}
+		res = append(res,r)
+	}
+	return res, nil
+}
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/pkg/api/rest/handlers.go b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
new file mode 100644
index 0000000..972912c
--- /dev/null
+++ b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
@@ -0,0 +1,146 @@
+package rest
+
+import (
+	"encoding/json"
+	"github.com/gorilla/mux"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"strconv"
+	"time"
+)
+
+func FromRESTCreate(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		bodyReq := public.CreateReq{}
+		bodyIn, err := ioutil.ReadAll(req.Body)
+		defer req.Body.Close()
+		if err != nil {
+			err503("can't body of the HTTP API request", err, calendar.Logger, r)
+		}
+		err = json.Unmarshal(bodyIn, &bodyReq)
+		if err != nil {
+			err503("can't unmarshal data from HTTP API request", err, calendar.Logger, r)
+		}
+		evt, err := createReq2Event(bodyReq)
+		if err != nil {
+			err503("can't convert types", err, calendar.Logger, r)
+		}
+		id, err := calendar.Storage.Create(evt)
+		if err != nil {
+			err503("can't create event through HTTP API", err, calendar.Logger, r)
+		}
+		bodyOut,err := json.Marshal(&public.CreateRsp{ID: int64(id)})
+		r.WriteHeader(201)
+		r.Write(bodyOut)
+	}
+}
+
+func FromRESTUpdate(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		paramID, err := strconv.Atoi(mux.Vars(req)["ID"])
+		if err != nil {
+			err503("can't get request parameter", err, calendar.Logger, r)
+		}
+		bodyReq := public.Event{}
+		bodyIn, err := ioutil.ReadAll(req.Body)
+		defer req.Body.Close()
+		if err != nil {
+			err503("can't body of the HTTP API request", err, calendar.Logger, r)
+		}
+		err = json.Unmarshal(bodyIn, &bodyReq)
+		if err != nil {
+			err503("can't unmarshal data from HTTP API request", err, calendar.Logger, r)
+		}
+		evt, err := pubEvent2Event(bodyReq)
+		if err != nil {
+			err503("can't convert types", err, calendar.Logger, r)
+		}
+		err = calendar.Storage.Update(event.ID(paramID), evt)
+		if err != nil {
+			err503("can't update event through HTTP API", err, calendar.Logger, r)
+		}
+		r.WriteHeader(200)
+	}
+}
+
+func FromRESTDelete(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		paramID, err := strconv.Atoi(mux.Vars(req)["ID"])
+		if err != nil {
+			err503("can't get request parameter", err, calendar.Logger, r)
+		}
+		err = calendar.Storage.Delete(event.ID(paramID))
+		if err != nil {
+			err503("can't create event from HTTP API", err, calendar.Logger, r)
+		}
+		r.WriteHeader(200)
+	}
+}
+
+func FromRESTList(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		evs, err := calendar.Storage.List()
+		if err != nil {
+			err503("can't list events through HTTP API", err, calendar.Logger, r)
+		}
+		events, err := events2pubEvents(evs)
+		if err != nil {
+			err503("can't convert types", err, calendar.Logger, r)
+		}
+		bodyOut,err := json.Marshal(&events)
+		r.WriteHeader(200)
+		r.Write(bodyOut)
+	}
+}
+
+func FromRESTGetByID(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		paramID, err := strconv.Atoi(mux.Vars(req)["ID"])
+		if err != nil {
+			err503("can't get request parameter", err, calendar.Logger, r)
+		}
+		ev, _ := calendar.Storage.GetByID(event.ID(paramID))
+		event, err := event2pubEvent(ev)
+		if err != nil {
+			err503("can't convert types", err, calendar.Logger, r)
+		}
+		bodyOut,err := json.Marshal(&event)
+		r.WriteHeader(200)
+		r.Write(bodyOut)
+
+
+		log.Println(paramID)
+		r.WriteHeader(555)
+	}
+}
+
+func FromRESTGetByDate(calendar *calendar.App) http.HandlerFunc {
+	return func(r http.ResponseWriter, req *http.Request) {
+		paramRange := mux.Vars(req)["Range"]
+		paramDate, err := time.Parse("2006-01-02 15:04:05", mux.Vars(req)["Date"])
+		if err != nil {
+			err503("can't parse date from request parameter", err, calendar.Logger, r)
+		}
+		evs, err := calendar.Storage.GetByDate(paramDate, paramRange)
+		if err != nil {
+			err503("can't list events through HTTP API", err, calendar.Logger, r)
+		}
+		events, err := events2pubEvents(evs)
+		if err != nil {
+			err503("can't convert types", err, calendar.Logger, r)
+		}
+		bodyOut,err := json.Marshal(&events)
+		r.WriteHeader(200)
+		r.Write(bodyOut)
+	}
+}
+
+func err503(s string, err error, l logger.Interface, r http.ResponseWriter) {
+	l.Errorf(s,": ", err.Error())
+	r.WriteHeader(503)
+}
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/test/client/httpapi.go b/hw12_13_14_15_calendar/test/client/httpapi.go
index d9f3a04..7b1a92a 100644
--- a/hw12_13_14_15_calendar/test/client/httpapi.go
+++ b/hw12_13_14_15_calendar/test/client/httpapi.go
@@ -50,7 +50,7 @@ func (h HTTPAPI) Update(req *public.UpdateReq) error {
 	if err != nil {
 		return err
 	}
-	if res.StatusCode!=201 {
+	if res.StatusCode!=200 {
 		return fmt.Errorf("unexpected status code %d",res.StatusCode)
 	}
 	return nil
@@ -65,7 +65,7 @@ func (h HTTPAPI) Delete(req *public.DeleteReq) error {
 	if err != nil {
 		return err
 	}
-	if res.StatusCode!=201 {
+	if res.StatusCode!=200 {
 		return fmt.Errorf("unexpected status code %d",res.StatusCode)
 	}
 	return nil
@@ -80,7 +80,7 @@ func (h HTTPAPI) GetByID(req *public.GetByIDReq) ( *public.GetByIDResp, error) {
 	if err != nil {
 		return &public.GetByIDResp{}, err
 	}
-	if res.StatusCode!=201 {
+	if res.StatusCode!=200 {
 		return &public.GetByIDResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
 	}
 	var getByIDResp public.GetByIDResp
@@ -116,7 +116,7 @@ func (h HTTPAPI) GetByDate(req *public.GetByDateReq) ( *public.GetByDateResp, er
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
-	if res.StatusCode!=201 {
+	if res.StatusCode!=200 {
 		return &public.GetByDateResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
 	}
 	var getByDateResp public.GetByDateResp
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index b38f224..74a72c8 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -6,8 +6,10 @@ import (
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
+	"log"
 	"sync"
 	"testing"
+	"time"
 )
 
 func TestPublicAPIEndpoints(t *testing.T) {
@@ -19,12 +21,17 @@ func TestPublicAPIEndpoints(t *testing.T) {
 	wg.Add(len(cli)*5)
 
 	for _,c := range cli {
-		t.Run("test "+c.GetName()+" for Create and GetById", func(t *testing.T) {
-			defer wg.Done()
+		t.Run("test "+c.GetName()+" for Create, GetById and Delete", func(t *testing.T) {
+			var ids []int64
+			defer func() {
+				wg.Done()
+				clean(c,&ids)
+			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
+			ids=append(ids,resp1.ID)
 
 			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
 			require.NoError(t, err)
@@ -34,12 +41,17 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.Equal(t, misc.TestEvent01.Note, resp2.Events[0].Note)
 		})
 
-		t.Run("test "+c.GetName()+" for Create, Update and GetById", func(t *testing.T) {
-			defer wg.Done()
+		t.Run("test "+c.GetName()+" for Create, Update, GetById and Delete", func(t *testing.T) {
+			var ids []int64
+			defer func() {
+				wg.Done()
+				clean(c,&ids)
+			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
+			ids=append(ids,resp1.ID)
 
 			err = c.Update(&public.UpdateReq{ID:resp1.ID, Event: &public.Event{ ID: resp1.ID, Title: misc.TestEvent02.Title, Date: misc.TestEvent02.Date, Latency: misc.TestEvent02.Latency, Note: misc.TestEvent02.Note, UserID: misc.TestEvent02.UserID, NotifyTime: misc.TestEvent02.NotifyTime }})
 			require.NoError(t, err)
@@ -67,16 +79,23 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.Nil(t, resp2)
 		})
 
-		t.Run("test "+c.GetName()+" for Create and List", func(t *testing.T) {
-			defer wg.Done()
+		t.Run("test "+c.GetName()+" for Create, List and Delete", func(t *testing.T) {
+			var ids []int64
+			defer func() {
+				wg.Done()
+				clean(c,&ids)
+			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
+			ids=append(ids,resp1.ID)
+
 
 			resp2, err := c.Create(&misc.TestEvent02)
 			require.NoError(t, err)
 			require.Greater(t, resp2.ID, int64(0))
+			ids=append(ids,resp2.ID)
 
 			resp3, err := c.List()
 			require.NoError(t, err)
@@ -92,29 +111,57 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			}
 			require.True(t, e1)
 			require.True(t, e2)
+
+			err = c.Delete(&public.DeleteReq{ ID: resp1.ID })
+			require.NoError(t, err)
+
+			err = c.Delete(&public.DeleteReq{ ID: resp2.ID })
+			require.NoError(t, err)
 		})
 
-		t.Run("test "+c.GetName()+" for Create and GetByDate", func(t *testing.T) {
-			defer wg.Done()
+		t.Run("test "+c.GetName()+" for Create, GetByDate and Delete", func(t *testing.T) {
+			var ids []int64
+			defer func() {
+				wg.Done()
+				clean(c,&ids)
+			}()
 
-			resp1, err := c.Create(&misc.TestEvent01)
+			startDate, err := time.Parse("2006-01-02T15:04:00","3100-01-01T12:00:00")
 			require.NoError(t, err)
-			require.Greater(t, resp1.ID, int64(0))
-
-			resp2, err := c.Create(&misc.TestEvent02)
-			require.NoError(t, err)
-			require.Greater(t, resp2.ID, int64(0))
-
-			resp3,err := c.GetByDate(&public.GetByDateReq{Date: misc.TestEvent01.Date, Range: public.QueryRange_DAY})
-			require.NoError(t, err)
-			require.GreaterOrEqual(t, len(resp3.Events), 1)
-			var e1 bool
-			for _, v := range resp3.Events {
-				if v.ID == resp1.ID {
-					e1 = true
-				}
+			for i:=time.Hour;i<(60*24*time.Hour);i=i+48*time.Hour{
+				resp1, err := c.Create(&public.CreateReq{
+					Title:      "Test event 02",
+					Date:       misc.Time2pbtimestamp(startDate.Add(i)),
+					Latency:    misc.Dur2pbduration(2 * 24 * time.Hour),
+					Note:       "Note of test event 02",
+					NotifyTime: misc.Dur2pbduration(5 * time.Minute),
+					UserID:     2222,
+				})
+				require.NoError(t, err)
+				require.Greater(t, resp1.ID, int64(0))
+				ids=append(ids,resp1.ID)
 			}
-			require.True(t, e1)
+
+			resp2,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_DAY})
+			require.NoError(t, err)
+			require.Equal(t, 1, len(resp2.Events) )
+
+			resp3,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_WEEK})
+			require.NoError(t, err)
+			require.Equal(t, 4, len(resp3.Events) )
+
+			resp4,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_MONTH})
+			require.NoError(t, err)
+			require.Equal(t, 16, len(resp4.Events) )
 		})
 	}
 }
+
+func clean(c client.Interface, ids *[]int64) {
+	for _,m := range *ids {
+		err := c.Delete(&public.DeleteReq{ID:m})
+		if err != nil {
+			log.Println("error when try to clean DB: ", err.Error())
+		}
+	}
+}
\ No newline at end of file

From 9c60336ef55823b071fa46f5184663ba6b83fed6 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Fri, 19 Mar 2021 11:59:05 -0400
Subject: [PATCH 12/20] HW15 WIP

---
 .golangci.yml                                 |  3 +-
 hw12_13_14_15_calendar/cmd/calendar/main.go   |  3 +-
 .../internal/api/private/converters.go        |  2 +-
 .../internal/api/private/handlers.go          |  2 +-
 .../pkg/api/public/converters.go              |  2 +-
 .../pkg/api/public/handler.go                 |  3 +-
 .../pkg/api/rest/converters.go                | 52 ++++++++-------
 .../pkg/api/rest/handlers.go                  | 58 +++++++++++-----
 hw12_13_14_15_calendar/pkg/storage/sql/sql.go | 10 +--
 hw12_13_14_15_calendar/test/client/grpcapi.go | 34 +++++-----
 hw12_13_14_15_calendar/test/client/httpapi.go | 66 +++++++++----------
 hw12_13_14_15_calendar/test/main.go           |  1 -
 hw12_13_14_15_calendar/test/main_test.go      | 65 +++++++++---------
 13 files changed, 163 insertions(+), 138 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index aee85c0..ec5a5e2 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -16,4 +16,5 @@ linters:
     - gofumpt
     - gosec
     - nlreturn
-    - exhaustive
\ No newline at end of file
+    - exhaustive
+    - exhaustivestruct
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main.go b/hw12_13_14_15_calendar/cmd/calendar/main.go
index 8fff6fd..b4ec6c8 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main.go
@@ -12,11 +12,11 @@ import (
 	"os/signal"
 	"syscall"
 
+	"github.com/gorilla/mux"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
-	"github.com/gorilla/mux"
 	store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage"
 )
 
@@ -58,7 +58,6 @@ func main() {
 		}
 	}()
 
-
 	_, cancel := context.WithCancel(context.Background())
 	m := mux.NewRouter()
 
diff --git a/hw12_13_14_15_calendar/internal/api/private/converters.go b/hw12_13_14_15_calendar/internal/api/private/converters.go
index 63ffdc2..df1eb7c 100644
--- a/hw12_13_14_15_calendar/internal/api/private/converters.go
+++ b/hw12_13_14_15_calendar/internal/api/private/converters.go
@@ -20,5 +20,5 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		events[i] = &evt
 		i++
 	}
-	return events, err
+	return events, fmt.Errorf("can't convert types: %w", err)
 }
diff --git a/hw12_13_14_15_calendar/internal/api/private/handlers.go b/hw12_13_14_15_calendar/internal/api/private/handlers.go
index da8a4e2..61b02b8 100644
--- a/hw12_13_14_15_calendar/internal/api/private/handlers.go
+++ b/hw12_13_14_15_calendar/internal/api/private/handlers.go
@@ -32,7 +32,7 @@ func (s *Service) Start(conf Config) error {
 	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Address, conf.Port))
 	RegisterGrpcServer(s.S, s)
 	if err != nil {
-		return err
+		return fmt.Errorf("can't start private GRPC service: %w", err)
 	}
 	return s.S.Serve(listnGrpc)
 }
diff --git a/hw12_13_14_15_calendar/pkg/api/public/converters.go b/hw12_13_14_15_calendar/pkg/api/public/converters.go
index 4ff845c..0522b29 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/converters.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/converters.go
@@ -55,7 +55,7 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		events[i] = &evt
 		i++
 	}
-	return events, err
+	return events, fmt.Errorf("can't convert types: %w", err)
 }
 
 func (s Service) buildTimeAndRange(e *GetByDateReq) (start time.Time, qrange string, err error) {
diff --git a/hw12_13_14_15_calendar/pkg/api/public/handler.go b/hw12_13_14_15_calendar/pkg/api/public/handler.go
index ff718c2..e8b5f5c 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/handler.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/handler.go
@@ -2,6 +2,7 @@ package public
 
 import (
 	"context"
+	"fmt"
 	"net"
 
 	"github.com/golang/protobuf/ptypes/empty"
@@ -26,7 +27,7 @@ func (s *Service) Start(conf config.Calendar) error {
 	s.App.Logger.Infof("public GRPC server starting")
 	listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.GRPC.Address, conf.GRPC.Port))
 	if err != nil {
-		return err
+		return fmt.Errorf("can't start public GRPC service: %w", err)
 	}
 	RegisterGrpcServer(s.S, s)
 	return s.S.Serve(listnGrpc)
diff --git a/hw12_13_14_15_calendar/pkg/api/rest/converters.go b/hw12_13_14_15_calendar/pkg/api/rest/converters.go
index 9a2bbd0..db96917 100644
--- a/hw12_13_14_15_calendar/pkg/api/rest/converters.go
+++ b/hw12_13_14_15_calendar/pkg/api/rest/converters.go
@@ -1,6 +1,8 @@
 package rest
 
 import (
+	"fmt"
+
 	"github.com/golang/protobuf/ptypes"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
@@ -8,42 +10,42 @@ import (
 
 func createReq2Event(e public.CreateReq) (res event.Event, err error) {
 	res = event.Event{
-		Title:      e.Title,
-		Note:       e.Note,
-		UserID:     e.UserID,
+		Title:  e.Title,
+		Note:   e.Note,
+		UserID: e.UserID,
 	}
 	res.Date, err = ptypes.Timestamp(e.Date)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	res.Latency, err = ptypes.Duration(e.Latency)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	res.NotifyTime, err = ptypes.Duration(e.NotifyTime)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	return res, nil
 }
 
 func pubEvent2Event(e public.Event) (res event.Event, err error) {
 	res = event.Event{
-		Title:      e.Title,
-		Note:       e.Note,
-		UserID:     e.UserID,
+		Title:  e.Title,
+		Note:   e.Note,
+		UserID: e.UserID,
 	}
 	res.Date, err = ptypes.Timestamp(e.Date)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	res.Latency, err = ptypes.Duration(e.Latency)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	res.NotifyTime, err = ptypes.Duration(e.NotifyTime)
 	if err != nil {
-		return event.Event{}, err
+		return event.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	return res, nil
 }
@@ -51,33 +53,33 @@ func pubEvent2Event(e public.Event) (res event.Event, err error) {
 func event2pubEvent(e event.Event) (res public.Event, err error) {
 	res = public.Event{
 		Title:      e.Title,
-		Latency:	ptypes.DurationProto(e.Latency),
+		Latency:    ptypes.DurationProto(e.Latency),
 		Note:       e.Note,
 		UserID:     e.UserID,
-		NotifyTime:	ptypes.DurationProto(e.NotifyTime),
+		NotifyTime: ptypes.DurationProto(e.NotifyTime),
 	}
 	res.Date, err = ptypes.TimestampProto(e.Date)
 	if err != nil {
-		return public.Event{}, err
+		return public.Event{}, fmt.Errorf("can;t convert types: %w", err)
 	}
 	return res, nil
 }
 
 func events2pubEvents(e map[event.ID]event.Event) (res []public.Event, err error) {
-	for id,ev := range e {
+	for id, ev := range e {
 		r := public.Event{
-			ID:                   int64(id),
-			Title:                ev.Title,
-			Latency:              ptypes.DurationProto(ev.Latency),
-			Note:                 ev.Note,
-			UserID:               ev.UserID,
-			NotifyTime:           ptypes.DurationProto(ev.NotifyTime),
+			ID:         int64(id),
+			Title:      ev.Title,
+			Latency:    ptypes.DurationProto(ev.Latency),
+			Note:       ev.Note,
+			UserID:     ev.UserID,
+			NotifyTime: ptypes.DurationProto(ev.NotifyTime),
 		}
 		r.Date, err = ptypes.TimestampProto(ev.Date)
 		if err != nil {
-			return []public.Event{}, err
+			return []public.Event{}, fmt.Errorf("can;t convert types: %w", err)
 		}
-		res = append(res,r)
+		res = append(res, r)
 	}
 	return res, nil
-}
\ No newline at end of file
+}
diff --git a/hw12_13_14_15_calendar/pkg/api/rest/handlers.go b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
index 972912c..425079b 100644
--- a/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
+++ b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
@@ -2,16 +2,17 @@ package rest
 
 import (
 	"encoding/json"
-	"github.com/gorilla/mux"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 	"io/ioutil"
 	"log"
 	"net/http"
 	"strconv"
 	"time"
+
+	"github.com/gorilla/mux"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/calendar"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
 func FromRESTCreate(calendar *calendar.App) http.HandlerFunc {
@@ -34,9 +35,15 @@ func FromRESTCreate(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't create event through HTTP API", err, calendar.Logger, r)
 		}
-		bodyOut,err := json.Marshal(&public.CreateRsp{ID: int64(id)})
+		bodyOut, err := json.Marshal(&public.CreateRsp{ID: int64(id)})
+		if err != nil {
+			err503("can't marshal request", err, calendar.Logger, r)
+		}
 		r.WriteHeader(201)
-		r.Write(bodyOut)
+		_, err = r.Write(bodyOut)
+		if err != nil {
+			calendar.Logger.Errorf("can't send response")
+		}
 	}
 }
 
@@ -92,9 +99,15 @@ func FromRESTList(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't convert types", err, calendar.Logger, r)
 		}
-		bodyOut,err := json.Marshal(&events)
+		bodyOut, err := json.Marshal(&events)
+		if err != nil {
+			err503("can't marshal request", err, calendar.Logger, r)
+		}
 		r.WriteHeader(200)
-		r.Write(bodyOut)
+		_, err = r.Write(bodyOut)
+		if err != nil {
+			calendar.Logger.Errorf("can't send response")
+		}
 	}
 }
 
@@ -105,14 +118,19 @@ func FromRESTGetByID(calendar *calendar.App) http.HandlerFunc {
 			err503("can't get request parameter", err, calendar.Logger, r)
 		}
 		ev, _ := calendar.Storage.GetByID(event.ID(paramID))
-		event, err := event2pubEvent(ev)
+		evnt, err := event2pubEvent(ev)
 		if err != nil {
 			err503("can't convert types", err, calendar.Logger, r)
 		}
-		bodyOut,err := json.Marshal(&event)
+		bodyOut, err := json.Marshal(&evnt)
+		if err != nil {
+			err503("can't marshal request", err, calendar.Logger, r)
+		}
 		r.WriteHeader(200)
-		r.Write(bodyOut)
-
+		_, err = r.Write(bodyOut)
+		if err != nil {
+			calendar.Logger.Errorf("can't send response")
+		}
 
 		log.Println(paramID)
 		r.WriteHeader(555)
@@ -134,13 +152,19 @@ func FromRESTGetByDate(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't convert types", err, calendar.Logger, r)
 		}
-		bodyOut,err := json.Marshal(&events)
+		bodyOut, err := json.Marshal(&events)
+		if err != nil {
+			err503("can't marshal request", err, calendar.Logger, r)
+		}
 		r.WriteHeader(200)
-		r.Write(bodyOut)
+		_, err = r.Write(bodyOut)
+		if err != nil {
+			calendar.Logger.Errorf("can't send response")
+		}
 	}
 }
 
 func err503(s string, err error, l logger.Interface, r http.ResponseWriter) {
-	l.Errorf(s,": ", err.Error())
+	l.Errorf(s, ": ", err.Error())
 	r.WriteHeader(503)
-}
\ No newline at end of file
+}
diff --git a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index 7549f67..e65463b 100644
--- a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -6,8 +6,8 @@ import (
 	"log"
 	"time"
 
+	// Postgresql driver.
 	_ "github.com/lib/pq"
-
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/storage/event"
 )
 
@@ -28,7 +28,7 @@ type Storage struct {
 func New(config Config) *Storage {
 	db, err := sql.Open("postgres", "user="+config.User+" password="+config.Pass+" host="+config.Host+" port="+config.Port+" dbname="+config.Dbase+" sslmode=disable")
 	if err != nil {
-		log.Fatalf("can't connect to db: %s",err.Error())
+		log.Fatalf("can't connect to db: %s", err.Error())
 	}
 	return &Storage{db: db}
 }
@@ -38,7 +38,7 @@ func (s *Storage) Close() error {
 }
 
 func (s *Storage) Create(ev event.Event) (event.ID, error) {
-	lastInsertId := -1
+	lastInsertID := -1
 	if err := s.db.QueryRow(
 		`INSERT INTO events 
 		(title, date, latency, note, userID, notifyTime) VALUES 
@@ -49,10 +49,10 @@ func (s *Storage) Create(ev event.Event) (event.ID, error) {
 		ev.Note,
 		ev.UserID,
 		ev.NotifyTime,
-	).Scan(&lastInsertId); err != nil {
+	).Scan(&lastInsertID); err != nil {
 		return -1, fmt.Errorf("can't create event in SQL DB: %w", err)
 	}
-	return event.ID(lastInsertId), nil
+	return event.ID(lastInsertID), nil
 }
 
 func (s *Storage) Update(id event.ID, event event.Event) error {
diff --git a/hw12_13_14_15_calendar/test/client/grpcapi.go b/hw12_13_14_15_calendar/test/client/grpcapi.go
index e30befc..5ba6640 100644
--- a/hw12_13_14_15_calendar/test/client/grpcapi.go
+++ b/hw12_13_14_15_calendar/test/client/grpcapi.go
@@ -7,9 +7,9 @@ import (
 	"time"
 )
 
-type GRPCAPI struct{
+type GRPCAPI struct {
 	Name string
-	Ctx context.Context
+	Ctx  context.Context
 	Host string
 	Port string
 }
@@ -20,11 +20,11 @@ func (h GRPCAPI) GetName() string {
 
 func (h GRPCAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	resp, err := cliGRPC.Create(ctx, req)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	return resp, nil
@@ -32,11 +32,11 @@ func (h GRPCAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
 
 func (h GRPCAPI) Update(req *public.UpdateReq) error {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return err
 	}
 	_, err = cliGRPC.Update(ctx, req)
-	if err != nil{
+	if err != nil {
 		return err
 	}
 	return nil
@@ -44,11 +44,11 @@ func (h GRPCAPI) Update(req *public.UpdateReq) error {
 
 func (h GRPCAPI) Delete(req *public.DeleteReq) error {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return err
 	}
 	_, err = cliGRPC.Delete(ctx, req)
-	if err != nil{
+	if err != nil {
 		return err
 	}
 	return nil
@@ -56,11 +56,11 @@ func (h GRPCAPI) Delete(req *public.DeleteReq) error {
 
 func (h GRPCAPI) GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error) {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	resp, err := cliGRPC.GetByID(ctx, req)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	return resp, nil
@@ -68,11 +68,11 @@ func (h GRPCAPI) GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error) {
 
 func (h GRPCAPI) List() (*public.ListResp, error) {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	resp, err := cliGRPC.List(ctx, &empty.Empty{})
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	return resp, nil
@@ -80,18 +80,18 @@ func (h GRPCAPI) List() (*public.ListResp, error) {
 
 func (h GRPCAPI) GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, error) {
 	ctx, cliGRPC, err := getCli(h)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	resp, err := cliGRPC.GetByDate(ctx, req)
-	if err != nil{
+	if err != nil {
 		return nil, err
 	}
 	return resp, nil
 }
 
 func getCli(h GRPCAPI) (context.Context, public.GrpcClient, error) {
-	ctx,_ := context.WithTimeout(h.Ctx, 15*time.Second)
-	cliGRPC, err := public.NewClient(ctx,h.Host, h.Port)
+	ctx, _ := context.WithTimeout(h.Ctx, 15*time.Second)
+	cliGRPC, err := public.NewClient(ctx, h.Host, h.Port)
 	return ctx, cliGRPC, err
-}
\ No newline at end of file
+}
diff --git a/hw12_13_14_15_calendar/test/client/httpapi.go b/hw12_13_14_15_calendar/test/client/httpapi.go
index 7b1a92a..b49a89b 100644
--- a/hw12_13_14_15_calendar/test/client/httpapi.go
+++ b/hw12_13_14_15_calendar/test/client/httpapi.go
@@ -12,8 +12,8 @@ import (
 	"time"
 )
 
-type HTTPAPI struct{
-	Name string
+type HTTPAPI struct {
+	Name    string
 	BaseURL string
 }
 
@@ -22,19 +22,19 @@ func (h HTTPAPI) GetName() string {
 }
 
 func (h HTTPAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
-	jreq,err:= json.Marshal(req)
+	jreq, err := json.Marshal(req)
 	if err != nil {
 		return &public.CreateRsp{}, err
 	}
-	res, body, err := apiCall("POST",h.BaseURL+"/events", jreq)
+	res, body, err := apiCall("POST", h.BaseURL+"/events", jreq)
 	if err != nil {
 		return &public.CreateRsp{}, err
 	}
-	if res.StatusCode!=201 {
-		return &public.CreateRsp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 201 {
+		return &public.CreateRsp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var createRsp public.CreateRsp
-	err = json.Unmarshal(body,&createRsp)
+	err = json.Unmarshal(body, &createRsp)
 	if err != nil {
 		return &public.CreateRsp{}, err
 	}
@@ -42,85 +42,85 @@ func (h HTTPAPI) Create(req *public.CreateReq) (*public.CreateRsp, error) {
 }
 
 func (h HTTPAPI) Update(req *public.UpdateReq) error {
-	jreq, err:= json.Marshal(req)
+	jreq, err := json.Marshal(req)
 	if err != nil {
 		return err
 	}
-	res, _, err := apiCall("PUT",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	res, _, err := apiCall("PUT", h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
 	if err != nil {
 		return err
 	}
-	if res.StatusCode!=200 {
-		return fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 200 {
+		return fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	return nil
 }
 
 func (h HTTPAPI) Delete(req *public.DeleteReq) error {
-	jreq, err:= json.Marshal(req)
+	jreq, err := json.Marshal(req)
 	if err != nil {
 		return err
 	}
-	res, _, err := apiCall("DELETE",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	res, _, err := apiCall("DELETE", h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
 	if err != nil {
 		return err
 	}
-	if res.StatusCode!=200 {
-		return fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 200 {
+		return fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	return nil
 }
 
-func (h HTTPAPI) GetByID(req *public.GetByIDReq) ( *public.GetByIDResp, error) {
-	jreq, err:= json.Marshal(req)
+func (h HTTPAPI) GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error) {
+	jreq, err := json.Marshal(req)
 	if err != nil {
 		return &public.GetByIDResp{}, err
 	}
-	res, body, err := apiCall("GET",h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
+	res, body, err := apiCall("GET", h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
 	if err != nil {
 		return &public.GetByIDResp{}, err
 	}
-	if res.StatusCode!=200 {
-		return &public.GetByIDResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 200 {
+		return &public.GetByIDResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var getByIDResp public.GetByIDResp
-	err = json.Unmarshal(body,&getByIDResp)
+	err = json.Unmarshal(body, &getByIDResp)
 	if err != nil {
 		return &public.GetByIDResp{}, err
 	}
 	return &getByIDResp, nil
 }
 
-func (h HTTPAPI) List() ( *public.ListResp, error) {
-	res, body, err := apiCall("GET",h.BaseURL+"/events", nil)
+func (h HTTPAPI) List() (*public.ListResp, error) {
+	res, body, err := apiCall("GET", h.BaseURL+"/events", nil)
 	if err != nil {
 		return &public.ListResp{}, err
 	}
-	if res.StatusCode!=200 {
-		return &public.ListResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 200 {
+		return &public.ListResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var listResp public.ListResp
-	err = json.Unmarshal(body,&listResp)
+	err = json.Unmarshal(body, &listResp)
 	if err != nil {
 		return &public.ListResp{}, err
 	}
 	return &listResp, nil
 }
 
-func (h HTTPAPI) GetByDate(req *public.GetByDateReq) ( *public.GetByDateResp, error) {
-	jreq, err:= json.Marshal(req)
+func (h HTTPAPI) GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, error) {
+	jreq, err := json.Marshal(req)
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
-	res, body, err := apiCall("GET",h.BaseURL+"/events/"+string(req.Range)+"/"+req.Date.String(), jreq)
+	res, body, err := apiCall("GET", h.BaseURL+"/events/"+string(req.Range)+"/"+req.Date.String(), jreq)
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
-	if res.StatusCode!=200 {
-		return &public.GetByDateResp{}, fmt.Errorf("unexpected status code %d",res.StatusCode)
+	if res.StatusCode != 200 {
+		return &public.GetByDateResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var getByDateResp public.GetByDateResp
-	err = json.Unmarshal(body,&getByDateResp)
+	err = json.Unmarshal(body, &getByDateResp)
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
@@ -128,7 +128,7 @@ func (h HTTPAPI) GetByDate(req *public.GetByDateReq) ( *public.GetByDateResp, er
 }
 
 func apiCall(method string, url string, payload []byte) (*http.Response, []byte, error) {
-	client := &http.Client{Transport: &http.Transport{ DialContext: (&net.Dialer{ Timeout: 15*time.Second}).DialContext }}
+	client := &http.Client{Transport: &http.Transport{DialContext: (&net.Dialer{Timeout: 15 * time.Second}).DialContext}}
 	req, err := http.NewRequest(method, url, bytes.NewBuffer(payload))
 	if err != nil {
 		return nil, nil, err
diff --git a/hw12_13_14_15_calendar/test/main.go b/hw12_13_14_15_calendar/test/main.go
index 7dd8061..ec84ace 100644
--- a/hw12_13_14_15_calendar/test/main.go
+++ b/hw12_13_14_15_calendar/test/main.go
@@ -4,7 +4,6 @@ import (
 	"log"
 )
 
-
 func main() {
 	log.Fatalln("Nothing to do")
 }
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index 74a72c8..8da33ef 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -14,28 +14,28 @@ import (
 
 func TestPublicAPIEndpoints(t *testing.T) {
 	cli := []client.Interface{
-		client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port:"50051", Name: "GRPC API"},
+		client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port: "50051", Name: "GRPC API"},
 		client.HTTPAPI{BaseURL: "http://localhost:50052", Name: "HTTP REST API"},
 	}
 	wg := sync.WaitGroup{}
-	wg.Add(len(cli)*5)
+	wg.Add(len(cli) * 5)
 
-	for _,c := range cli {
+	for _, c := range cli {
 		t.Run("test "+c.GetName()+" for Create, GetById and Delete", func(t *testing.T) {
 			var ids []int64
 			defer func() {
 				wg.Done()
-				clean(c,&ids)
+				clean(c, &ids)
 			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
-			ids=append(ids,resp1.ID)
+			ids = append(ids, resp1.ID)
 
-			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			resp2, err := c.GetByID(&public.GetByIDReq{ID: resp1.ID})
 			require.NoError(t, err)
-			require.Equal(t,1, len(resp2.Events))
+			require.Equal(t, 1, len(resp2.Events))
 			require.Equal(t, misc.TestEvent01.Title, resp2.Events[0].Title)
 			require.Equal(t, misc.TestEvent01.UserID, resp2.Events[0].UserID)
 			require.Equal(t, misc.TestEvent01.Note, resp2.Events[0].Note)
@@ -45,20 +45,20 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			var ids []int64
 			defer func() {
 				wg.Done()
-				clean(c,&ids)
+				clean(c, &ids)
 			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
-			ids=append(ids,resp1.ID)
+			ids = append(ids, resp1.ID)
 
-			err = c.Update(&public.UpdateReq{ID:resp1.ID, Event: &public.Event{ ID: resp1.ID, Title: misc.TestEvent02.Title, Date: misc.TestEvent02.Date, Latency: misc.TestEvent02.Latency, Note: misc.TestEvent02.Note, UserID: misc.TestEvent02.UserID, NotifyTime: misc.TestEvent02.NotifyTime }})
+			err = c.Update(&public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: misc.TestEvent02.Title, Date: misc.TestEvent02.Date, Latency: misc.TestEvent02.Latency, Note: misc.TestEvent02.Note, UserID: misc.TestEvent02.UserID, NotifyTime: misc.TestEvent02.NotifyTime}})
 			require.NoError(t, err)
 
-			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			resp2, err := c.GetByID(&public.GetByIDReq{ID: resp1.ID})
 			require.NoError(t, err)
-			require.Equal(t,1, len(resp2.Events))
+			require.Equal(t, 1, len(resp2.Events))
 			require.Equal(t, misc.TestEvent02.Title, resp2.Events[0].Title)
 			require.Equal(t, misc.TestEvent02.UserID, resp2.Events[0].UserID)
 			require.Equal(t, misc.TestEvent02.Note, resp2.Events[0].Note)
@@ -71,10 +71,10 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
 
-			err = c.Delete(&public.DeleteReq{ ID: resp1.ID })
+			err = c.Delete(&public.DeleteReq{ID: resp1.ID})
 			require.NoError(t, err)
 
-			resp2,err := c.GetByID(&public.GetByIDReq{ID:resp1.ID})
+			resp2, err := c.GetByID(&public.GetByIDReq{ID: resp1.ID})
 			require.Error(t, err)
 			require.Nil(t, resp2)
 		})
@@ -83,19 +83,18 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			var ids []int64
 			defer func() {
 				wg.Done()
-				clean(c,&ids)
+				clean(c, &ids)
 			}()
 
 			resp1, err := c.Create(&misc.TestEvent01)
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
-			ids=append(ids,resp1.ID)
-
+			ids = append(ids, resp1.ID)
 
 			resp2, err := c.Create(&misc.TestEvent02)
 			require.NoError(t, err)
 			require.Greater(t, resp2.ID, int64(0))
-			ids=append(ids,resp2.ID)
+			ids = append(ids, resp2.ID)
 
 			resp3, err := c.List()
 			require.NoError(t, err)
@@ -112,10 +111,10 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.True(t, e1)
 			require.True(t, e2)
 
-			err = c.Delete(&public.DeleteReq{ ID: resp1.ID })
+			err = c.Delete(&public.DeleteReq{ID: resp1.ID})
 			require.NoError(t, err)
 
-			err = c.Delete(&public.DeleteReq{ ID: resp2.ID })
+			err = c.Delete(&public.DeleteReq{ID: resp2.ID})
 			require.NoError(t, err)
 		})
 
@@ -123,12 +122,12 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			var ids []int64
 			defer func() {
 				wg.Done()
-				clean(c,&ids)
+				clean(c, &ids)
 			}()
 
-			startDate, err := time.Parse("2006-01-02T15:04:00","3100-01-01T12:00:00")
+			startDate, err := time.Parse("2006-01-02T15:04:00", "3100-01-01T12:00:00")
 			require.NoError(t, err)
-			for i:=time.Hour;i<(60*24*time.Hour);i=i+48*time.Hour{
+			for i := time.Hour; i < (60 * 24 * time.Hour); i = i + 48*time.Hour {
 				resp1, err := c.Create(&public.CreateReq{
 					Title:      "Test event 02",
 					Date:       misc.Time2pbtimestamp(startDate.Add(i)),
@@ -139,29 +138,29 @@ func TestPublicAPIEndpoints(t *testing.T) {
 				})
 				require.NoError(t, err)
 				require.Greater(t, resp1.ID, int64(0))
-				ids=append(ids,resp1.ID)
+				ids = append(ids, resp1.ID)
 			}
 
-			resp2,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_DAY})
+			resp2, err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_DAY})
 			require.NoError(t, err)
-			require.Equal(t, 1, len(resp2.Events) )
+			require.Equal(t, 1, len(resp2.Events))
 
-			resp3,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_WEEK})
+			resp3, err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_WEEK})
 			require.NoError(t, err)
-			require.Equal(t, 4, len(resp3.Events) )
+			require.Equal(t, 4, len(resp3.Events))
 
-			resp4,err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_MONTH})
+			resp4, err := c.GetByDate(&public.GetByDateReq{Date: misc.Time2pbtimestamp(startDate), Range: public.QueryRange_MONTH})
 			require.NoError(t, err)
-			require.Equal(t, 16, len(resp4.Events) )
+			require.Equal(t, 16, len(resp4.Events))
 		})
 	}
 }
 
 func clean(c client.Interface, ids *[]int64) {
-	for _,m := range *ids {
-		err := c.Delete(&public.DeleteReq{ID:m})
+	for _, m := range *ids {
+		err := c.Delete(&public.DeleteReq{ID: m})
 		if err != nil {
 			log.Println("error when try to clean DB: ", err.Error())
 		}
 	}
-}
\ No newline at end of file
+}

From b5d5f8761524e94393537439fda996f9a1e78152 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Sat, 20 Mar 2021 14:12:07 -0400
Subject: [PATCH 13/20] HW15 WIP

---
 hw12_13_14_15_calendar/configs/calendar.conf  |  2 +-
 .../internal/api/private/converters.go        |  2 +-
 .../pkg/api/public/converters.go              |  2 +-
 .../pkg/api/rest/handlers.go                  | 20 +++++++++---------
 hw12_13_14_15_calendar/test/client/httpapi.go | 21 ++++++++++---------
 hw12_13_14_15_calendar/test/main_test.go      |  3 +--
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index b1f3a9e..3518edc 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -15,7 +15,7 @@ File = "./logs/calendar.log"
 Level = "INFO"
 
 [Storage]
-inMemory = false
+inMemory = true
 SQLHost = "localhost"
 SQLPort = "5432"
 SQLDbase = "calendar"
diff --git a/hw12_13_14_15_calendar/internal/api/private/converters.go b/hw12_13_14_15_calendar/internal/api/private/converters.go
index df1eb7c..4b0cbea 100644
--- a/hw12_13_14_15_calendar/internal/api/private/converters.go
+++ b/hw12_13_14_15_calendar/internal/api/private/converters.go
@@ -20,5 +20,5 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		events[i] = &evt
 		i++
 	}
-	return events, fmt.Errorf("can't convert types: %w", err)
+	return events, nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/api/public/converters.go b/hw12_13_14_15_calendar/pkg/api/public/converters.go
index 0522b29..7a75f67 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/converters.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/converters.go
@@ -55,7 +55,7 @@ func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, erro
 		events[i] = &evt
 		i++
 	}
-	return events, fmt.Errorf("can't convert types: %w", err)
+	return events, nil
 }
 
 func (s Service) buildTimeAndRange(e *GetByDateReq) (start time.Time, qrange string, err error) {
diff --git a/hw12_13_14_15_calendar/pkg/api/rest/handlers.go b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
index 425079b..aecdd8f 100644
--- a/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
+++ b/hw12_13_14_15_calendar/pkg/api/rest/handlers.go
@@ -2,8 +2,8 @@ package rest
 
 import (
 	"encoding/json"
+	"fmt"
 	"io/ioutil"
-	"log"
 	"net/http"
 	"strconv"
 	"time"
@@ -53,7 +53,7 @@ func FromRESTUpdate(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't get request parameter", err, calendar.Logger, r)
 		}
-		bodyReq := public.Event{}
+		bodyReq := public.UpdateReq{}
 		bodyIn, err := ioutil.ReadAll(req.Body)
 		defer req.Body.Close()
 		if err != nil {
@@ -63,7 +63,7 @@ func FromRESTUpdate(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't unmarshal data from HTTP API request", err, calendar.Logger, r)
 		}
-		evt, err := pubEvent2Event(bodyReq)
+		evt, err := pubEvent2Event(*bodyReq.Event)
 		if err != nil {
 			err503("can't convert types", err, calendar.Logger, r)
 		}
@@ -117,7 +117,10 @@ func FromRESTGetByID(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't get request parameter", err, calendar.Logger, r)
 		}
-		ev, _ := calendar.Storage.GetByID(event.ID(paramID))
+		ev, ok := calendar.Storage.GetByID(event.ID(paramID))
+		if !ok {
+			err503("event not found", fmt.Errorf("no one"), calendar.Logger, r)
+		}
 		evnt, err := event2pubEvent(ev)
 		if err != nil {
 			err503("can't convert types", err, calendar.Logger, r)
@@ -126,21 +129,18 @@ func FromRESTGetByID(calendar *calendar.App) http.HandlerFunc {
 		if err != nil {
 			err503("can't marshal request", err, calendar.Logger, r)
 		}
-		r.WriteHeader(200)
 		_, err = r.Write(bodyOut)
 		if err != nil {
 			calendar.Logger.Errorf("can't send response")
 		}
-
-		log.Println(paramID)
-		r.WriteHeader(555)
 	}
 }
 
 func FromRESTGetByDate(calendar *calendar.App) http.HandlerFunc {
 	return func(r http.ResponseWriter, req *http.Request) {
 		paramRange := mux.Vars(req)["Range"]
-		paramDate, err := time.Parse("2006-01-02 15:04:05", mux.Vars(req)["Date"])
+		d, err := strconv.Atoi(mux.Vars(req)["Date"])
+		paramDate := time.Unix(int64(d), 0)
 		if err != nil {
 			err503("can't parse date from request parameter", err, calendar.Logger, r)
 		}
@@ -165,6 +165,6 @@ func FromRESTGetByDate(calendar *calendar.App) http.HandlerFunc {
 }
 
 func err503(s string, err error, l logger.Interface, r http.ResponseWriter) {
-	l.Errorf(s, ": ", err.Error())
+	l.Errorf("%s: %w", s, err.Error())
 	r.WriteHeader(503)
 }
diff --git a/hw12_13_14_15_calendar/test/client/httpapi.go b/hw12_13_14_15_calendar/test/client/httpapi.go
index b49a89b..2c9d303 100644
--- a/hw12_13_14_15_calendar/test/client/httpapi.go
+++ b/hw12_13_14_15_calendar/test/client/httpapi.go
@@ -74,21 +74,21 @@ func (h HTTPAPI) Delete(req *public.DeleteReq) error {
 func (h HTTPAPI) GetByID(req *public.GetByIDReq) (*public.GetByIDResp, error) {
 	jreq, err := json.Marshal(req)
 	if err != nil {
-		return &public.GetByIDResp{}, err
+		return nil, err
 	}
 	res, body, err := apiCall("GET", h.BaseURL+"/events/"+strconv.Itoa(int(req.ID)), jreq)
 	if err != nil {
-		return &public.GetByIDResp{}, err
+		return nil, err
 	}
 	if res.StatusCode != 200 {
-		return &public.GetByIDResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
+		return nil, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
-	var getByIDResp public.GetByIDResp
-	err = json.Unmarshal(body, &getByIDResp)
+	var ev public.Event
+	err = json.Unmarshal(body, &ev)
 	if err != nil {
-		return &public.GetByIDResp{}, err
+		return nil, err
 	}
-	return &getByIDResp, nil
+	return &public.GetByIDResp{Events: []*public.Event{&ev}}, nil
 }
 
 func (h HTTPAPI) List() (*public.ListResp, error) {
@@ -100,7 +100,7 @@ func (h HTTPAPI) List() (*public.ListResp, error) {
 		return &public.ListResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var listResp public.ListResp
-	err = json.Unmarshal(body, &listResp)
+	err = json.Unmarshal(body, &listResp.Events)
 	if err != nil {
 		return &public.ListResp{}, err
 	}
@@ -112,7 +112,8 @@ func (h HTTPAPI) GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, err
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
-	res, body, err := apiCall("GET", h.BaseURL+"/events/"+string(req.Range)+"/"+req.Date.String(), jreq)
+
+	res, body, err := apiCall("GET", h.BaseURL+"/events/"+req.Range.String()+"/"+strconv.Itoa(int(req.Date.Seconds)), jreq)
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
@@ -120,7 +121,7 @@ func (h HTTPAPI) GetByDate(req *public.GetByDateReq) (*public.GetByDateResp, err
 		return &public.GetByDateResp{}, fmt.Errorf("unexpected status code %d", res.StatusCode)
 	}
 	var getByDateResp public.GetByDateResp
-	err = json.Unmarshal(body, &getByDateResp)
+	err = json.Unmarshal(body, &getByDateResp.Events)
 	if err != nil {
 		return &public.GetByDateResp{}, err
 	}
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index 8da33ef..ab80e3f 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"context"
 	"github.com/stretchr/testify/require"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
@@ -14,7 +13,7 @@ import (
 
 func TestPublicAPIEndpoints(t *testing.T) {
 	cli := []client.Interface{
-		client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port: "50051", Name: "GRPC API"},
+		// client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port: "50051", Name: "GRPC API"},
 		client.HTTPAPI{BaseURL: "http://localhost:50052", Name: "HTTP REST API"},
 	}
 	wg := sync.WaitGroup{}

From fda5fb0a49be1bfc03e7b715429759f72c2b6655 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Sat, 20 Mar 2021 21:17:45 +0300
Subject: [PATCH 14/20] Update .golangci.yml

---
 .golangci.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.golangci.yml b/.golangci.yml
index ec5a5e2..5bb7646 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -17,4 +17,3 @@ linters:
     - gosec
     - nlreturn
     - exhaustive
-    - exhaustivestruct
\ No newline at end of file

From e213b4a9006c1fcdfe1d4d8b8177390a3bcd879f Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 22 Mar 2021 06:23:57 -0400
Subject: [PATCH 15/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile             |  5 ++++-
 hw12_13_14_15_calendar/cicd/dc_calendar.yml |  2 +-
 hw12_13_14_15_calendar/go.mod               |  2 --
 hw12_13_14_15_calendar/go.sum               | 12 ------------
 hw12_13_14_15_calendar/test/Dockerfile      |  6 ++++++
 hw12_13_14_15_calendar/test/main_test.go    |  3 ++-
 6 files changed, 13 insertions(+), 17 deletions(-)
 create mode 100644 hw12_13_14_15_calendar/test/Dockerfile

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 1e2b9f6..95971ff 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -3,6 +3,9 @@ cdir = $(shell pwd)
 integration-test:
 	go test -count 10 -race ./cmd/calendar/... --config ./../../configs/calendar.conf
 
+bdd:
+	docker build -t bdd --network host -f test/Dockerfile .
+
 test:
 	go test -race ./internal/... ./pkg/...
 
@@ -41,6 +44,6 @@ sup-down:
 	docker-compose -f ./cicd/dc_sup.yml down
 
 clean:
-	sudo docker rmi $(sudo docker images | grep '<none>' | awk '{print $3}')
+	docker rmi $(sudo docker images | grep '<none>' | awk '{print $3}')
 
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/dc_calendar.yml b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
index 90c9ab4..c56a30c 100644
--- a/hw12_13_14_15_calendar/cicd/dc_calendar.yml
+++ b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
@@ -11,7 +11,7 @@ services:
       APP_GRPC_ADDRESS: 0.0.0.0
       APP_GRPC_PORT: 50051
       APP_HTTP_ADDRESS: 0.0.0.0
-      APP_HTTP_PORT: 8888
+      APP_HTTP_PORT: 50052
       APP_API_ADDRESS: 0.0.0.0
       APP_API_PORT: 50053
       APP_LOGGER_FILE: /logs/calendar.log
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index 249adf8..854a676 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -8,7 +8,6 @@ require (
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/golang/protobuf v1.4.2
 	github.com/gorilla/mux v1.8.0
-	github.com/grpc-ecosystem/grpc-gateway v1.15.0
 	github.com/kr/text v0.2.0 // indirect
 	github.com/lib/pq v1.10.0
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
@@ -17,7 +16,6 @@ require (
 	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
 	go.uber.org/zap v1.15.0 // indirect
-	golang.org/x/net v0.0.0-20200625001655-4c5254603344
 	golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
 	golang.org/x/text v0.3.3 // indirect
 	golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 // indirect
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index 98f3379..1c88ff2 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -1,10 +1,8 @@
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
-cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec h1:tDOPo9NAXCjvoK35HgZyzQSNLmb3chZqN2tnO273Bro=
 github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec/go.mod h1:RZEHP3cxXvQlMuMjkpdh6qXA4b0CpjxnUBNxOpR0r30=
-github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
@@ -16,7 +14,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
-github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -41,8 +38,6 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
 github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
-github.com/grpc-ecosystem/grpc-gateway v1.15.0 h1:ntPNC9TD/6l2XDenJZe6T5lSMg95thpV9sGAqHX4WU8=
-github.com/grpc-ecosystem/grpc-gateway v1.15.0/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -61,7 +56,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
-github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
@@ -103,19 +97,15 @@ golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
-golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -148,7 +138,6 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
-google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70 h1:wboULUXGF3c5qdUnKp+6gLAccE6PRpa/czkYvQ4UXv8=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
@@ -177,7 +166,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
diff --git a/hw12_13_14_15_calendar/test/Dockerfile b/hw12_13_14_15_calendar/test/Dockerfile
new file mode 100644
index 0000000..e20cde2
--- /dev/null
+++ b/hw12_13_14_15_calendar/test/Dockerfile
@@ -0,0 +1,6 @@
+FROM golang:1.14
+RUN mkdir -p /app
+WORKDIR /app
+COPY . .
+RUN go get -d /app/test/.
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test ./test/...
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index ab80e3f..75e7250 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -5,6 +5,7 @@ import (
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
+	"context"
 	"log"
 	"sync"
 	"testing"
@@ -13,7 +14,7 @@ import (
 
 func TestPublicAPIEndpoints(t *testing.T) {
 	cli := []client.Interface{
-		// client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port: "50051", Name: "GRPC API"},
+		client.GRPCAPI{Ctx: context.Background(), Host: "localhost", Port: "50051", Name: "GRPC API"},
 		client.HTTPAPI{BaseURL: "http://localhost:50052", Name: "HTTP REST API"},
 	}
 	wg := sync.WaitGroup{}

From bb3e580e67f3ce66a3431418065719fba1a16ed3 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 22 Mar 2021 09:15:36 -0400
Subject: [PATCH 16/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 95971ff..68278dd 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -1,11 +1,25 @@
 cdir = $(shell pwd)
 
-integration-test:
+inplace-integration-test:
 	go test -count 10 -race ./cmd/calendar/... --config ./../../configs/calendar.conf
 
 bdd:
 	docker build -t bdd --network host -f test/Dockerfile .
 
+integration-test:
+	set -e ;\
+	docker-compose -f ./cicd/dc_sup.yml up -d --build ;\
+	docker-compose -f ./cicd/dc_calendar.yml up -d --build ;\
+	docker-compose -f ./cicd/dc_sender.yml up -d --build ;\
+	docker-compose -f ./cicd/dc_sheduler.yml up -d --build ;\
+	test_status_code=0 ;\
+	docker build -t bdd --network host -f test/Dockerfile . || test_status_code=$$? ;\
+	docker-compose -f ./cicd/dc_sup.yml down --rmi local --volumes --remove-orphans --timeout 60 ;\
+	docker-compose -f ./cicd/dc_calendar.yml down --rmi local --volumes --remove-orphans --timeout 60 ;\
+	docker-compose -f ./cicd/dc_sender.yml down --rmi local --volumes --remove-orphans --timeout 60 ;\
+	docker-compose -f ./cicd/dc_sheduler.yml down --rmi local --volumes --remove-orphans --timeout 60 ;\
+	exit $$test_status_code
+
 test:
 	go test -race ./internal/... ./pkg/...
 
@@ -43,7 +57,4 @@ sup-up:
 sup-down:
 	docker-compose -f ./cicd/dc_sup.yml down
 
-clean:
-	docker rmi $(sudo docker images | grep '<none>' | awk '{print $3}')
-
 .PHONY: build run test lint
\ No newline at end of file

From 1c4ba38acf1138584afe59ce304447c3f2cf8835 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Mon, 22 Mar 2021 13:03:12 -0400
Subject: [PATCH 17/20] HW15 WIP

---
 .../api/public/public.proto                   |  1 +
 hw12_13_14_15_calendar/cicd/dc_sender.yml     |  2 +
 .../cmd/calendar/main_test.go                 | 95 -------------------
 hw12_13_14_15_calendar/configs/calendar.conf  |  2 +-
 hw12_13_14_15_calendar/configs/scheduler.conf |  2 +-
 hw12_13_14_15_calendar/configs/sender.conf    |  6 +-
 .../internal/sender/app_sender.go             | 24 +++--
 .../internal/sheduler/app_scheduler.go        |  2 +-
 .../internal/sheduler/scheduler.go            |  5 +-
 .../pkg/api/public/public.pb.go               | 85 +++++++++--------
 hw12_13_14_15_calendar/pkg/storage/sql/sql.go | 22 ++---
 hw12_13_14_15_calendar/test/main_test.go      | 23 ++++-
 hw12_13_14_15_calendar/test/misc/misc.go      |  9 ++
 13 files changed, 119 insertions(+), 159 deletions(-)

diff --git a/hw12_13_14_15_calendar/api/public/public.proto b/hw12_13_14_15_calendar/api/public/public.proto
index 5b0c4dd..4d82ba8 100644
--- a/hw12_13_14_15_calendar/api/public/public.proto
+++ b/hw12_13_14_15_calendar/api/public/public.proto
@@ -58,6 +58,7 @@ message Event {
   string Note = 5;
   int64 UserID = 6;
   google.protobuf.Duration NotifyTime = 7;
+  bool notified = 8;
 }
 
 message CreateReq {
diff --git a/hw12_13_14_15_calendar/cicd/dc_sender.yml b/hw12_13_14_15_calendar/cicd/dc_sender.yml
index 919eaa1..9a0145f 100644
--- a/hw12_13_14_15_calendar/cicd/dc_sender.yml
+++ b/hw12_13_14_15_calendar/cicd/dc_sender.yml
@@ -15,6 +15,8 @@ services:
       APP_RABBITMQ_EXCHANGE: calendar
       APP_RABBITMQ_QUEUE: notifications
       APP_RABBITMQ_KEY: events
+      APP_API_ADDRESS: localhost
+      APP_API_PORT: 50053
       APP_LOGGER_FILE: /logs/calendar.log
       APP_LOGGER_LEVEL: INFO
     network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cmd/calendar/main_test.go b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
index baf13bc..6721274 100644
--- a/hw12_13_14_15_calendar/cmd/calendar/main_test.go
+++ b/hw12_13_14_15_calendar/cmd/calendar/main_test.go
@@ -148,101 +148,6 @@ func TestPublicGRPCEndpoint(t *testing.T) {
 	wg.Wait()
 }
 
-func TestPublicAPIEndpoint(t *testing.T) {
-	wg := sync.WaitGroup{}
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-	publicAPI, err := public.NewClient(ctx, "localhost", "50051")
-	require.NoError(t, err)
-
-	wg.Add(5)
-	// Реализовать тесты логики приложения:
-	t.Run("test public GRPC.Create and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent01.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent01.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent01.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent01.Note, resp2.Events[0].Note)
-	})
-
-	t.Run("test public GRPC.Create, GRPC.Update and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Update(ctx, &public.UpdateReq{ID: resp1.ID, Event: &public.Event{ID: resp1.ID, Title: testEvent02.Title, Date: testEvent02.Date, Latency: testEvent02.Latency, Note: testEvent02.Note, UserID: testEvent02.UserID, NotifyTime: testEvent02.NotifyTime}})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.NoError(t, err)
-		require.Equal(t, 1, len(resp2.Events))
-		require.Equal(t, testEvent02.Title, resp2.Events[0].Title)
-		require.Equal(t, testEvent02.UserID, resp2.Events[0].UserID)
-		require.Equal(t, testEvent02.Date.Seconds, resp2.Events[0].Date.Seconds)
-		require.Equal(t, testEvent02.Note, resp2.Events[0].Note)
-	})
-
-	t.Run("test public GRPC.Create, GRPC.Delete and GRPC.GetById", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		require.Greater(t, resp1.ID, int64(0))
-		_, err = publicAPI.Delete(ctx, &public.DeleteReq{ID: resp1.ID})
-		require.NoError(t, err)
-		resp2, err := publicAPI.GetByID(ctx, &public.GetByIDReq{ID: resp1.ID})
-		require.Error(t, err)
-		require.Nil(t, resp2)
-	})
-
-	t.Run("test public GRPC.Create and GRPC.List", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		resp2, err := publicAPI.Create(ctx, &testEvent02)
-		require.NoError(t, err)
-		require.NotEqual(t, resp1.ID, resp2.ID)
-
-		list, err := publicAPI.List(ctx, &empty.Empty{})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1, e2 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-			if v.ID == resp2.ID {
-				e2 = true
-			}
-		}
-		require.True(t, e1)
-		require.True(t, e2)
-	})
-
-	t.Run("test public GRPC.Create and GRPC.GetByDate", func(t *testing.T) {
-		defer wg.Done()
-		resp1, err := publicAPI.Create(ctx, &testEvent01)
-		require.NoError(t, err)
-		list, err := publicAPI.GetByDate(ctx, &public.GetByDateReq{Date: testEvent01.Date, Range: public.QueryRange_DAY})
-		require.NoError(t, err)
-		require.GreaterOrEqual(t, len(list.Events), 2)
-		var e1 bool
-		for _, v := range list.Events {
-			if v.ID == resp1.ID {
-				e1 = true
-			}
-		}
-		require.True(t, e1)
-	})
-
-	wg.Wait()
-}
-
 func time2pbtimestamp(t time.Time) *timestamp.Timestamp {
 	r, err := ptypes.TimestampProto(t)
 	if err != nil {
diff --git a/hw12_13_14_15_calendar/configs/calendar.conf b/hw12_13_14_15_calendar/configs/calendar.conf
index 3518edc..b1f3a9e 100644
--- a/hw12_13_14_15_calendar/configs/calendar.conf
+++ b/hw12_13_14_15_calendar/configs/calendar.conf
@@ -15,7 +15,7 @@ File = "./logs/calendar.log"
 Level = "INFO"
 
 [Storage]
-inMemory = true
+inMemory = false
 SQLHost = "localhost"
 SQLPort = "5432"
 SQLDbase = "calendar"
diff --git a/hw12_13_14_15_calendar/configs/scheduler.conf b/hw12_13_14_15_calendar/configs/scheduler.conf
index da6ef69..3abe61e 100644
--- a/hw12_13_14_15_calendar/configs/scheduler.conf
+++ b/hw12_13_14_15_calendar/configs/scheduler.conf
@@ -11,6 +11,6 @@ Key = "events"
 File = "./logs/calendar.log"
 Level = "INFO"
 
-[API]
+[CalendarAPI]
 Address = "localhost"
 Port = "50053"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/configs/sender.conf b/hw12_13_14_15_calendar/configs/sender.conf
index 2e6ebcc..da6ef69 100644
--- a/hw12_13_14_15_calendar/configs/sender.conf
+++ b/hw12_13_14_15_calendar/configs/sender.conf
@@ -9,4 +9,8 @@ Key = "events"
 
 [Logger]
 File = "./logs/calendar.log"
-Level = "INFO"
\ No newline at end of file
+Level = "INFO"
+
+[API]
+Address = "localhost"
+Port = "50053"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/internal/sender/app_sender.go b/hw12_13_14_15_calendar/internal/sender/app_sender.go
index 6117811..04880d3 100644
--- a/hw12_13_14_15_calendar/internal/sender/app_sender.go
+++ b/hw12_13_14_15_calendar/internal/sender/app_sender.go
@@ -13,15 +13,17 @@ import (
 )
 
 type Sender struct {
-	Logger logger.Interface
-	Rabbit *rabbit.Rabbit
-	Queue  string
-	Stop   context.CancelFunc
+	GRPCAPI private.GrpcClient
+	Logger  logger.Interface
+	Rabbit  *rabbit.Rabbit
+	Queue   string
+	Stop    context.CancelFunc
 }
 
 type Config struct {
-	Rabbitmq config.Rabbit
-	Logger   config.Logger
+	CalendarAPI config.Server
+	Rabbitmq    config.Rabbit
+	Logger      config.Logger
 }
 
 func New(conf Config) Sender {
@@ -33,7 +35,11 @@ func New(conf Config) Sender {
 	if err != nil {
 		log.Fatalf("failed to connect to RabbitMQ:", err.Error())
 	}
-	return Sender{Logger: log, Rabbit: rb, Queue: conf.Rabbitmq.Queue}
+	cli, err := private.NewClient(conf.CalendarAPI.Address, conf.CalendarAPI.Port)
+	if err != nil {
+		log.Fatalf("can't get GRPC client: %w", err.Error())
+	}
+	return Sender{Logger: log, Rabbit: rb, Queue: conf.Rabbitmq.Queue, GRPCAPI: cli}
 }
 
 func (s *Sender) Start() error {
@@ -54,6 +60,10 @@ func (s *Sender) Start() error {
 					s.Logger.Errorf("can`t unmarshal data %w", err)
 				}
 				for _, v := range data {
+					_, err = s.GRPCAPI.SetNotified(ctx, &private.SetReq{ID: v.ID})
+					if err != nil {
+						s.Logger.Errorf("can`t mark event with ID %d as notified data %w", v.ID, err)
+					}
 					s.Logger.Infof("User %s notified about event %s", v.UserID, v.ID)
 				}
 			case <-ctx.Done():
diff --git a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
index 8932b72..c6034b0 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/app_scheduler.go
@@ -39,7 +39,7 @@ func New(conf Config) Scheduler {
 func (s *Scheduler) Start() error {
 	ctx, cancel := context.WithCancel(context.Background())
 	s.Stop = cancel
-	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit, s.Logger) }, 1*time.Minute)
+	fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit, s.Logger) }, 10*time.Second)
 	go func() {
 		for {
 			select {
diff --git a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
index 75850a7..a00a71a 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"time"
 
+	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/api/private"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/logger"
@@ -43,11 +44,11 @@ func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit, l
 	if err != nil {
 		return fmt.Errorf("can't get GRPC client: %w", err)
 	}
-	resp, err := cli.GetNotifications(ctx, nil)
+	resp, err := cli.GetNotifications(ctx, &empty.Empty{})
 	if err != nil {
 		return fmt.Errorf("can't get events from GRPC endpoint: %w", err)
 	}
-	for event := range resp.Events {
+	for _, event := range resp.Events {
 		b, err := json.Marshal(event)
 		if err != nil {
 			return fmt.Errorf("can't marshal events into JSON: %w", err)
diff --git a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
index e9ecd62..ccd63bc 100644
--- a/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
+++ b/hw12_13_14_15_calendar/pkg/api/public/public.pb.go
@@ -64,6 +64,7 @@ type Event struct {
 	Note                 string               `protobuf:"bytes,5,opt,name=Note,proto3" json:"Note,omitempty"`
 	UserID               int64                `protobuf:"varint,6,opt,name=UserID,proto3" json:"UserID,omitempty"`
 	NotifyTime           *duration.Duration   `protobuf:"bytes,7,opt,name=NotifyTime,proto3" json:"NotifyTime,omitempty"`
+	Notified             bool                 `protobuf:"varint,8,opt,name=notified,proto3" json:"notified,omitempty"`
 	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
 	XXX_unrecognized     []byte               `json:"-"`
 	XXX_sizecache        int32                `json:"-"`
@@ -143,6 +144,13 @@ func (m *Event) GetNotifyTime() *duration.Duration {
 	return nil
 }
 
+func (m *Event) GetNotified() bool {
+	if m != nil {
+		return m.Notified
+	}
+	return false
+}
+
 type CreateReq struct {
 	Title                string               `protobuf:"bytes,2,opt,name=Title,proto3" json:"Title,omitempty"`
 	Date                 *timestamp.Timestamp `protobuf:"bytes,3,opt,name=Date,proto3" json:"Date,omitempty"`
@@ -567,45 +575,46 @@ func init() {
 func init() { proto.RegisterFile("public.proto", fileDescriptor_413a91106d7bcce8) }
 
 var fileDescriptor_413a91106d7bcce8 = []byte{
-	// 606 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0xcd, 0x6e, 0xd3, 0x40,
-	0x10, 0xc7, 0x71, 0xe2, 0x38, 0xf5, 0x34, 0x2d, 0xe9, 0x50, 0x8a, 0x71, 0xab, 0x12, 0x2d, 0x42,
+	// 619 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x95, 0xcd, 0x6e, 0xd3, 0x40,
+	0x10, 0xc7, 0xb1, 0xe3, 0x38, 0xf6, 0x34, 0x2d, 0xe9, 0x50, 0x8a, 0x71, 0xab, 0x12, 0x2d, 0x42,
 	0x8a, 0x72, 0xb0, 0x45, 0x8a, 0x90, 0xe0, 0x44, 0x8b, 0x23, 0x6a, 0x51, 0x8a, 0xb0, 0x5a, 0xf1,
-	0x71, 0x73, 0xd2, 0x6d, 0xb0, 0x94, 0xd8, 0x8b, 0xbd, 0x41, 0x8a, 0xaa, 0x5c, 0x78, 0x05, 0xde,
-	0x8a, 0x2b, 0xaf, 0xc0, 0x95, 0x07, 0xe0, 0x86, 0xbc, 0x5e, 0x3b, 0xcd, 0x47, 0x45, 0xee, 0xdc,
-	0xb2, 0xfb, 0x9f, 0xf9, 0xcd, 0xcc, 0xce, 0x5f, 0x31, 0xd4, 0xd8, 0xa8, 0x3b, 0x08, 0x7a, 0x16,
-	0x8b, 0x23, 0x1e, 0xa1, 0x96, 0x9d, 0xcc, 0x07, 0xfd, 0x28, 0xea, 0x0f, 0xa8, 0x2d, 0x6e, 0xbb,
-	0xa3, 0x4b, 0x9b, 0x07, 0x43, 0x9a, 0x70, 0x7f, 0xc8, 0xb2, 0x40, 0x73, 0x7f, 0x3e, 0xe0, 0x62,
-	0x14, 0xfb, 0x3c, 0x88, 0x42, 0xa9, 0xef, 0xce, 0xeb, 0x74, 0xc8, 0xf8, 0x58, 0x8a, 0x7b, 0x52,
-	0xf4, 0x59, 0x60, 0xfb, 0x61, 0x18, 0x71, 0x91, 0x99, 0x64, 0x2a, 0xf9, 0xa3, 0x40, 0xa5, 0xf3,
-	0x95, 0x86, 0x1c, 0x37, 0xa1, 0xe4, 0x3a, 0x86, 0xd2, 0x50, 0x9a, 0x65, 0xaf, 0xe4, 0x3a, 0xb8,
-	0x0d, 0x95, 0xb3, 0x80, 0x0f, 0xa8, 0x51, 0x6a, 0x28, 0x4d, 0xdd, 0xcb, 0x0e, 0x68, 0x81, 0xea,
-	0xf8, 0x9c, 0x1a, 0xe5, 0x86, 0xd2, 0x5c, 0x6f, 0x9b, 0x56, 0x06, 0xb7, 0xf2, 0xca, 0xd6, 0x59,
-	0xde, 0xba, 0x27, 0xe2, 0xf0, 0x00, 0xaa, 0x27, 0x3e, 0xa7, 0x61, 0x6f, 0x6c, 0xa8, 0x22, 0xe5,
-	0xfe, 0x42, 0x8a, 0x23, 0x87, 0xf1, 0xf2, 0x48, 0x44, 0x50, 0x4f, 0x23, 0x4e, 0x8d, 0x8a, 0xa8,
-	0x2c, 0x7e, 0xe3, 0x0e, 0x68, 0xe7, 0x09, 0x8d, 0x5d, 0xc7, 0xd0, 0x44, 0x8b, 0xf2, 0x84, 0xcf,
-	0x00, 0x4e, 0x23, 0x1e, 0x5c, 0x8e, 0xd3, 0xca, 0x46, 0xf5, 0x5f, 0x35, 0xae, 0x05, 0x93, 0xdf,
-	0x0a, 0xe8, 0x2f, 0x63, 0xea, 0x73, 0xea, 0xd1, 0x2f, 0xff, 0xc1, 0xbc, 0xbb, 0xc5, 0xb8, 0x09,
-	0x9b, 0x5f, 0x37, 0x79, 0x01, 0xfa, 0x39, 0xbb, 0x90, 0x6f, 0x31, 0xef, 0x85, 0x87, 0xd2, 0x24,
-	0xe2, 0x6d, 0xd6, 0xdb, 0x1b, 0x96, 0xf4, 0xb1, 0xb8, 0xf4, 0x32, 0x2d, 0xc5, 0x3b, 0x74, 0x40,
-	0x97, 0x12, 0xc8, 0x63, 0x58, 0x3b, 0x09, 0x12, 0xee, 0xd1, 0x84, 0xe1, 0x23, 0xd0, 0x44, 0x46,
-	0x62, 0x28, 0x8d, 0xf2, 0x22, 0x4e, 0x8a, 0x64, 0x0f, 0xe0, 0x15, 0xe5, 0x47, 0x63, 0xd7, 0x59,
-	0x06, 0x7c, 0x02, 0xeb, 0x85, 0xba, 0x3a, 0xf3, 0x33, 0xd4, 0x44, 0x96, 0x23, 0x07, 0xcd, 0xd7,
-	0xab, 0xac, 0xb8, 0xde, 0x26, 0x54, 0x3c, 0x3f, 0xec, 0x67, 0x26, 0xd9, 0x6c, 0x63, 0x5e, 0xe5,
-	0xdd, 0x88, 0xc6, 0x63, 0xa1, 0x78, 0x59, 0x00, 0x79, 0x0a, 0x1b, 0xd7, 0x2a, 0xad, 0xdc, 0x61,
-	0xab, 0x05, 0x30, 0x85, 0x61, 0x15, 0xca, 0xce, 0xe1, 0xc7, 0xfa, 0x2d, 0x5c, 0x03, 0xf5, 0x7d,
-	0xa7, 0xf3, 0xba, 0xae, 0xa0, 0x0e, 0x95, 0x37, 0x6f, 0x4f, 0xcf, 0x8e, 0xeb, 0xa5, 0xf6, 0x8f,
-	0x32, 0xa8, 0xfd, 0x98, 0xf5, 0xf0, 0x08, 0xb4, 0x6c, 0xb3, 0xb8, 0x95, 0x53, 0x0b, 0x63, 0x9b,
-	0xf3, 0x57, 0x09, 0x23, 0xf8, 0xed, 0xe7, 0xaf, 0xef, 0xa5, 0x1a, 0xa9, 0xda, 0x54, 0x54, 0x7d,
-	0xae, 0xb4, 0xf0, 0x04, 0xb4, 0xcc, 0x00, 0x53, 0x46, 0x61, 0x08, 0x73, 0x67, 0xe1, 0x65, 0x3a,
-	0xe9, 0x5f, 0x0c, 0xb9, 0x27, 0x40, 0x5b, 0x66, 0x4d, 0x82, 0xec, 0x2b, 0xd7, 0x99, 0xa4, 0x34,
-	0x17, 0xb4, 0xcc, 0x0c, 0x53, 0x5a, 0x61, 0x8e, 0x1b, 0x69, 0xdb, 0x82, 0xb6, 0xd9, 0x9a, 0xa1,
-	0xe1, 0x21, 0xa8, 0xa9, 0x75, 0xf0, 0x86, 0x2c, 0xb3, 0x9e, 0x17, 0xc8, 0x0d, 0x46, 0x6e, 0x0b,
-	0x8e, 0x8e, 0xf9, 0x78, 0x78, 0x0c, 0x55, 0x69, 0x16, 0x2c, 0x56, 0x36, 0xf5, 0x96, 0x79, 0x67,
-	0xe1, 0x2e, 0x61, 0x79, 0x33, 0x38, 0xdb, 0xcc, 0x07, 0xd0, 0x8b, 0xb5, 0xe2, 0xf6, 0x4c, 0x9e,
-	0xf4, 0x94, 0x79, 0x77, 0xc9, 0x6d, 0xc2, 0xc8, 0xbe, 0xe0, 0x19, 0x64, 0xa7, 0xe0, 0x89, 0x15,
-	0x4f, 0xec, 0xab, 0x34, 0x64, 0x72, 0xb4, 0xf6, 0x49, 0x7e, 0x0f, 0xba, 0x9a, 0x18, 0xf0, 0xe0,
-	0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x37, 0x8b, 0x96, 0x2e, 0x06, 0x00, 0x00,
+	0x71, 0x73, 0xdb, 0x6d, 0xb0, 0x94, 0xda, 0x8b, 0xbd, 0x41, 0x8a, 0xaa, 0x5e, 0x78, 0x05, 0xc4,
+	0x4b, 0x71, 0xe5, 0x15, 0xb8, 0xf2, 0x0e, 0xc8, 0xeb, 0xb5, 0xd3, 0x26, 0xa9, 0xc8, 0x99, 0x5b,
+	0xe6, 0xeb, 0x37, 0x33, 0x3b, 0x7f, 0xc5, 0xd0, 0x64, 0xa3, 0xe3, 0x61, 0x74, 0xe2, 0xb0, 0x34,
+	0xe1, 0x09, 0xea, 0x85, 0x65, 0x3f, 0x18, 0x24, 0xc9, 0x60, 0x48, 0x5d, 0xe1, 0x3d, 0x1e, 0x9d,
+	0xb9, 0x3c, 0x3a, 0xa7, 0x19, 0x0f, 0xcf, 0x59, 0x91, 0x68, 0x6f, 0x4d, 0x27, 0x9c, 0x8e, 0xd2,
+	0x90, 0x47, 0x49, 0x2c, 0xe3, 0x1b, 0xd3, 0x71, 0x7a, 0xce, 0xf8, 0x58, 0x06, 0x37, 0x65, 0x30,
+	0x64, 0x91, 0x1b, 0xc6, 0x71, 0xc2, 0x45, 0x65, 0x56, 0x44, 0xc9, 0x0f, 0x15, 0xea, 0xfd, 0xaf,
+	0x34, 0xe6, 0xb8, 0x02, 0xaa, 0xef, 0x59, 0x4a, 0x5b, 0xe9, 0xd4, 0x02, 0xd5, 0xf7, 0x70, 0x0d,
+	0xea, 0x87, 0x11, 0x1f, 0x52, 0x4b, 0x6d, 0x2b, 0x1d, 0x33, 0x28, 0x0c, 0x74, 0x40, 0xf3, 0x42,
+	0x4e, 0xad, 0x5a, 0x5b, 0xe9, 0x2c, 0xf5, 0x6c, 0xa7, 0x80, 0x3b, 0x65, 0x67, 0xe7, 0xb0, 0x1c,
+	0x3d, 0x10, 0x79, 0xb8, 0x0d, 0x8d, 0xfd, 0x90, 0xd3, 0xf8, 0x64, 0x6c, 0x69, 0xa2, 0xe4, 0xfe,
+	0x4c, 0x89, 0x27, 0x97, 0x09, 0xca, 0x4c, 0x44, 0xd0, 0x0e, 0x12, 0x4e, 0xad, 0xba, 0xe8, 0x2c,
+	0x7e, 0xe3, 0x3a, 0xe8, 0x47, 0x19, 0x4d, 0x7d, 0xcf, 0xd2, 0xc5, 0x88, 0xd2, 0xc2, 0x67, 0x00,
+	0x07, 0x09, 0x8f, 0xce, 0xc6, 0x79, 0x67, 0xab, 0xf1, 0xaf, 0x1e, 0x57, 0x92, 0xd1, 0x06, 0x23,
+	0xce, 0xad, 0x88, 0x9e, 0x5a, 0x46, 0x5b, 0xe9, 0x18, 0x41, 0x65, 0x93, 0x3f, 0x0a, 0x98, 0x2f,
+	0x53, 0x1a, 0x72, 0x1a, 0xd0, 0x2f, 0xff, 0xff, 0x5b, 0x90, 0x8d, 0x6a, 0xdd, 0x8c, 0x4d, 0x4b,
+	0x81, 0xbc, 0x00, 0xf3, 0x88, 0x9d, 0xca, 0xb7, 0x98, 0xd6, 0xc9, 0x43, 0x29, 0x20, 0xf1, 0x36,
+	0x4b, 0xbd, 0x65, 0x47, 0x6a, 0x5c, 0x38, 0x83, 0x22, 0x96, 0xe3, 0x3d, 0x3a, 0xa4, 0x73, 0x09,
+	0xe4, 0x31, 0x18, 0xfb, 0x51, 0xc6, 0x03, 0x9a, 0x31, 0x7c, 0x04, 0xba, 0xa8, 0xc8, 0x2c, 0xa5,
+	0x5d, 0x9b, 0xc5, 0xc9, 0x20, 0xd9, 0x04, 0x78, 0x45, 0xf9, 0xee, 0xd8, 0xf7, 0xe6, 0x01, 0x9f,
+	0xc0, 0x52, 0x15, 0x5d, 0x9c, 0xf9, 0x19, 0x9a, 0xa2, 0xca, 0x93, 0x8b, 0x96, 0xe7, 0x55, 0x16,
+	0x3c, 0x6f, 0x07, 0xea, 0x41, 0x18, 0x0f, 0x0a, 0x91, 0xac, 0xf4, 0xb0, 0xec, 0xf2, 0x6e, 0x44,
+	0xd3, 0xb1, 0x88, 0x04, 0x45, 0x02, 0x79, 0x0a, 0xcb, 0x57, 0x3a, 0x2d, 0x3c, 0x61, 0xb7, 0x0b,
+	0x30, 0x81, 0x61, 0x03, 0x6a, 0xde, 0xce, 0xc7, 0xd6, 0x2d, 0x34, 0x40, 0x7b, 0xdf, 0xef, 0xbf,
+	0x6e, 0x29, 0x68, 0x42, 0xfd, 0xcd, 0xdb, 0x83, 0xc3, 0xbd, 0x96, 0xda, 0xfb, 0x59, 0x03, 0x6d,
+	0x90, 0xb2, 0x13, 0xdc, 0x05, 0xbd, 0xb8, 0x2c, 0xae, 0x96, 0xd4, 0x4a, 0xd8, 0xf6, 0xb4, 0x2b,
+	0x63, 0x04, 0xbf, 0xfd, 0xfa, 0xfd, 0x5d, 0x6d, 0x92, 0x86, 0x4b, 0x45, 0xd7, 0xe7, 0x4a, 0x17,
+	0xf7, 0x41, 0x2f, 0x04, 0x30, 0x61, 0x54, 0x82, 0xb0, 0xd7, 0x67, 0x5e, 0xa6, 0x9f, 0xff, 0xfd,
+	0x90, 0x7b, 0x02, 0xb4, 0x6a, 0x37, 0x25, 0xc8, 0xbd, 0xf0, 0xbd, 0xcb, 0x9c, 0xe6, 0x83, 0x5e,
+	0x88, 0x61, 0x42, 0xab, 0xc4, 0x71, 0x23, 0x6d, 0x4d, 0xd0, 0x56, 0xba, 0xd7, 0x68, 0xb8, 0x03,
+	0x5a, 0x2e, 0x1d, 0xbc, 0xa1, 0xca, 0x6e, 0x95, 0x0d, 0x4a, 0x81, 0x91, 0xdb, 0x82, 0x63, 0x62,
+	0xb9, 0x1e, 0xee, 0x41, 0x43, 0x8a, 0x05, 0xab, 0x93, 0x4d, 0xb4, 0x65, 0xdf, 0x99, 0xf1, 0x65,
+	0xac, 0x1c, 0x06, 0xaf, 0x0f, 0xf3, 0x01, 0xcc, 0xea, 0xac, 0xb8, 0x76, 0xad, 0x4e, 0x6a, 0xca,
+	0xbe, 0x3b, 0xc7, 0x9b, 0x31, 0xb2, 0x25, 0x78, 0x16, 0x59, 0xaf, 0x78, 0xe2, 0xc4, 0x97, 0xee,
+	0x45, 0x9e, 0x72, 0xb9, 0x6b, 0x7c, 0x92, 0xdf, 0x8a, 0x63, 0x5d, 0x2c, 0xb8, 0xfd, 0x37, 0x00,
+	0x00, 0xff, 0xff, 0xef, 0xf0, 0x80, 0xc3, 0x4a, 0x06, 0x00, 0x00,
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
diff --git a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
index e65463b..bd178cd 100644
--- a/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
+++ b/hw12_13_14_15_calendar/pkg/storage/sql/sql.go
@@ -41,14 +41,15 @@ func (s *Storage) Create(ev event.Event) (event.ID, error) {
 	lastInsertID := -1
 	if err := s.db.QueryRow(
 		`INSERT INTO events 
-		(title, date, latency, note, userID, notifyTime) VALUES 
-		($1, $2, $3, $4, $5, $6) RETURNING id`,
+		(title, date, latency, note, userID, notifyTime,notified) VALUES 
+		($1, $2, $3, $4, $5, $6, $7) RETURNING id`,
 		ev.Title,
 		ev.Date.Format(dateTimeLayout),
 		ev.Latency,
 		ev.Note,
 		ev.UserID,
 		ev.NotifyTime,
+		false,
 	).Scan(&lastInsertID); err != nil {
 		return -1, fmt.Errorf("can't create event in SQL DB: %w", err)
 	}
@@ -87,7 +88,7 @@ func (s *Storage) Delete(id event.ID) error {
 
 func (s *Storage) List() (map[event.ID]event.Event, error) {
 	res := make(map[event.ID]event.Event)
-	results, err := s.db.Query(`SELECT id,title,date,latency,note,userID,notifyTime from events ORDER BY id`)
+	results, err := s.db.Query(`SELECT id,title,date,latency,note,userID,notifyTime,notified from events ORDER BY id`)
 	if err != nil {
 		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
@@ -96,7 +97,7 @@ func (s *Storage) List() (map[event.ID]event.Event, error) {
 		var id event.ID
 		var evt event.Event
 		var dateRaw string
-		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
+		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime, &evt.Notified)
 		if err != nil {
 			return nil, fmt.Errorf("can't parce list of events getted from SQL DB: %w", err)
 		}
@@ -116,7 +117,7 @@ func (s *Storage) GetByID(id event.ID) (event.Event, bool) {
 	var res event.Event
 	var dateRaw string
 	err := s.db.QueryRow(
-		`SELECT title,date,latency,note,userID,notifyTime from events where id=$1`, id).Scan(&res.Title, &dateRaw, &res.Latency, &res.Note, &res.UserID, &res.NotifyTime)
+		`SELECT title,date,latency,note,userID,notifyTime,notified from events where id=$1`, id).Scan(&res.Title, &dateRaw, &res.Latency, &res.Note, &res.UserID, &res.NotifyTime, &res.Notified)
 	if err != nil {
 		return res, false
 	}
@@ -133,7 +134,7 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 	endDate := getEndDate(startDate, rng)
 
 	results, err := s.db.Query(
-		`SELECT id,title,date,latency,note,userID,notifyTime
+		`SELECT id,title,date,latency,note,userID,notifyTime,notified
 				from events
 				where (date>=$1 AND date<=$2)
 				ORDER BY id`,
@@ -148,7 +149,7 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 		var id event.ID
 		var evt event.Event
 		var dateRaw string
-		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime)
+		err = results.Scan(&id, &evt.Title, &dateRaw, &evt.Latency, &evt.Note, &evt.UserID, &evt.NotifyTime, &evt.Notified)
 		if err != nil {
 			return nil, fmt.Errorf("can't parce list of events getted from SQL DB: %w", err)
 		}
@@ -167,11 +168,10 @@ func (s *Storage) GetByDate(startDate time.Time, rng string) (map[event.ID]event
 func (s *Storage) GetNotifications() (map[event.ID]event.Event, error) {
 	res := make(map[event.ID]event.Event)
 	results, err := s.db.Query(
-		`SELECT (id,title,date,latency,note,userID,notifyTime)
+		`SELECT id,title,date,latency,note,userID,notifyTime
 				from events
-				where 	($1>date-notifyTime) AND (NOT notified)
-				ORDER BY id`,
-		time.Now())
+				where 	(NOW()>date) AND (NOT notified)
+				ORDER BY id`)
 	if err != nil {
 		return nil, fmt.Errorf("can't get list of events from SQL DB: %w", err)
 	}
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index 75e7250..4121222 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -1,11 +1,11 @@
 package main
 
 import (
+	"context"
 	"github.com/stretchr/testify/require"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
 	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
-	"context"
 	"log"
 	"sync"
 	"testing"
@@ -18,7 +18,7 @@ func TestPublicAPIEndpoints(t *testing.T) {
 		client.HTTPAPI{BaseURL: "http://localhost:50052", Name: "HTTP REST API"},
 	}
 	wg := sync.WaitGroup{}
-	wg.Add(len(cli) * 5)
+	wg.Add(len(cli) * 6)
 
 	for _, c := range cli {
 		t.Run("test "+c.GetName()+" for Create, GetById and Delete", func(t *testing.T) {
@@ -153,6 +153,25 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.NoError(t, err)
 			require.Equal(t, 16, len(resp4.Events))
 		})
+
+		t.Run("test "+c.GetName()+" for send notification", func(t *testing.T) {
+			var ids []int64
+			defer func() {
+				wg.Done()
+				clean(c, &ids)
+			}()
+
+			resp1, err := c.Create(&misc.TestEvent03)
+			require.NoError(t, err)
+			require.Greater(t, resp1.ID, int64(0))
+			ids = append(ids, resp1.ID)
+			time.Sleep(3 * time.Second)
+
+			resp2, err := c.GetByID(&public.GetByIDReq{ID: resp1.ID})
+			require.NoError(t, err)
+			require.Equal(t, 1, len(resp2.Events))
+			require.True(t, resp2.Events[0].Notified)
+		})
 	}
 }
 
diff --git a/hw12_13_14_15_calendar/test/misc/misc.go b/hw12_13_14_15_calendar/test/misc/misc.go
index 61a8ccc..74d7d35 100644
--- a/hw12_13_14_15_calendar/test/misc/misc.go
+++ b/hw12_13_14_15_calendar/test/misc/misc.go
@@ -27,6 +27,15 @@ var TestEvent02 = public.CreateReq{
 	UserID:     2222,
 }
 
+var TestEvent03 = public.CreateReq{
+	Title:      "Test event 03",
+	Date:       Time2pbtimestamp(time.Now().Add(-5 * time.Minute)),
+	Latency:    Dur2pbduration(24 * time.Hour),
+	Note:       "Note of test event 03",
+	NotifyTime: Dur2pbduration(1 * time.Second),
+	UserID:     1111,
+}
+
 func Time2pbtimestamp(t time.Time) *timestamp.Timestamp {
 	r, err := ptypes.TimestampProto(t)
 	if err != nil {

From 6948e2e9d495abe55bf875e11958d7383066cf09 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Tue, 4 May 2021 18:18:49 +0300
Subject: [PATCH 18/20] HW15 WIP

---
 .run/calendar.run.xml                         | 12 +++++
 .run/scheduler.run.xml                        | 13 ++++++
 .run/sender.run.xml                           | 13 ++++++
 hw12_13_14_15_calendar/Makefile               |  6 +--
 hw12_13_14_15_calendar/cmd/scheduler/main.go  |  8 ++--
 hw12_13_14_15_calendar/configs/sender.conf    |  2 +-
 hw12_13_14_15_calendar/go.mod                 |  5 +-
 hw12_13_14_15_calendar/go.sum                 | 46 +++++++++++++++++++
 .../internal/sender/app_sender.go             | 18 ++++----
 .../internal/sheduler/scheduler.go            |  2 +-
 hw12_13_14_15_calendar/pkg/rabbit/consumer.go |  6 ++-
 hw12_13_14_15_calendar/pkg/rabbit/producer.go | 24 ++++++----
 hw12_13_14_15_calendar/pkg/rabbit/rabbit.go   | 18 ++++----
 hw12_13_14_15_calendar/test/main_test.go      | 12 +++--
 14 files changed, 139 insertions(+), 46 deletions(-)
 create mode 100644 .run/calendar.run.xml
 create mode 100644 .run/scheduler.run.xml
 create mode 100644 .run/sender.run.xml

diff --git a/.run/calendar.run.xml b/.run/calendar.run.xml
new file mode 100644
index 0000000..d622a14
--- /dev/null
+++ b/.run/calendar.run.xml
@@ -0,0 +1,12 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="calendar" type="GoApplicationRunConfiguration" factoryName="Go Application">
+    <module name="HW_OTUS" />
+    <working_directory value="$PROJECT_DIR$/hw12_13_14_15_calendar" />
+    <parameters value="-config=configs/calendar.conf" />
+    <kind value="PACKAGE" />
+    <package value="github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/cmd/calendar" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$/hw12_13_14_15_calendar/cmd/calendar/main.go" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/scheduler.run.xml b/.run/scheduler.run.xml
new file mode 100644
index 0000000..0a4c686
--- /dev/null
+++ b/.run/scheduler.run.xml
@@ -0,0 +1,13 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="scheduler" type="GoApplicationRunConfiguration" factoryName="Go Application">
+    <module name="HW_OTUS" />
+    <working_directory value="$PROJECT_DIR$/hw12_13_14_15_calendar" />
+    <go_parameters value="-i" />
+    <parameters value="-config=configs/scheduler.conf" />
+    <kind value="PACKAGE" />
+    <package value="github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/cmd/scheduler" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/sender.run.xml b/.run/sender.run.xml
new file mode 100644
index 0000000..606a2d9
--- /dev/null
+++ b/.run/sender.run.xml
@@ -0,0 +1,13 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="sender" type="GoApplicationRunConfiguration" factoryName="Go Application">
+    <module name="HW_OTUS" />
+    <working_directory value="$PROJECT_DIR$/hw12_13_14_15_calendar" />
+    <go_parameters value="-i" />
+    <parameters value="-config=configs/sender.conf" />
+    <kind value="PACKAGE" />
+    <package value="github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/cmd/sender" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 68278dd..10720f7 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -47,14 +47,14 @@ sender-up:
 sender-down:
 	docker-compose -f ./cicd/dc_sender.yml down
 
-sheduler-up:
+scheduler-up:
 	docker-compose -f ./cicd/dc_sheduler.yml up -d --build
-sheduler-down:
+scheduler-down:
 	docker-compose -f ./cicd/dc_sheduler.yml down
 
 sup-up:
 	docker-compose -f ./cicd/dc_sup.yml up -d --build
 sup-down:
-	docker-compose -f ./cicd/dc_sup.yml down
+	docker-compose -f ./cicd/dc_sup.yml down --rmi local -v
 
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cmd/scheduler/main.go b/hw12_13_14_15_calendar/cmd/scheduler/main.go
index b94c8d9..c9bc8ee 100644
--- a/hw12_13_14_15_calendar/cmd/scheduler/main.go
+++ b/hw12_13_14_15_calendar/cmd/scheduler/main.go
@@ -2,13 +2,15 @@ package main
 
 import (
 	"flag"
-	_ "github.com/go-sql-driver/mysql"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sheduler"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 	"log"
 	"os"
 	"os/signal"
 	"syscall"
+
+	_ "github.com/go-sql-driver/mysql"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/sheduler"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/config"
 )
 
 var configFile string
diff --git a/hw12_13_14_15_calendar/configs/sender.conf b/hw12_13_14_15_calendar/configs/sender.conf
index da6ef69..3abe61e 100644
--- a/hw12_13_14_15_calendar/configs/sender.conf
+++ b/hw12_13_14_15_calendar/configs/sender.conf
@@ -11,6 +11,6 @@ Key = "events"
 File = "./logs/calendar.log"
 Level = "INFO"
 
-[API]
+[CalendarAPI]
 Address = "localhost"
 Port = "50053"
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/go.mod b/hw12_13_14_15_calendar/go.mod
index 854a676..762aed8 100644
--- a/hw12_13_14_15_calendar/go.mod
+++ b/hw12_13_14_15_calendar/go.mod
@@ -5,6 +5,7 @@ go 1.14
 require (
 	github.com/BurntSushi/toml v0.3.1
 	github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec
+	github.com/daixiang0/gci v0.2.8 // indirect
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/golang/protobuf v1.4.2
 	github.com/gorilla/mux v1.8.0
@@ -16,12 +17,8 @@ require (
 	github.com/streadway/amqp v1.0.0
 	github.com/stretchr/testify v1.6.1
 	go.uber.org/zap v1.15.0 // indirect
-	golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
-	golang.org/x/text v0.3.3 // indirect
-	golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 // indirect
 	google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70
 	google.golang.org/grpc v1.32.0
-	google.golang.org/protobuf v1.25.0 // indirect
 	gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
 	gopkg.in/yaml.v2 v2.3.0 // indirect
 )
diff --git a/hw12_13_14_15_calendar/go.sum b/hw12_13_14_15_calendar/go.sum
index 1c88ff2..63344a1 100644
--- a/hw12_13_14_15_calendar/go.sum
+++ b/hw12_13_14_15_calendar/go.sum
@@ -6,13 +6,18 @@ github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec/go.mod h1:RZEHP3c
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
+github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/daixiang0/gci v0.2.8 h1:1mrIGMBQsBu0P7j7m1M8Lb+ZeZxsZL+jyGX4YoMJJpg=
+github.com/daixiang0/gci v0.2.8/go.mod h1:+4dZ7TISfSmqfAGv59ePaHfNzgGtIkHAhhdKggP1JAc=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
+github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
+github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@@ -29,13 +34,18 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
 github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
 github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -67,9 +77,11 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
@@ -92,7 +104,9 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
+golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -103,11 +117,17 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
 golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
+golang.org/x/net v0.0.0-20210504132125-bbd867fde50d h1:nTDGCTeAu2LhcsHTRzjyIUbZHCJ4QePArsm27Hka0UM=
+golang.org/x/net v0.0.0-20210504132125-bbd867fde50d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -116,9 +136,22 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 h1:cdsMqa2nXzqlgs183pHxtvoVwU7CyzaCTAUOg94af4c=
+golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -128,12 +161,16 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw
 golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 h1:yaM5S0KcY0lIoZo7Fl+oi91b/DdlU2zuWpfHrpWbCS0=
 golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
+golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
@@ -141,12 +178,17 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70 h1:wboULUXGF3c5qdUnKp+6gLAccE6PRpa/czkYvQ4UXv8=
 google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
+google.golang.org/genproto v0.0.0-20210504143626-3b2ad6ccc450 h1:iSifhRHb9+Pi325BWlAfpJbuG2YXlBoHE2aEFJY/Pg8=
+google.golang.org/genproto v0.0.0-20210504143626-3b2ad6ccc450/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
 google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
 google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
 google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
+google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
+google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c=
+google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -155,9 +197,13 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
 google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
 google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
 google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
diff --git a/hw12_13_14_15_calendar/internal/sender/app_sender.go b/hw12_13_14_15_calendar/internal/sender/app_sender.go
index 04880d3..7610b64 100644
--- a/hw12_13_14_15_calendar/internal/sender/app_sender.go
+++ b/hw12_13_14_15_calendar/internal/sender/app_sender.go
@@ -54,17 +54,17 @@ func (s *Sender) Start() error {
 		for {
 			select {
 			case m := <-msg:
-				var data []private.Event
-				err := json.Unmarshal(m.Data, &data)
-				if err != nil {
-					s.Logger.Errorf("can`t unmarshal data %w", err)
-				}
-				for _, v := range data {
-					_, err = s.GRPCAPI.SetNotified(ctx, &private.SetReq{ID: v.ID})
+				if m.Data != nil {
+					var data private.Event
+					err := json.Unmarshal(m.Data, &data)
 					if err != nil {
-						s.Logger.Errorf("can`t mark event with ID %d as notified data %w", v.ID, err)
+						s.Logger.Errorf("can`t unmarshal data %w", err)
 					}
-					s.Logger.Infof("User %s notified about event %s", v.UserID, v.ID)
+					_, err = s.GRPCAPI.SetNotified(ctx, &private.SetReq{ID: data.ID})
+					if err != nil {
+						s.Logger.Errorf("can`t mark event with ID %d as notified data %w", data.ID, err)
+					}
+					s.Logger.Infof("User %s notified about event %s", data.UserID, data.ID)
 				}
 			case <-ctx.Done():
 				return
diff --git a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
index a00a71a..e7334e7 100644
--- a/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
+++ b/hw12_13_14_15_calendar/internal/sheduler/scheduler.go
@@ -53,7 +53,7 @@ func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit, l
 		if err != nil {
 			return fmt.Errorf("can't marshal events into JSON: %w", err)
 		}
-		err = rb.Publish(string(b))
+		err = rb.Publish(b)
 		if err != nil {
 			return fmt.Errorf("can't publish serialized data to RabbitMQ: %w", err)
 		}
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/consumer.go b/hw12_13_14_15_calendar/pkg/rabbit/consumer.go
index 8182005..1505221 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/consumer.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/consumer.go
@@ -19,7 +19,11 @@ type Message struct {
 
 func (r *Rabbit) Consume(ctx context.Context, queue string) (<-chan Message, error) {
 	messages := make(chan Message)
-	deliveries, err := r.Channel.Consume(queue, "", false, false, false, false, nil)
+	ch, err := r.Connection.Channel()
+	if err != nil {
+		return nil, fmt.Errorf("can't get channel from AMQP connection: %w", err)
+	}
+	deliveries, err := ch.Consume(queue, "", false, false, false, false, nil)
 	if err != nil {
 		return nil, fmt.Errorf("start consuming: %w", err)
 	}
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/producer.go b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
index 708bd63..51a0b6e 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/producer.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/producer.go
@@ -1,28 +1,34 @@
 package rabbit
 
 import (
-	"encoding/json"
 	"fmt"
+	"log"
 
 	"github.com/streadway/amqp"
 )
 
-func (r *Rabbit) Publish(body string) error {
-	b, err := json.Marshal([]byte(body))
+func (r *Rabbit) Publish(b []byte) error {
+	ch, err := r.Connection.Channel()
+	defer func() {
+		if err := ch.Close(); err != nil {
+			log.Println("can't close AMQP connection")
+		}
+	}()
 	if err != nil {
-		return fmt.Errorf("can't marshal message body into JSON: %w", err)
+		return fmt.Errorf("can't get channel from AMQP connection: %w", err)
 	}
-	err = r.Channel.Publish(
+	err = ch.Publish(
 		r.Exchange, // exchange
 		r.Key,      // routing key
-		false,      // mandatory
+		true,       // mandatory
 		false,      // immediate
 		amqp.Publishing{
-			ContentType: "application/json; charset=utf-8",
-			Body:        b,
+			DeliveryMode: amqp.Persistent,
+			ContentType:  "application/json; charset=utf-8",
+			Body:         b,
 		})
 	if err != nil {
-		return fmt.Errorf("can't publish message into RabbitMQ exchange: %w", err)
+		return fmt.Errorf("can't publish message into RabbitMQ: %w", err)
 	}
 	return nil
 }
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
index b893dc6..b2932ac 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
@@ -2,13 +2,13 @@ package rabbit
 
 import (
 	"fmt"
+	"log"
 
 	"github.com/streadway/amqp"
 )
 
 type Rabbit struct {
 	Connection *amqp.Connection
-	Channel    *amqp.Channel
 	Exchange   string
 	Key        string
 	Queue      string
@@ -30,6 +30,11 @@ func New(conf Config) (*Rabbit, error) {
 		return nil, fmt.Errorf("can't dial RabbitMQ over AMQP: %w", err)
 	}
 	ch, err := conn.Channel()
+	defer func() {
+		if err := ch.Close(); err != nil {
+			log.Println("can't close AMQP connection")
+		}
+	}()
 	if err != nil {
 		return nil, fmt.Errorf("can't get channel from AMQP connection: %w", err)
 	}
@@ -60,7 +65,7 @@ func New(conf Config) (*Rabbit, error) {
 	if err != nil {
 		return nil, fmt.Errorf("can't bind Queue on Exchange in RabbitMQ: %w", err)
 	}
-	return &Rabbit{Connection: conn, Channel: ch}, nil
+	return &Rabbit{Connection: conn, Exchange: conf.Exchange, Key: conf.Key, Queue: conf.Queue}, nil
 }
 
 func Attach(conf Config) (*Rabbit, error) {
@@ -68,17 +73,10 @@ func Attach(conf Config) (*Rabbit, error) {
 	if err != nil {
 		return nil, fmt.Errorf("can't dial RabbitMQ over AMQP: %w", err)
 	}
-	ch, err := conn.Channel()
-	if err != nil {
-		return nil, fmt.Errorf("can't get channel from AMQP connection: %w", err)
-	}
-	return &Rabbit{Connection: conn, Channel: ch, Exchange: conf.Exchange, Queue: conf.Queue, Key: conf.Key}, nil
+	return &Rabbit{Connection: conn, Exchange: conf.Exchange, Queue: conf.Queue, Key: conf.Key}, nil
 }
 
 func (r *Rabbit) Close() error {
-	if err := r.Channel.Close(); err != nil {
-		return fmt.Errorf("can't close connection channel: %w", err)
-	}
 	if err := r.Connection.Close(); err != nil {
 		return fmt.Errorf("can't close connection: %w", err)
 	}
diff --git a/hw12_13_14_15_calendar/test/main_test.go b/hw12_13_14_15_calendar/test/main_test.go
index 4121222..dd30367 100644
--- a/hw12_13_14_15_calendar/test/main_test.go
+++ b/hw12_13_14_15_calendar/test/main_test.go
@@ -2,14 +2,16 @@ package main
 
 import (
 	"context"
-	"github.com/stretchr/testify/require"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
-	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
 	"log"
 	"sync"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/require"
+
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/pkg/api/public"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/client"
+	"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test/misc"
 )
 
 func TestPublicAPIEndpoints(t *testing.T) {
@@ -165,7 +167,7 @@ func TestPublicAPIEndpoints(t *testing.T) {
 			require.NoError(t, err)
 			require.Greater(t, resp1.ID, int64(0))
 			ids = append(ids, resp1.ID)
-			time.Sleep(3 * time.Second)
+			time.Sleep(5 * time.Second)
 
 			resp2, err := c.GetByID(&public.GetByIDReq{ID: resp1.ID})
 			require.NoError(t, err)

From 0f8b3ae7ea7e2efd896a2ccbf628bc5193c5a884 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Sun, 23 May 2021 16:24:10 +0300
Subject: [PATCH 19/20] HW15 WIP

---
 hw12_13_14_15_calendar/Makefile             | 8 ++++++--
 hw12_13_14_15_calendar/cicd/dc_calendar.yml | 4 ----
 hw12_13_14_15_calendar/cicd/dc_sup.yml      | 5 -----
 hw12_13_14_15_calendar/pkg/rabbit/rabbit.go | 2 +-
 4 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/hw12_13_14_15_calendar/Makefile b/hw12_13_14_15_calendar/Makefile
index 68278dd..c4ea6ea 100644
--- a/hw12_13_14_15_calendar/Makefile
+++ b/hw12_13_14_15_calendar/Makefile
@@ -47,9 +47,9 @@ sender-up:
 sender-down:
 	docker-compose -f ./cicd/dc_sender.yml down
 
-sheduler-up:
+scheduler-up:
 	docker-compose -f ./cicd/dc_sheduler.yml up -d --build
-sheduler-down:
+scheduler-down:
 	docker-compose -f ./cicd/dc_sheduler.yml down
 
 sup-up:
@@ -57,4 +57,8 @@ sup-up:
 sup-down:
 	docker-compose -f ./cicd/dc_sup.yml down
 
+debug: sup-up calendar-up sender-up
+
+kill: sender-down calendar-down sup-down
+
 .PHONY: build run test lint
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/dc_calendar.yml b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
index c56a30c..9af7975 100644
--- a/hw12_13_14_15_calendar/cicd/dc_calendar.yml
+++ b/hw12_13_14_15_calendar/cicd/dc_calendar.yml
@@ -22,8 +22,4 @@ services:
       APP_STORAGE_SQLDBASE: calendar
       APP_STORAGE_SQLUSER: calendar
       APP_STORAGE_SQLPASS: 12345678
-    ports:
-      - 8888:8888
-      - 50051:50051
-      - 50053:50053
     network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/cicd/dc_sup.yml b/hw12_13_14_15_calendar/cicd/dc_sup.yml
index c186ce3..c1be174 100644
--- a/hw12_13_14_15_calendar/cicd/dc_sup.yml
+++ b/hw12_13_14_15_calendar/cicd/dc_sup.yml
@@ -20,8 +20,6 @@ services:
       POSTGRES_USER: calendar
       POSTGRES_PASSWORD: 12345678
       POSTGRES_DB: calendar
-    ports:
-    - 5432:5432
     network_mode: host
 
   rabbitmq:
@@ -33,7 +31,4 @@ services:
       RABBITMQ_DEFAULT_USER: "rabbit"
       RABBITMQ_DEFAULT_PASS: "rabbit"
       RABBITMQ_DEFAULT_VHOST: "/"
-    ports:
-      - 15672:15672
-      - 5672:5672
     network_mode: host
\ No newline at end of file
diff --git a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
index b893dc6..06e99a7 100644
--- a/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
+++ b/hw12_13_14_15_calendar/pkg/rabbit/rabbit.go
@@ -60,7 +60,7 @@ func New(conf Config) (*Rabbit, error) {
 	if err != nil {
 		return nil, fmt.Errorf("can't bind Queue on Exchange in RabbitMQ: %w", err)
 	}
-	return &Rabbit{Connection: conn, Channel: ch}, nil
+	return &Rabbit{Connection: conn, Channel: ch, Exchange:conf.Exchange, Key: conf.Key, Queue: conf.Queue}, nil
 }
 
 func Attach(conf Config) (*Rabbit, error) {

From b3ebe12c6f922219384e4c166c00908cf08f9363 Mon Sep 17 00:00:00 2001
From: Andrey Ivanov <tiburon-777@users.noreply.github.com>
Date: Sun, 23 May 2021 16:28:40 +0300
Subject: [PATCH 20/20] HW15 WIP

---
 .run/integration.run.xml      | 12 ++++++++++++
 hw08_zenv_to_structure/go.mod |  2 +-
 hw08_zenv_to_structure/go.sum |  6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 .run/integration.run.xml
 create mode 100644 hw08_zenv_to_structure/go.sum

diff --git a/.run/integration.run.xml b/.run/integration.run.xml
new file mode 100644
index 0000000..e9823e8
--- /dev/null
+++ b/.run/integration.run.xml
@@ -0,0 +1,12 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="integration" type="GoTestRunConfiguration" factoryName="Go Test">
+    <module name="HW_OTUS" />
+    <working_directory value="$PROJECT_DIR$/hw12_13_14_15_calendar/test" />
+    <kind value="PACKAGE" />
+    <package value="github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/test" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$" />
+    <framework value="gotest" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/hw08_zenv_to_structure/go.mod b/hw08_zenv_to_structure/go.mod
index 29e1197..45287ab 100644
--- a/hw08_zenv_to_structure/go.mod
+++ b/hw08_zenv_to_structure/go.mod
@@ -2,4 +2,4 @@ module github.com/tiburon-777/HW_OTUS/hw08_zenv_to_structure
 
 go 1.14
 
-require github.com/stretchr/testify v1.6.1
\ No newline at end of file
+require github.com/stretchr/testify v1.6.1
diff --git a/hw08_zenv_to_structure/go.sum b/hw08_zenv_to_structure/go.sum
new file mode 100644
index 0000000..065f520
--- /dev/null
+++ b/hw08_zenv_to_structure/go.sum
@@ -0,0 +1,6 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=