Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hw12 calendar #12

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ linters-settings:
funlen:
lines: 150
statements: 80
depguard:
rules:
main:
allow:
- $gostd
- github.com/shimmy8/hw-otus/hw12_13_14_15_calendar
- github.com/pressly/goose/v3
- github.com/stretchr/testify/require
- github.com/jmoiron/sqlx
- github.com/spf13/viper
- github.com/jackc/pgx/stdlib

issues:
exclude-rules:
Expand Down
Empty file removed hw12_13_14_15_calendar/.sync
Empty file.
6 changes: 3 additions & 3 deletions hw12_13_14_15_calendar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BIN := "./bin/calendar"
DOCKER_IMG="calendar:develop"

GIT_HASH := $(shell git log --format="%h" -n 1)
LDFLAGS := -X main.release="develop" -X main.buildDate=$(shell date -u +%Y-%m-%dT%H:%M:%S) -X main.gitHash=$(GIT_HASH)
LDFLAGS := -X main.release="develop"

build:
go build -v -o $(BIN) -ldflags "$(LDFLAGS)" ./cmd/calendar
Expand All @@ -23,10 +23,10 @@ version: build
$(BIN) version

test:
go test -race ./internal/... ./pkg/...
go test -race ./internal/...

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.50.1
(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.54.2
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пришлось бампнуть версию, наткнулся на ошибку golangci/golangci-lint#3107


lint: install-lint-deps
golangci-lint run ./...
Expand Down
20 changes: 0 additions & 20 deletions hw12_13_14_15_calendar/cmd/calendar/config.go

This file was deleted.

36 changes: 23 additions & 13 deletions hw12_13_14_15_calendar/cmd/calendar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"syscall"
"time"

"github.com/fixme_my_friend/hw12_13_14_15_calendar/internal/app"
"github.com/fixme_my_friend/hw12_13_14_15_calendar/internal/logger"
internalhttp "github.com/fixme_my_friend/hw12_13_14_15_calendar/internal/server/http"
memorystorage "github.com/fixme_my_friend/hw12_13_14_15_calendar/internal/storage/memory"
"github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/app"
"github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/config"
"github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/logger"
internalhttp "github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/server/http"
memorystorage "github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/storage/memory"
sqlstorage "github.com/shimmy8/hw-otus/hw12_13_14_15_calendar/internal/storage/sql"
)

var configFile string
Expand All @@ -28,17 +30,25 @@ func main() {
return
}

config := NewConfig()
logg := logger.New(config.Logger.Level)
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
defer cancel()

storage := memorystorage.New()
calendar := app.New(logg, storage)
config := config.NewConfig(configFile)

server := internalhttp.NewServer(logg, calendar)
var storage app.Storage

ctx, cancel := signal.NotifyContext(context.Background(),
syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
defer cancel()
switch config.Storage.DB {
case "in-memory":
storage = memorystorage.New()
case "db":
storage = sqlstorage.New(ctx, config.Storage.URL, config.Storage.Timeout)
default:
storage = memorystorage.New()
}

logg := logger.New(config.Logger.Level, "server")
calendar := app.New(logg, storage)
server := internalhttp.NewServer(logg, calendar)

go func() {
<-ctx.Done()
Expand All @@ -53,7 +63,7 @@ func main() {

logg.Info("calendar is running...")

if err := server.Start(ctx); err != nil {
if err := server.Start(ctx, config.HTTPServer.Host, config.HTTPServer.Port); err != nil {
logg.Error("failed to start http server: " + err.Error())
cancel()
os.Exit(1) //nolint:gocritic
Expand Down
9 changes: 7 additions & 2 deletions hw12_13_14_15_calendar/configs/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[logger]
level = "INFO"

# TODO
# ...
[storage]
db = "in-memory"
timeout = 3

[httpserver]
host = "localhost"
port = 8080
37 changes: 36 additions & 1 deletion hw12_13_14_15_calendar/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
module github.com/fixme_my_friend/hw12_13_14_15_calendar
module github.com/shimmy8/hw-otus/hw12_13_14_15_calendar

go 1.19

require (
github.com/jmoiron/sqlx v1.3.5
github.com/pressly/goose/v3 v3.16.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/pgx v3.6.2+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading