Skip to content

Commit

Permalink
Merge branch 'master' of gitlab.com:slon/shad-go-private into treeiter
Browse files Browse the repository at this point in the history
  • Loading branch information
pkositsyn committed Apr 2, 2022
2 parents c96f7e3 + 7658844 commit 6613189
Show file tree
Hide file tree
Showing 157 changed files with 1,264 additions and 198 deletions.
95 changes: 94 additions & 1 deletion .deadlines.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,99 @@
- group: SQL
start: 31-03-2022 18:00
deadline: 17-04-2022 23:59
tasks:
- task: wscat
score: 200
- task: dao
score: 100
- task: ledger
score: 200
- task: shopfront
score: 100

- group: HTTP
start: 23-03-2022 18:00
deadline: 10-04-2022 23:59
tasks:
- task: urlshortener
score: 100
- task: digitalclock
score: 100
- task: olympics
score: 200
- task: firewall
score: 200
- task: coverme
score: 300

- group: Concurrency with shared memory
start: 17-03-2022 23:59
deadline: 03-04-2022 23:59
tasks:
- task: dupcall
score: 200
- task: keylock
score: 200
- task: batcher
score: 200
- task: pubsub
score: 300

- group: "[HW] Gitfame"
start: 11-03-2022 11:59
deadline: 30-03-2022 23:59
tasks:
- task: gitfame
score: 0

- group: Testing
start: 10-03-2022 20:00
deadline: 29-03-2022 23:59
tasks:
- task: testequal
score: 100
- task: fileleak
score: 100
- task: tabletest
score: 100
- task: tparallel
score: 200

- group: Goroutines
start: 03-03-2022 18:00
deadline: 22-03-2022 23:59
tasks:
- task: tour1
score: 100
- task: once
score: 100
- task: rwmutex
score: 100
- task: waitgroup
score: 100
- task: cond
score: 100
- task: ratelimit
score: 100

- group: Interfaces
start: 24-02-2022 18:00
deadline: 13-03-2022 23:59
tasks:
- task: otp
score: 100
- task: lrucache
score: 100
- task: externalsort
score: 100
- task: retryupdate
score: 100
- task: ciletters
score: 100

- group: Basics
start: 17-02-2022 18:00
deadline: 27-02-2022 23:59
deadline: 06-03-2022 23:59
tasks:
- task: hotelbusiness
score: 100
Expand Down
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ linters-settings:
stylecheck:
# https://staticcheck.io/docs/options#checks
checks: ["all", "-ST1018"]
# https://staticcheck.io/docs/options#initialisms
initialisms: [
"ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS",
"RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL",
"UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "CSV",
]


linters:
disable-all: true
Expand Down
4 changes: 2 additions & 2 deletions .releaser-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ check:
- golangci-lint run --build-tags private,solution ./...
#- go test -v -tags private,solution ./...
#- go test -v -race -tags private,solution ./...
- go test $(go list -tags private,solution ./... | grep -v /dockertest | grep -v /foolsday3) -tags private,solution -v ./...
- go test $(go list -tags private,solution ./... | grep -v /dockertest) -tags private,solution -v -race ./...
- sudo -u nobody HOME=/tmp PATH=$PATH /usr/local/go/bin/go test $(go list -tags private,solution ./... | grep -v /dockertest | grep -v /foolsday3) -tags private,solution -v ./...
- sudo -u nobody HOME=/tmp PATH=$PATH /usr/local/go/bin/go test $(go list -tags private,solution ./... | grep -v /dockertest) -tags private,solution -v -race ./...

rebuild-base-image:
tags:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Курс по Го в ШАД

Для работы с кодом нужен go 1.17 или выше.
Для работы с кодом нужен go 1.18 или выше.

```sh
git clone https://gitlab.com/slon/shad-go.git
Expand Down
2 changes: 1 addition & 1 deletion allocs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`Counter` используется для нахождения уникальных слов и подсчета вхождений каждого из них.
Его интерфейс выглядит так:

* `Count(r io.Reader) error` — функция, которая подсчитывает количество вхождений для каждого слова в тексте.
* `Count(r io.Reader) error` — функция, которая подсчитывает количество вхождений каждого слова в тексте.
На вход подается io.Reader, в котором находится некоторый текст.
Разделителями являются только переносы строк и пробелы.
* `String() string` — преобразует мапу вида `{"слово": "количество вхождений"}` в форматированную строку.
Expand Down
1 change: 0 additions & 1 deletion allocs/allocs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution
// +build !solution

package allocs

Expand Down
1 change: 0 additions & 1 deletion allocs/baseline.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution && !change
// +build !solution,!change

package allocs

Expand Down
1 change: 0 additions & 1 deletion batcher/batcher.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution
// +build !solution

package batcher

Expand Down
1 change: 0 additions & 1 deletion batcher/batcher_race_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build race
// +build race

package batcher

Expand Down
1 change: 0 additions & 1 deletion batcher/slow/value.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !change
// +build !change

package slow

Expand Down
1 change: 0 additions & 1 deletion blowfish/blowfish.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution
// +build !solution

package blowfish

Expand Down
6 changes: 3 additions & 3 deletions build.docker
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.17
FROM golang:1.18

RUN apt-get update && apt-get install -y \
rsync libssl-dev \
rsync libssl-dev postgresql sudo redis-server \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.0
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
RUN curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
RUN chmod +x /usr/local/bin/docker-compose
RUN curl -fsSL https://get.docker.com | sh
5 changes: 4 additions & 1 deletion ciletters/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## ciletters

В этой задаче вам предстоит познакомиться со стандартным пакетом [text/template](https://golang.org/pkg/text/template/),
позволяющим генерировать текст в определенном формате.
позволяющим генерировать текст в определенном формате, а также с пакетом [embed](https://pkg.go.dev/embed),
позволяющим вкомпиливать в исполняемый файл строковые литералы.

### Легенда

Expand All @@ -20,6 +21,8 @@
Нужно реализовать функцию `MakeLetter` из файла [letter.go](./letter.go),
которая по go объекту нотификации генерирует её текстовое представление.

Для этого нужно написать `text/template` шаблон, сохранить его в отдельный файл, а затем получить его содержимое в коде с помомщью `go:embed`.

#### Прокомментированный пример из теста
```
Your pipeline #194613 has failed! // 194613 -- это ID pipeline'а
Expand Down
1 change: 0 additions & 1 deletion ciletters/letter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution
// +build !solution

package ciletters

Expand Down
1 change: 0 additions & 1 deletion ciletters/notification.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !change
// +build !change

package ciletters

Expand Down
2 changes: 1 addition & 1 deletion cond/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### Что нужно сделать?

Нужно написать реализацию Cond используя каналы.
Нужно написать реализацию Cond, используя каналы.

Использование пакета [sync](https://golang.org/pkg/sync) в этой задаче запрещено!

Expand Down
1 change: 0 additions & 1 deletion cond/cond.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !solution
// +build !solution

package cond

Expand Down
2 changes: 1 addition & 1 deletion cond/cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestCondBroadcast(t *testing.T) {

// nolint
func TestCondSignalStealing(t *testing.T) {
for iters := 0; iters < 1000; iters++ {
for iters := 0; iters < 20000; iters++ {
var m sync.Mutex
cond := New(&m)

Expand Down
32 changes: 27 additions & 5 deletions coverme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ Package main можно не тестировать.
Coverage 100% говорит ровно о том, что все строки кода выполнялись.
Хорошие тесты, в первую очередь, тестируют функциональность.

Как посмотреть coverage:
Как посмотреть общий coverage:
```
go test -v -cover ./coverme/...
```

Coverage можно выводить в html (см. ссылки), и эта функциональность поддерживается в Goland.
Как посмотреть coverage пакета в html:
```
go test -v -coverprofile=/tmp/coverage.out ./coverme/models/...
go tool cover -html=/tmp/coverage.out
```
Аналогичная функциональность поддерживается в Goland.
Также рекомендуем ознакомиться с рассказом о cover в блоге (см. ссылки).

## Ссылки

Expand All @@ -44,7 +50,7 @@ Todo-app с минимальной функциональностью + client.

Health check:
```
✗ curl -i -X GET localhost:6029/
✗ curl -i -X GET localhost:6029/
HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 19 Mar 2020 21:46:02 GMT
Expand All @@ -66,7 +72,7 @@ Content-Length: 51

Получить todo по id:
```
✗ curl -i localhost:6029/todo/0
✗ curl -i localhost:6029/todo/0
HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 19 Mar 2020 21:44:17 GMT
Expand All @@ -77,11 +83,27 @@ Content-Length: 51

Получить все todo:
```
✗ curl -i -X GET localhost:6029/todo
✗ curl -i -X GET localhost:6029/todo
HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 19 Mar 2020 21:44:37 GMT
Content-Length: 53
[{"id":0,"title":"A","content":"a","finished":false}]
```

Завершить todo:
```
✗ curl -i -X POST localhost:6029/todo/0/finish
HTTP/1.1 200 OK
Date: Thu, 24 Mar 2022 15:40:49 GMT
Content-Length: 0
✗ curl -i -X GET localhost:6029/todo
HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 24 Mar 2022 15:41:04 GMT
Content-Length: 52
[{"id":0,"title":"A","content":"a","finished":true}]%
```
28 changes: 21 additions & 7 deletions coverme/app/app.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !change
// +build !change

package app

Expand All @@ -9,7 +8,6 @@ import (
"net/http"
"os"
"strconv"
"strings"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
Expand All @@ -34,10 +32,11 @@ func (app *App) Start(port int) {

func (app *App) initRoutes() {
app.router = mux.NewRouter()
app.router.HandleFunc("/", app.status).Methods("Get")
app.router.HandleFunc("/todo", app.list).Methods("Get")
app.router.HandleFunc("/todo/{id:[0-9]+}", app.getTodo).Methods("Get")
app.router.HandleFunc("/todo/create", app.addTodo).Methods("Post")
app.router.HandleFunc("/", app.status).Methods("GET")
app.router.HandleFunc("/todo", app.list).Methods("GET")
app.router.HandleFunc("/todo/{id:[0-9]+}", app.getTodo).Methods("GET")
app.router.HandleFunc("/todo/{id:[0-9]+}/finish", app.finishTodo).Methods("POST")
app.router.HandleFunc("/todo/create", app.addTodo).Methods("POST")
}

func (app *App) run(addr string) {
Expand Down Expand Up @@ -80,7 +79,7 @@ func (app *App) addTodo(w http.ResponseWriter, r *http.Request) {
}

func (app *App) getTodo(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/todo/"))
id, err := strconv.Atoi(mux.Vars(r)["id"])
if err != nil {
utils.BadRequest(w, "ID must be an int")
return
Expand All @@ -95,6 +94,21 @@ func (app *App) getTodo(w http.ResponseWriter, r *http.Request) {
_ = utils.RespondJSON(w, http.StatusOK, todo)
}

func (app *App) finishTodo(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(mux.Vars(r)["id"])
if err != nil {
utils.BadRequest(w, "ID must be an int")
return
}

if err := app.db.FinishTodo(models.ID(id)); err != nil {
utils.ServerError(w)
return
}

w.WriteHeader(http.StatusOK)
}

func (app *App) status(w http.ResponseWriter, r *http.Request) {
_ = utils.RespondJSON(w, http.StatusOK, "API is up and working!")
}
1 change: 0 additions & 1 deletion coverme/app/coverage_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !change
// +build !change

package app

Expand Down
Loading

0 comments on commit 6613189

Please sign in to comment.