generated from Yandex-Practicum/go-musthave-metrics-tpl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
из-за поздней сдачи возникают конфликты с веткой iter13
- Loading branch information
1 parent
fa73032
commit 5a46c41
Showing
52 changed files
with
1,275 additions
and
2,905 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"log" | ||
|
||
"github.com/StasMerzlyakov/go-metrics/internal/config" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/fs/formatter" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/handler" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/compress" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/logging" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/storage/memory" | ||
"github.com/StasMerzlyakov/go-metrics/internal/server/usecase" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type Server interface { | ||
Start(ctx context.Context) | ||
WaitDone() | ||
} | ||
|
||
func createMiddleWareList(log *zap.SugaredLogger) []func(http.Handler) http.Handler { | ||
return []func(http.Handler) http.Handler{ | ||
logging.NewLoggingResponseMW(log), | ||
compress.NewCompressGZIPResponseMW(log), //compress.NewCompressGZIPBufferResponseMW(log), | ||
compress.NewUncompressGZIPRequestMW(log), | ||
logging.NewLoggingRequestMW(log), | ||
} | ||
} | ||
|
||
func main() { | ||
|
||
// Конфигурация | ||
srvConf, err := config.LoadServerConfig() | ||
srvConf, err := server.LoadConfig() | ||
if err != nil { | ||
panic(err) | ||
log.Fatal(err) | ||
} | ||
|
||
// Создаем логгер | ||
logger, err := zap.NewDevelopment() | ||
if err != nil { | ||
// вызываем панику, если ошибка | ||
panic("cannot initialize zap") | ||
if err := server.CreateServer(srvConf); err != nil { | ||
panic(err) | ||
} | ||
defer logger.Sync() | ||
|
||
sugarLog := logger.Sugar() | ||
|
||
// Сборка сервера | ||
storage := memory.NewStorage() | ||
|
||
backupFomratter := formatter.NewJSON(sugarLog, srvConf.FileStoragePath) | ||
backup := usecase.NewBackup(sugarLog, storage, backupFomratter) | ||
|
||
metrics := usecase.NewMetrics(storage) | ||
|
||
mwList := createMiddleWareList(sugarLog) | ||
httpHandler := handler.NewHTTP(metrics, sugarLog, mwList...) | ||
|
||
var server Server = server.NewMetricsServer(srvConf, | ||
sugarLog, | ||
httpHandler, | ||
metrics, | ||
backup) | ||
|
||
// Запуск сервера | ||
ctx, cancelFn := context.WithCancel(context.Background()) | ||
exit := make(chan os.Signal, 1) | ||
signal.Notify(exit, os.Interrupt, syscall.SIGTERM) | ||
|
||
server.Start(ctx) | ||
defer func() { | ||
cancelFn() | ||
server.WaitDone() | ||
}() | ||
<-exit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package agent | ||
|
||
import "errors" | ||
|
||
type MetricsSource interface { | ||
PollMetrics() map[string]float64 | ||
PollCount() int64 | ||
} | ||
|
||
var ErrServerInteraction = errors.New("server interaction error") | ||
|
||
type ResultSender interface { | ||
SendGauge(name string, value float64) error | ||
SendCounter(name string, value int64) error | ||
} |
Oops, something went wrong.